INT-1459 added namespace support for 'converter' on payload-serializing and payload-deserializing transformers
This commit is contained in:
@@ -35,6 +35,7 @@ public class PayloadDeserializingTransformerParser extends AbstractTransformerPa
|
||||
|
||||
@Override
|
||||
protected void parseTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "converter");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ public class PayloadSerializingTransformerParser extends AbstractTransformerPars
|
||||
|
||||
@Override
|
||||
protected void parseTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "converter");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -32,19 +32,18 @@ import org.springframework.core.convert.converter.Converter;
|
||||
* @since 1.0.1
|
||||
*/
|
||||
public class PayloadDeserializingTransformer extends PayloadTypeConvertingTransformer<byte[], Object> {
|
||||
|
||||
@Override
|
||||
protected Object transformPayload(byte[] payload) throws Exception {
|
||||
if (this.converter == null) {
|
||||
this.converter = new DeserializingConverter(new JavaStreamingConverter());
|
||||
}
|
||||
return converter.convert(payload);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConverter(Converter<byte[], Object> converter) {
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Object transformPayload(byte[] payload) throws Exception {
|
||||
if (this.converter == null) {
|
||||
this.converter = new DeserializingConverter(new JavaStreamingConverter());
|
||||
}
|
||||
return this.converter.convert(payload);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -33,18 +33,17 @@ import org.springframework.core.convert.converter.Converter;
|
||||
*/
|
||||
public class PayloadSerializingTransformer extends PayloadTypeConvertingTransformer<Object, byte[]> {
|
||||
|
||||
|
||||
@Override
|
||||
public void setConverter(Converter<Object, byte[]> converter) {
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte[] transformPayload(Object payload) throws Exception {
|
||||
if (this.converter == null) {
|
||||
this.converter = new SerializingConverter(new JavaStreamingConverter());
|
||||
}
|
||||
return converter.convert(payload);
|
||||
return this.converter.convert(payload);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConverter(Converter<Object, byte[]> converter) {
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1009,8 +1009,8 @@
|
||||
<xsd:element name="delayer" type="delayer-type" />
|
||||
<xsd:element name="gateway" type="innerGatewayType" />
|
||||
<xsd:element name="poller" type="innerPollerType" />
|
||||
<xsd:element name="payload-serializing-transformer" type="specialized-transformer-type" />
|
||||
<xsd:element name="payload-deserializing-transformer" type="specialized-transformer-type" />
|
||||
<xsd:element name="payload-serializing-transformer" type="payload-serializing-transformer-type" />
|
||||
<xsd:element name="payload-deserializing-transformer" type="payload-deserializing-transformer-type" />
|
||||
<xsd:element name="object-to-string-transformer" type="specialized-transformer-type" />
|
||||
<xsd:element name="object-to-map-transformer" type="specialized-transformer-type" />
|
||||
<xsd:element name="map-to-object-transformer" type="map-to-object-transformer-type" />
|
||||
@@ -1629,6 +1629,74 @@
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:element name="payload-serializing-transformer">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a Transformer that converts an object payload to a byte array.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="payload-serializing-transformer-type">
|
||||
<xsd:attributeGroup ref="inputOutputChannelGroup" />
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:complexType name="payload-serializing-transformer-type">
|
||||
<xsd:choice minOccurs="0" maxOccurs="unbounded">
|
||||
<xsd:element ref="poller" />
|
||||
</xsd:choice>
|
||||
<xsd:attribute name="converter" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Reference to a Converter instance that converts from an object to a byte array.
|
||||
This is optional. The default Converter will use standard Java serialization.
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.core.convert.converter.Converter" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:element name="payload-deserializing-transformer">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a Transformer that converts a byte array to an object.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="payload-deserializing-transformer-type">
|
||||
<xsd:attributeGroup ref="inputOutputChannelGroup" />
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:complexType name="payload-deserializing-transformer-type">
|
||||
<xsd:choice minOccurs="0" maxOccurs="unbounded">
|
||||
<xsd:element ref="poller" />
|
||||
</xsd:choice>
|
||||
<xsd:attribute name="converter" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Reference to a Converter instance that converts from a byte array to an object.
|
||||
This is optional. The default Converter will use standard Java deserialization.
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.core.convert.converter.Converter" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:element name="claim-check-in" type="claimCheckTransformerType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
@@ -1670,39 +1738,6 @@
|
||||
<xsd:attributeGroup ref="inputOutputChannelGroup" />
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:element name="payload-serializing-transformer">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a Transformer that serializes any Object payload that implements
|
||||
Serializable into a byte
|
||||
array.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="specialized-transformer-type">
|
||||
<xsd:attributeGroup ref="inputOutputChannelGroup" />
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="payload-deserializing-transformer">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a Transformer that deserializes a byte array payload into an
|
||||
Object.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="specialized-transformer-type">
|
||||
<xsd:attributeGroup ref="inputOutputChannelGroup" />
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:complexType name="specialized-transformer-type">
|
||||
<xsd:choice minOccurs="1" maxOccurs="unbounded">
|
||||
<xsd:any processContents="strict" namespace="##other" minOccurs="0" maxOccurs="unbounded" />
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
<queue capacity="1"/>
|
||||
</channel>
|
||||
|
||||
<channel id="customConverterInput"/>
|
||||
|
||||
<channel id="output">
|
||||
<queue capacity="1"/>
|
||||
</channel>
|
||||
@@ -20,9 +22,11 @@
|
||||
<payload-deserializing-transformer input-channel="directInput" output-channel="output"/>
|
||||
|
||||
<payload-deserializing-transformer input-channel="queueInput" output-channel="output">
|
||||
<poller>
|
||||
<interval-trigger interval="10000"/>
|
||||
</poller>
|
||||
<poller fixed-delay="10000"/>
|
||||
</payload-deserializing-transformer>
|
||||
|
||||
<payload-deserializing-transformer input-channel="customConverterInput" output-channel="output" converter="customConverter"/>
|
||||
|
||||
<beans:bean id="customConverter" class="org.springframework.integration.config.xml.PayloadDeserializingTransformerParserTests$TestDeserializingConverter"/>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -23,12 +23,13 @@ import static org.junit.Assert.assertTrue;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
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.core.convert.converter.Converter;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
@@ -45,15 +46,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
public class PayloadDeserializingTransformerParserTests {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("directInput")
|
||||
private MessageChannel directInput;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("queueInput")
|
||||
private MessageChannel queueInput;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("output")
|
||||
private MessageChannel customConverterInput;
|
||||
|
||||
@Autowired
|
||||
private PollableChannel output;
|
||||
|
||||
|
||||
@@ -103,6 +104,15 @@ public class PayloadDeserializingTransformerParserTests {
|
||||
directInput.send(new GenericMessage<byte[]>(bytes));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customConverter() throws Exception {
|
||||
customConverterInput.send(new GenericMessage<byte[]>("test".getBytes(Charset.forName("UTF-8"))));
|
||||
Message<?> result = output.receive(3000);
|
||||
assertNotNull(result);
|
||||
assertEquals(String.class, result.getPayload().getClass());
|
||||
assertEquals("TEST", result.getPayload());
|
||||
}
|
||||
|
||||
|
||||
private static byte[] serialize(Object object) throws Exception {
|
||||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
||||
@@ -119,4 +129,12 @@ public class PayloadDeserializingTransformerParserTests {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static class TestDeserializingConverter implements Converter<byte[], Object> {
|
||||
|
||||
public Object convert(byte[] source) {
|
||||
return new String(source, Charset.forName("UTF-8")).toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
<queue capacity="1"/>
|
||||
</channel>
|
||||
|
||||
<channel id="customConverterInput"/>
|
||||
|
||||
<channel id="output">
|
||||
<queue capacity="1"/>
|
||||
</channel>
|
||||
@@ -20,9 +22,11 @@
|
||||
<payload-serializing-transformer input-channel="directInput" output-channel="output"/>
|
||||
|
||||
<payload-serializing-transformer input-channel="queueInput" output-channel="output">
|
||||
<poller>
|
||||
<interval-trigger interval="10000"/>
|
||||
</poller>
|
||||
<poller fixed-delay="10000"/>
|
||||
</payload-serializing-transformer>
|
||||
|
||||
<payload-serializing-transformer input-channel="customConverterInput" output-channel="output" converter="customConverter"/>
|
||||
|
||||
<beans:bean id="customConverter" class="org.springframework.integration.config.xml.PayloadSerializingTransformerParserTests$TestSerializingConverter"/>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -23,12 +23,13 @@ import static org.junit.Assert.assertTrue;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
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.core.convert.converter.Converter;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
@@ -45,15 +46,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
public class PayloadSerializingTransformerParserTests {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("directInput")
|
||||
private MessageChannel directInput;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("queueInput")
|
||||
private MessageChannel queueInput;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("output")
|
||||
private MessageChannel customConverterInput;
|
||||
|
||||
@Autowired
|
||||
private PollableChannel output;
|
||||
|
||||
|
||||
@@ -101,6 +102,15 @@ public class PayloadSerializingTransformerParserTests {
|
||||
directInput.send(new GenericMessage<Object>(new Object()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customConverter() throws Exception {
|
||||
customConverterInput.send(new GenericMessage<String>("test"));
|
||||
Message<?> result = output.receive(3000);
|
||||
assertNotNull(result);
|
||||
assertEquals(byte[].class, result.getPayload().getClass());
|
||||
assertEquals("TEST", new String((byte[]) result.getPayload(), Charset.forName("UTF-8")));
|
||||
}
|
||||
|
||||
|
||||
private static Object deserialize(byte[] bytes) throws Exception {
|
||||
ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes);
|
||||
@@ -116,4 +126,12 @@ public class PayloadSerializingTransformerParserTests {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static class TestSerializingConverter implements Converter<Object, byte[]> {
|
||||
|
||||
public byte[] convert(Object source) {
|
||||
return source.toString().toUpperCase().getBytes(Charset.forName("UTF-8"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user