Added namespace support for PayloadSerializingTransformer (INT-517).
This commit is contained in:
@@ -107,6 +107,7 @@ public class IntegrationNamespaceHandler implements NamespaceHandler {
|
||||
registerBeanDefinitionParser("resequencer", new ResequencerParser());
|
||||
registerBeanDefinitionParser("header-enricher", new StandardHeaderEnricherParser());
|
||||
registerBeanDefinitionParser("object-to-string-transformer", new ObjectToStringTransformerParser());
|
||||
registerBeanDefinitionParser("payload-serializing-transformer", new PayloadSerializingTransformerParser());
|
||||
registerBeanDefinitionParser("inbound-channel-adapter", new MethodInvokingInboundChannelAdapterParser());
|
||||
registerBeanDefinitionParser("outbound-channel-adapter", new MethodInvokingOutboundChannelAdapterParser());
|
||||
registerBeanDefinitionParser("gateway", new GatewayParser());
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.config.xml;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
|
||||
/**
|
||||
* Parser for the 'payload-serializing-transformer' element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @since 1.0.1
|
||||
*/
|
||||
public class PayloadSerializingTransformerParser extends AbstractTransformerParser {
|
||||
|
||||
@Override
|
||||
protected String getTransformerClassName() {
|
||||
return IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.PayloadSerializingTransformer";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void parseTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -599,6 +599,14 @@
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="payload-serializing-transformer" type="inputOutputEndpointType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a Transformer that serializes any Object payload that implements Serializable into a byte array.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="filter">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<channel id="directInput"/>
|
||||
|
||||
<channel id="queueInput">
|
||||
<queue capacity="1"/>
|
||||
</channel>
|
||||
|
||||
<channel id="output">
|
||||
<queue capacity="1"/>
|
||||
</channel>
|
||||
|
||||
<payload-serializing-transformer input-channel="directInput" output-channel="output"/>
|
||||
|
||||
<payload-serializing-transformer input-channel="queueInput" output-channel="output">
|
||||
<poller>
|
||||
<interval-trigger interval="10000"/>
|
||||
</poller>
|
||||
</payload-serializing-transformer>
|
||||
|
||||
</beans:beans>
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.transformer.MessageTransformationException;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class PayloadSerializingTransformerParserTests {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("directInput")
|
||||
private MessageChannel directInput;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("queueInput")
|
||||
private MessageChannel queueInput;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("output")
|
||||
private PollableChannel output;
|
||||
|
||||
|
||||
@Test
|
||||
public void directChannelWithStringMessage() throws Exception {
|
||||
directInput.send(new StringMessage("foo"));
|
||||
Message<?> result = output.receive(0);
|
||||
assertNotNull(result);
|
||||
assertTrue(result.getPayload() instanceof byte[]);
|
||||
assertEquals("foo", deserialize((byte[]) result.getPayload()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queueChannelWithStringMessage() throws Exception {
|
||||
queueInput.send(new StringMessage("foo"));
|
||||
Message<?> result = output.receive(3000);
|
||||
assertNotNull(result);
|
||||
assertTrue(result.getPayload() instanceof byte[]);
|
||||
assertEquals("foo", deserialize((byte[]) result.getPayload()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void directChannelWithObjectMessage() throws Exception {
|
||||
directInput.send(new GenericMessage<TestBean>(new TestBean()));
|
||||
Message<?> result = output.receive(0);
|
||||
assertNotNull(result);
|
||||
assertTrue(result.getPayload() instanceof byte[]);
|
||||
Object deserialized = deserialize((byte[]) result.getPayload());
|
||||
assertEquals(TestBean.class, deserialized.getClass());
|
||||
assertEquals("test", ((TestBean) deserialized).name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queueChannelWithObjectMessage() throws Exception {
|
||||
queueInput.send(new GenericMessage<TestBean>(new TestBean()));
|
||||
Message<?> result = output.receive(3000);
|
||||
assertTrue(result.getPayload() instanceof byte[]);
|
||||
Object deserialized = deserialize((byte[]) result.getPayload());
|
||||
assertEquals(TestBean.class, deserialized.getClass());
|
||||
assertEquals("test", ((TestBean) deserialized).name);
|
||||
}
|
||||
|
||||
@Test(expected = MessageTransformationException.class)
|
||||
public void invalidPayload() {
|
||||
directInput.send(new GenericMessage<Object>(new Object()));
|
||||
}
|
||||
|
||||
|
||||
private static Object deserialize(byte[] bytes) throws Exception {
|
||||
ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes);
|
||||
ObjectInputStream objectStream = new ObjectInputStream(byteStream);
|
||||
return objectStream.readObject();
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static class TestBean implements Serializable {
|
||||
|
||||
public final String name = "test";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user