INT-1486 updated IP module for refactored Serialization code
This commit is contained in:
@@ -89,9 +89,9 @@ public abstract class IpAdapterParserUtils {
|
||||
|
||||
static final String TCP_CONNECTION_TYPE = "type";
|
||||
|
||||
static final String INPUT_CONVERTER = "input-converter";
|
||||
static final String SERIALIZER = "serializer";
|
||||
|
||||
static final String OUTPUT_CONVERTER = "output-converter";
|
||||
static final String DESERIALIZER = "deserializer";
|
||||
|
||||
static final String SINGLE_USE = "single-use";
|
||||
|
||||
|
||||
@@ -85,9 +85,9 @@ public class TcpConnectionParser extends AbstractBeanDefinitionParser {
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element,
|
||||
IpAdapterParserUtils.TASK_EXECUTOR);
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element,
|
||||
IpAdapterParserUtils.INPUT_CONVERTER);
|
||||
IpAdapterParserUtils.SERIALIZER);
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element,
|
||||
IpAdapterParserUtils.OUTPUT_CONVERTER);
|
||||
IpAdapterParserUtils.DESERIALIZER);
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element,
|
||||
IpAdapterParserUtils.SINGLE_USE);
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element,
|
||||
|
||||
@@ -70,8 +70,9 @@ public abstract class AbstractClientConnectionFactory extends AbstractConnection
|
||||
}
|
||||
}
|
||||
connection.setMapper(this.mapper);
|
||||
connection.setInputConverter(this.inputConverter);
|
||||
connection.setOutputConverter(this.outputConverter);
|
||||
connection.setDeserializer(this.deserializer);
|
||||
connection.setSerializer(this.serializer);
|
||||
connection.setSingleUse(this.singleUse);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,8 +23,9 @@ import java.util.concurrent.Executors;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.commons.serializer.InputStreamingConverter;
|
||||
import org.springframework.commons.serializer.OutputStreamingConverter;
|
||||
|
||||
import org.springframework.commons.serializer.Deserializer;
|
||||
import org.springframework.commons.serializer.Serializer;
|
||||
import org.springframework.context.SmartLifecycle;
|
||||
import org.springframework.integration.ip.tcp.converter.ByteArrayCrLfConverter;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -67,9 +68,9 @@ public abstract class AbstractConnectionFactory
|
||||
|
||||
protected Executor taskExecutor;
|
||||
|
||||
protected InputStreamingConverter<?> inputConverter = new ByteArrayCrLfConverter();
|
||||
protected Deserializer<?> deserializer = new ByteArrayCrLfConverter();
|
||||
|
||||
protected OutputStreamingConverter<?> outputConverter = new ByteArrayCrLfConverter();
|
||||
protected Serializer<?> serializer = new ByteArrayCrLfConverter();
|
||||
|
||||
protected TcpMessageMapper mapper = new TcpMessageMapper();
|
||||
|
||||
@@ -250,18 +251,18 @@ public abstract class AbstractConnectionFactory
|
||||
|
||||
/**
|
||||
*
|
||||
* @param converter the inputConverter to set
|
||||
* @param deserializer the deserializer to set
|
||||
*/
|
||||
public void setInputConverter(InputStreamingConverter<?> converter) {
|
||||
this.inputConverter = converter;
|
||||
public void setDeserializer(Deserializer<?> deserializer) {
|
||||
this.deserializer = deserializer;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param outputConverter the outputConverter to set
|
||||
* @param serializer the serializer to set
|
||||
*/
|
||||
public void setOutputConverter(OutputStreamingConverter<?> outputConverter) {
|
||||
this.outputConverter = outputConverter;
|
||||
public void setSerializer(Serializer<?> serializer) {
|
||||
this.serializer = serializer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,21 +19,21 @@ package org.springframework.integration.ip.tcp.connection;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Base class for all server connection factories. Server connection factories
|
||||
* listen on a port for incoming connections and create new TcpConnection objects
|
||||
* for each new connection.
|
||||
* for each new connection.
|
||||
*
|
||||
* @author Gary Russell
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public abstract class AbstractServerConnectionFactory extends AbstractConnectionFactory {
|
||||
|
||||
protected boolean listening;
|
||||
|
||||
protected String localAddress;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The port on which the factory will listen.
|
||||
* @param port
|
||||
@@ -41,7 +41,8 @@ public abstract class AbstractServerConnectionFactory extends AbstractConnection
|
||||
public AbstractServerConnectionFactory(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Not supported because the factory manages multiple connections and this
|
||||
* method cannot discriminate.
|
||||
@@ -70,8 +71,8 @@ public abstract class AbstractServerConnectionFactory extends AbstractConnection
|
||||
}
|
||||
connection.registerSender(this.sender);
|
||||
connection.setMapper(this.mapper);
|
||||
connection.setInputConverter(this.inputConverter);
|
||||
connection.setOutputConverter(this.outputConverter);
|
||||
connection.setDeserializer(this.deserializer);
|
||||
connection.setSerializer(this.serializer);
|
||||
connection.setSingleUse(this.singleUse);
|
||||
/*
|
||||
* If we have a collaborating outbound channel adapter and we are configured
|
||||
|
||||
@@ -20,8 +20,9 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.commons.serializer.InputStreamingConverter;
|
||||
import org.springframework.commons.serializer.OutputStreamingConverter;
|
||||
|
||||
import org.springframework.commons.serializer.Deserializer;
|
||||
import org.springframework.commons.serializer.Serializer;
|
||||
import org.springframework.integration.ip.tcp.converter.AbstractByteArrayStreamingConverter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -39,10 +40,10 @@ public abstract class AbstractTcpConnection implements TcpConnection {
|
||||
protected Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected InputStreamingConverter inputConverter;
|
||||
protected Deserializer deserializer;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected OutputStreamingConverter outputConverter;
|
||||
protected Serializer serializer;
|
||||
|
||||
protected TcpMessageMapper mapper;
|
||||
|
||||
@@ -84,42 +85,42 @@ public abstract class AbstractTcpConnection implements TcpConnection {
|
||||
public void setMapper(TcpMessageMapper mapper) {
|
||||
Assert.notNull(mapper, this.getClass().getName() + " Mapper may not be null");
|
||||
this.mapper = mapper;
|
||||
if (this.outputConverter != null &&
|
||||
!(this.outputConverter instanceof AbstractByteArrayStreamingConverter)) {
|
||||
if (this.serializer != null &&
|
||||
!(this.serializer instanceof AbstractByteArrayStreamingConverter)) {
|
||||
mapper.setStringToBytes(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the input converter
|
||||
* @return the deserializer
|
||||
*/
|
||||
public InputStreamingConverter<?> getInputConverter() {
|
||||
return inputConverter;
|
||||
public Deserializer<?> getDeserializer() {
|
||||
return this.deserializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param inputConverter the input converter to set
|
||||
* @param deserializer the deserializer to set
|
||||
*/
|
||||
public void setInputConverter(InputStreamingConverter<?> inputConverter) {
|
||||
this.inputConverter = inputConverter;
|
||||
public void setDeserializer(Deserializer<?> deserializer) {
|
||||
this.deserializer = deserializer;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the output converter
|
||||
* @return the serializer
|
||||
*/
|
||||
public OutputStreamingConverter<?> getOutputConverter() {
|
||||
return outputConverter;
|
||||
public Serializer<?> getSerializer() {
|
||||
return this.serializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param outputConverter the output converter to set
|
||||
* @param serializer the serializer to set
|
||||
*/
|
||||
public void setOutputConverter(OutputStreamingConverter<?> outputConverter) {
|
||||
this.outputConverter = outputConverter;
|
||||
if (!(outputConverter instanceof AbstractByteArrayStreamingConverter)) {
|
||||
mapper.setStringToBytes(false);
|
||||
public void setSerializer(Serializer<?> serializer) {
|
||||
this.serializer = serializer;
|
||||
if (!(serializer instanceof AbstractByteArrayStreamingConverter)) {
|
||||
this.mapper.setStringToBytes(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.ip.tcp.connection;
|
||||
|
||||
|
||||
import org.springframework.commons.serializer.InputStreamingConverter;
|
||||
import org.springframework.commons.serializer.OutputStreamingConverter;
|
||||
import org.springframework.commons.serializer.Deserializer;
|
||||
import org.springframework.commons.serializer.Serializer;
|
||||
import org.springframework.integration.Message;
|
||||
|
||||
/**
|
||||
@@ -26,7 +26,6 @@ import org.springframework.integration.Message;
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractTcpConnectionInterceptor implements TcpConnectionInterceptor {
|
||||
|
||||
@@ -36,6 +35,7 @@ public abstract class AbstractTcpConnectionInterceptor implements TcpConnectionI
|
||||
|
||||
private TcpSender tcpSender;
|
||||
|
||||
|
||||
public void close() {
|
||||
this.theConnection.close();
|
||||
}
|
||||
@@ -90,20 +90,20 @@ public abstract class AbstractTcpConnectionInterceptor implements TcpConnectionI
|
||||
this.theConnection.setMapper(mapper);
|
||||
}
|
||||
|
||||
public InputStreamingConverter<?> getInputConverter() {
|
||||
return this.theConnection.getInputConverter();
|
||||
public Deserializer<?> getDeserializer() {
|
||||
return this.theConnection.getDeserializer();
|
||||
}
|
||||
|
||||
public void setInputConverter(InputStreamingConverter<?> inputConverter) {
|
||||
this.theConnection.setInputConverter(inputConverter);
|
||||
public void setDeserializer(Deserializer<?> deserializer) {
|
||||
this.theConnection.setDeserializer(deserializer);
|
||||
}
|
||||
|
||||
public OutputStreamingConverter<?> getOutputConverter() {
|
||||
return this.theConnection.getOutputConverter();
|
||||
public Serializer<?> getSerializer() {
|
||||
return this.theConnection.getSerializer();
|
||||
}
|
||||
|
||||
public void setOutputConverter(OutputStreamingConverter<?> outputConverter) {
|
||||
this.theConnection.setOutputConverter(outputConverter);
|
||||
public void setSerializer(Serializer<?> serializer) {
|
||||
this.theConnection.setSerializer(serializer);
|
||||
}
|
||||
|
||||
public boolean isServer() {
|
||||
|
||||
@@ -19,8 +19,8 @@ package org.springframework.integration.ip.tcp.connection;
|
||||
import java.net.Socket;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
import org.springframework.commons.serializer.InputStreamingConverter;
|
||||
import org.springframework.commons.serializer.OutputStreamingConverter;
|
||||
import org.springframework.commons.serializer.Deserializer;
|
||||
import org.springframework.commons.serializer.Serializer;
|
||||
import org.springframework.integration.Message;
|
||||
|
||||
/**
|
||||
@@ -119,25 +119,25 @@ public interface TcpConnection extends Runnable {
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the input converter
|
||||
* @return the deserializer
|
||||
*/
|
||||
public InputStreamingConverter<?> getInputConverter();
|
||||
public Deserializer<?> getDeserializer();
|
||||
|
||||
/**
|
||||
* @param inputConverter the inputConverter to set
|
||||
* @param deserializer the deserializer to set
|
||||
*/
|
||||
public void setInputConverter(InputStreamingConverter<?> inputConverter);
|
||||
public void setDeserializer(Deserializer<?> deserializer);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the output converter
|
||||
* @return the serializer
|
||||
*/
|
||||
public OutputStreamingConverter<?> getOutputConverter();
|
||||
public Serializer<?> getSerializer();
|
||||
|
||||
/**
|
||||
* @param outputConverter the outputConverter to set
|
||||
* @param serializer the serializer to set
|
||||
*/
|
||||
public void setOutputConverter(OutputStreamingConverter<?> outputConverter);
|
||||
public void setSerializer(Serializer<?> serializer);
|
||||
|
||||
/**
|
||||
* @return this connection's listener
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.integration.ip.tcp.connection;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
|
||||
import org.springframework.commons.serializer.InputStreamingConverter;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.ip.tcp.SocketIoUtils;
|
||||
import org.springframework.integration.ip.tcp.converter.SoftEndOfStreamException;
|
||||
@@ -64,7 +63,7 @@ public class TcpNetConnection extends AbstractTcpConnection {
|
||||
@SuppressWarnings("unchecked")
|
||||
public synchronized void send(Message<?> message) throws Exception {
|
||||
Object object = mapper.fromMessage(message);
|
||||
this.outputConverter.convert(object, this.socket.getOutputStream());
|
||||
this.serializer.serialize(object, this.socket.getOutputStream());
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Message sent " + message);
|
||||
}
|
||||
@@ -78,7 +77,7 @@ public class TcpNetConnection extends AbstractTcpConnection {
|
||||
}
|
||||
|
||||
public Object getPayload() throws Exception {
|
||||
return this.inputConverter.convert(this.socket.getInputStream());
|
||||
return this.deserializer.deserialize(this.socket.getInputStream());
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
|
||||
@@ -106,7 +106,7 @@ public class TcpNioConnection extends AbstractTcpConnection {
|
||||
public void send(Message<?> message) throws Exception {
|
||||
synchronized(mapper) {
|
||||
Object object = mapper.fromMessage(message);
|
||||
this.outputConverter.convert(object, this.channelOutputStream);
|
||||
this.serializer.serialize(object, this.channelOutputStream);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public class TcpNioConnection extends AbstractTcpConnection {
|
||||
}
|
||||
|
||||
public Object getPayload() throws Exception {
|
||||
return this.inputConverter.convert(pipedInputStream);
|
||||
return this.deserializer.deserialize(pipedInputStream);
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
|
||||
@@ -20,8 +20,9 @@ import java.io.IOException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.commons.serializer.InputStreamingConverter;
|
||||
import org.springframework.commons.serializer.OutputStreamingConverter;
|
||||
|
||||
import org.springframework.commons.serializer.Deserializer;
|
||||
import org.springframework.commons.serializer.Serializer;
|
||||
|
||||
/**
|
||||
* Base class for streaming converters that convert to/from a byte array.
|
||||
@@ -31,8 +32,8 @@ import org.springframework.commons.serializer.OutputStreamingConverter;
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractByteArrayStreamingConverter implements
|
||||
InputStreamingConverter<byte[]>,
|
||||
OutputStreamingConverter<byte[]> {
|
||||
Serializer<byte[]>,
|
||||
Deserializer<byte[]> {
|
||||
|
||||
protected int maxMessageSize = 2048;
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ import java.io.OutputStream;
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
public class ByteArrayCrLfConverter extends AbstractByteArrayStreamingConverter {
|
||||
|
||||
@@ -37,7 +36,7 @@ public class ByteArrayCrLfConverter extends AbstractByteArrayStreamingConverter
|
||||
* is closed immediately after the \r\n (i.e. no data is in the process of
|
||||
* being read).
|
||||
*/
|
||||
public byte[] convert(InputStream inputStream) throws IOException {
|
||||
public byte[] deserialize(InputStream inputStream) throws IOException {
|
||||
byte[] buffer = new byte[this.maxMessageSize];
|
||||
int n = 0;
|
||||
int bite;
|
||||
@@ -66,7 +65,7 @@ public class ByteArrayCrLfConverter extends AbstractByteArrayStreamingConverter
|
||||
/**
|
||||
* Writes the byte[] to the stream and appends \r\n.
|
||||
*/
|
||||
public void convert(byte[] bytes, OutputStream outputStream) throws IOException {
|
||||
public void serialize(byte[] bytes, OutputStream outputStream) throws IOException {
|
||||
outputStream.write(bytes);
|
||||
outputStream.write('\r');
|
||||
outputStream.write('\n');
|
||||
|
||||
@@ -32,8 +32,9 @@ import org.apache.commons.logging.LogFactory;
|
||||
* The length field contains the length of data following the length
|
||||
* field.
|
||||
* (network byte order).
|
||||
*
|
||||
* @author Gary Russell
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public class ByteArrayLengthHeaderConverter extends AbstractByteArrayStreamingConverter {
|
||||
|
||||
@@ -46,7 +47,7 @@ public class ByteArrayLengthHeaderConverter extends AbstractByteArrayStreamingCo
|
||||
* Throws a {@link SoftEndOfStreamException} if the stream
|
||||
* is closed between messages.
|
||||
*/
|
||||
public byte[] convert(InputStream inputStream) throws IOException {
|
||||
public byte[] deserialize(InputStream inputStream) throws IOException {
|
||||
byte[] lengthPart = new byte[4];
|
||||
int status = read(inputStream, lengthPart, true);
|
||||
if (status < 0) {
|
||||
@@ -69,8 +70,7 @@ public class ByteArrayLengthHeaderConverter extends AbstractByteArrayStreamingCo
|
||||
* Writes the byte[] to the output stream, preceded by a 4 byte
|
||||
* length in network byte order (big endian).
|
||||
*/
|
||||
public void convert(byte[] bytes, OutputStream outputStream)
|
||||
throws IOException {
|
||||
public void serialize(byte[] bytes, OutputStream outputStream) throws IOException {
|
||||
ByteBuffer lengthPart = ByteBuffer.allocate(4);
|
||||
lengthPart.putInt(bytes.length);
|
||||
outputStream.write(lengthPart.array());
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.integration.mapping.MessageMappingException;
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
public class ByteArrayStxEtxConverter extends AbstractByteArrayStreamingConverter {
|
||||
|
||||
@@ -45,7 +44,7 @@ public class ByteArrayStxEtxConverter extends AbstractByteArrayStreamingConverte
|
||||
* being read).
|
||||
*
|
||||
*/
|
||||
public byte[] convert(InputStream inputStream) throws IOException {
|
||||
public byte[] deserialize(InputStream inputStream) throws IOException {
|
||||
int bite = inputStream.read();
|
||||
if (bite < 0) {
|
||||
throw new SoftEndOfStreamException("Stream closed between payloads");
|
||||
@@ -71,7 +70,7 @@ public class ByteArrayStxEtxConverter extends AbstractByteArrayStreamingConverte
|
||||
* Writes the byte[] to the stream, prefixed by an ASCII STX character and
|
||||
* terminated with an ASCII ETX character.
|
||||
*/
|
||||
public void convert(byte[] bytes, OutputStream outputStream) throws IOException {
|
||||
public void serialize(byte[] bytes, OutputStream outputStream) throws IOException {
|
||||
outputStream.write(STX);
|
||||
outputStream.write(bytes);
|
||||
outputStream.write(ETX);
|
||||
|
||||
@@ -290,31 +290,31 @@ the factory, the connection will be closed after a response is received.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="input-converter" type="xsd:string" >
|
||||
<xsd:attribute name="serializer" type="xsd:string" >
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.commons.serializer.InputStreamingConverter"/>
|
||||
<tool:expected-type type="org.springframework.commons.serializer.Serializer"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
<xsd:documentation>
|
||||
An InputStreamingConverter that converts message payloads to/from output streams/input streams
|
||||
associated with the connection. Default is ByteArrayCrLfConverter. Input and output converters
|
||||
would normally be the same but this is not required.
|
||||
A Serializer that converts message payloads to/from output streams/input streams
|
||||
associated with the connection. Default is ByteArrayCrLfConverter. Serializer and Deserializer
|
||||
would normally be the same but this is not required.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="output-converter" type="xsd:string" >
|
||||
<xsd:attribute name="deserializer" type="xsd:string" >
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.commons.serializer.OutputStreamingConverter"/>
|
||||
<tool:expected-type type="org.springframework.commons.serializer.Deserializer"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
<xsd:documentation>
|
||||
An OutputStreamingConverter that converts message payloads to/from output streams/input streams
|
||||
associated with the connection. Default is ByteArrayCrLfConverter. Input and output converters
|
||||
would normally be the same but this is not required.
|
||||
A Deserializer that converts message payloads to/from output streams/input streams
|
||||
associated with the connection. Default is ByteArrayCrLfConverter. Serializer and Deserializer
|
||||
would normally be the same but this is not required.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
|
||||
Reference in New Issue
Block a user