INT-1486 updated IP module for refactored Serialization code

This commit is contained in:
Mark Fisher
2010-09-28 15:56:01 -04:00
parent aba3b47060
commit 68648dcb94
28 changed files with 292 additions and 287 deletions

View File

@@ -131,8 +131,8 @@
type="client"
host="localhost"
port="#{tcpIpUtils.findAvailableServerSocket(6000)}"
input-converter="serial"
output-converter="serial"
serializer="defaultSerializer"
deserializer="defaultDeserializer"
so-keep-alive="true"
so-linger="54"
so-receive-buffer-size="1234"
@@ -153,8 +153,8 @@
type="server"
port="#{client1.port}"
local-address="127.0.0.1"
input-converter="serial"
output-converter="serial"
serializer="defaultSerializer"
deserializer="defaultDeserializer"
so-keep-alive="true"
so-linger="55"
so-receive-buffer-size="1234"
@@ -175,8 +175,8 @@
type="client"
host="localhost"
port="#{tcpIpUtils.findAvailableServerSocket(6100)}"
input-converter="serial"
output-converter="serial"
serializer="defaultSerializer"
deserializer="defaultDeserializer"
so-keep-alive="true"
so-linger="54"
so-receive-buffer-size="1234"
@@ -196,8 +196,8 @@
type="server"
port="#{client1.port}"
local-address="127.0.0.1"
input-converter="serial"
output-converter="serial"
serializer="defaultSerializer"
deserializer="defaultDeserializer"
so-keep-alive="true"
so-linger="55"
so-receive-buffer-size="1234"
@@ -214,8 +214,10 @@
<bean id="interceptors" class="org.springframework.integration.ip.tcp.connection.TcpConnectionInterceptorFactoryChain" />
<bean id="serial" class="org.springframework.commons.serializer.java.JavaStreamingConverter" />
<bean id="defaultSerializer" class="org.springframework.commons.serializer.DefaultSerializer" />
<bean id="defaultDeserializer" class="org.springframework.commons.serializer.DefaultDeserializer" />
<ip:tcp-outbound-channel-adapter id="tcpNewOut1"
channel="tcpChannel"
connection-factory="client1" />

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.ip.config;
import static org.junit.Assert.assertEquals;
@@ -23,10 +24,12 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.commons.serializer.InputStreamingConverter;
import org.springframework.commons.serializer.Deserializer;
import org.springframework.commons.serializer.Serializer;
import org.springframework.context.ApplicationContext;
import org.springframework.core.task.TaskExecutor;
import org.springframework.integration.ip.tcp.TcpInboundGateway;
@@ -46,7 +49,6 @@ import org.springframework.integration.ip.udp.UnicastSendingMessageHandler;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Gary Russell
* @since 2.0
@@ -111,8 +113,11 @@ public class ParserUnitTests {
AbstractConnectionFactory cfC2;
@Autowired
InputStreamingConverter<byte[]> converter;
Serializer<?> serializer;
@Autowired
Deserializer<?> deserializer;
@Autowired
@Qualifier(value="server1")
AbstractConnectionFactory server1;
@@ -263,8 +268,8 @@ public class ParserUnitTests {
assertEquals(1236, client1.getSoTimeout());
assertEquals(12, client1.getSoTrafficClass());
DirectFieldAccessor dfa = new DirectFieldAccessor(client1);
assertSame(converter, dfa.getPropertyValue("inputConverter"));
assertSame(converter, dfa.getPropertyValue("outputConverter"));
assertSame(serializer, dfa.getPropertyValue("serializer"));
assertSame(deserializer, dfa.getPropertyValue("deserializer"));
assertEquals(true, dfa.getPropertyValue("soTcpNoDelay"));
assertEquals(true, dfa.getPropertyValue("singleUse"));
assertSame(taskExecutor, dfa.getPropertyValue("taskExecutor"));
@@ -283,8 +288,8 @@ public class ParserUnitTests {
assertEquals(1236, server1.getSoTimeout());
assertEquals(12, server1.getSoTrafficClass());
DirectFieldAccessor dfa = new DirectFieldAccessor(server1);
assertSame(converter, dfa.getPropertyValue("inputConverter"));
assertSame(converter, dfa.getPropertyValue("outputConverter"));
assertSame(serializer, dfa.getPropertyValue("serializer"));
assertSame(deserializer, dfa.getPropertyValue("deserializer"));
assertEquals(true, dfa.getPropertyValue("soTcpNoDelay"));
assertEquals(true, dfa.getPropertyValue("singleUse"));
assertSame(taskExecutor, dfa.getPropertyValue("taskExecutor"));
@@ -304,8 +309,8 @@ public class ParserUnitTests {
assertEquals(1236, client1.getSoTimeout());
assertEquals(12, client1.getSoTrafficClass());
DirectFieldAccessor dfa = new DirectFieldAccessor(client1);
assertSame(converter, dfa.getPropertyValue("inputConverter"));
assertSame(converter, dfa.getPropertyValue("outputConverter"));
assertSame(serializer, dfa.getPropertyValue("serializer"));
assertSame(deserializer, dfa.getPropertyValue("deserializer"));
assertEquals(true, dfa.getPropertyValue("soTcpNoDelay"));
assertEquals(true, dfa.getPropertyValue("singleUse"));
assertSame(taskExecutor, dfa.getPropertyValue("taskExecutor"));
@@ -323,8 +328,8 @@ public class ParserUnitTests {
assertEquals(1236, server1.getSoTimeout());
assertEquals(12, server1.getSoTrafficClass());
DirectFieldAccessor dfa = new DirectFieldAccessor(server1);
assertSame(converter, dfa.getPropertyValue("inputConverter"));
assertSame(converter, dfa.getPropertyValue("outputConverter"));
assertSame(serializer, dfa.getPropertyValue("serializer"));
assertSame(deserializer, dfa.getPropertyValue("deserializer"));
assertEquals(true, dfa.getPropertyValue("soTcpNoDelay"));
assertEquals(true, dfa.getPropertyValue("singleUse"));
assertSame(taskExecutor, dfa.getPropertyValue("taskExecutor"));

View File

@@ -7,10 +7,11 @@
http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="tcpIpUtils" class="org.springframework.integration.ip.util.SocketUtils" />
<bean id="serializer" class="org.springframework.commons.serializer.java.JavaStreamingConverter" />
<bean id="serializer" class="org.springframework.commons.serializer.DefaultSerializer" />
<bean id="deserializer" class="org.springframework.commons.serializer.DefaultDeserializer" />
<bean id="helloWorldInterceptors" class="org.springframework.integration.ip.tcp.connection.TcpConnectionInterceptorFactoryChain">
<property name="interceptors">
@@ -27,8 +28,8 @@
<int-ip:tcp-connection-factory id="server"
type="server"
port="#{tcpIpUtils.findAvailableServerSocket(10100)}"
input-converter="serializer"
output-converter="serializer"
serializer="serializer"
deserializer="deserializer"
using-nio="true"
single-use="true"
interceptor-factory-chain="helloWorldInterceptors"
@@ -41,8 +42,8 @@
single-use="true"
so-timeout="100000"
using-nio="true"
input-converter="serializer"
output-converter="serializer"
serializer="serializer"
deserializer="deserializer"
interceptor-factory-chain="helloWorldInterceptors"
/>

View File

@@ -11,13 +11,15 @@
<bean id="tcpIpUtils" class="org.springframework.integration.ip.util.SocketUtils" />
<bean id="serializer" class="org.springframework.commons.serializer.java.JavaStreamingConverter" />
<bean id="serializer" class="org.springframework.commons.serializer.DefaultSerializer" />
<bean id="deserializer" class="org.springframework.commons.serializer.DefaultDeserializer" />
<int-ip:tcp-connection-factory id="server"
type="server"
port="#{tcpIpUtils.findAvailableServerSocket(10200)}"
input-converter="serializer"
output-converter="serializer"
serializer="serializer"
deserializer="deserializer"
using-nio="true"
single-use="true"
/>
@@ -28,8 +30,8 @@
port="#{server.port}"
single-use="true"
so-timeout="10000"
input-converter="serializer"
output-converter="serializer"
serializer="serializer"
deserializer="deserializer"
/>
<int:channel id="input" />

View File

@@ -16,7 +16,6 @@
package org.springframework.integration.ip.tcp;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

View File

@@ -38,7 +38,8 @@ import javax.net.ServerSocketFactory;
import org.junit.Test;
import org.springframework.commons.serializer.java.JavaStreamingConverter;
import org.springframework.commons.serializer.DefaultDeserializer;
import org.springframework.commons.serializer.DefaultSerializer;
import org.springframework.integration.Message;
import org.springframework.integration.MessageTimeoutException;
import org.springframework.integration.channel.QueueChannel;
@@ -50,7 +51,6 @@ import org.springframework.integration.support.MessageBuilder;
/**
* @author Gary Russell
* @since 2.0
*
*/
public class TcpOutboundGatewayTests {
@@ -69,7 +69,7 @@ public class TcpOutboundGatewayTests {
while (true) {
Socket socket = server.accept();
ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
Object in = ois.readObject();
ois.readObject();
ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
oos.writeObject("Reply" + (i++));
}
@@ -80,9 +80,8 @@ public class TcpOutboundGatewayTests {
}
}
});
JavaStreamingConverter converter = new JavaStreamingConverter();
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(new DefaultSerializer());
ccf.setDeserializer(new DefaultDeserializer());
ccf.setSoTimeout(10000);
ccf.setSingleUse(true);
ccf.setPoolSize(10);
@@ -135,9 +134,8 @@ public class TcpOutboundGatewayTests {
}
});
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost", port);
JavaStreamingConverter converter = new JavaStreamingConverter();
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(new DefaultSerializer());
ccf.setDeserializer(new DefaultDeserializer());
ccf.setSoTimeout(10000);
ccf.setSingleUse(false);
ccf.start();
@@ -188,9 +186,8 @@ public class TcpOutboundGatewayTests {
}
});
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost", port);
JavaStreamingConverter converter = new JavaStreamingConverter();
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(new DefaultSerializer());
ccf.setDeserializer(new DefaultDeserializer());
ccf.setSoTimeout(10000);
ccf.setSingleUse(false);
ccf.start();

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.ip.tcp;
import static org.junit.Assert.assertEquals;
@@ -35,7 +36,9 @@ import java.util.concurrent.Executors;
import javax.net.SocketFactory;
import org.junit.Test;
import org.springframework.commons.serializer.java.JavaStreamingConverter;
import org.springframework.commons.serializer.DefaultDeserializer;
import org.springframework.commons.serializer.DefaultSerializer;
import org.springframework.integration.Message;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
@@ -49,7 +52,6 @@ import org.springframework.integration.ip.util.SocketUtils;
/**
* @author Gary Russell
*
*/
public class TcpReceivingChannelAdapterTests {
@@ -58,8 +60,8 @@ public class TcpReceivingChannelAdapterTests {
final int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(port);
ByteArrayCrLfConverter converter = new ByteArrayCrLfConverter();
scf.setInputConverter(converter);
scf.setOutputConverter(converter);
scf.setSerializer(converter);
scf.setDeserializer(converter);
TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter();
adapter.setConnectionFactory(scf);
scf.start();
@@ -88,8 +90,8 @@ public class TcpReceivingChannelAdapterTests {
final int port = SocketUtils.findAvailableServerSocket();
TcpNioServerConnectionFactory scf = new TcpNioServerConnectionFactory(port);
ByteArrayCrLfConverter converter = new ByteArrayCrLfConverter();
scf.setInputConverter(converter);
scf.setOutputConverter(converter);
scf.setSerializer(converter);
scf.setDeserializer(converter);
scf.setSoTimeout(5000);
TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter();
adapter.setConnectionFactory(scf);
@@ -123,8 +125,8 @@ public class TcpReceivingChannelAdapterTests {
final int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(port);
ByteArrayCrLfConverter converter = new ByteArrayCrLfConverter();
scf.setInputConverter(converter);
scf.setOutputConverter(converter);
scf.setSerializer(converter);
scf.setDeserializer(converter);
TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
handler.setConnectionFactory(scf);
TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter();
@@ -161,8 +163,8 @@ public class TcpReceivingChannelAdapterTests {
final int port = SocketUtils.findAvailableServerSocket();
TcpNioServerConnectionFactory scf = new TcpNioServerConnectionFactory(port);
ByteArrayCrLfConverter converter = new ByteArrayCrLfConverter();
scf.setInputConverter(converter);
scf.setOutputConverter(converter);
scf.setSerializer(converter);
scf.setDeserializer(converter);
TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
handler.setConnectionFactory(scf);
TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter();
@@ -199,8 +201,8 @@ public class TcpReceivingChannelAdapterTests {
final int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(port);
ByteArrayCrLfConverter converter = new ByteArrayCrLfConverter();
scf.setInputConverter(converter);
scf.setOutputConverter(converter);
scf.setSerializer(converter);
scf.setDeserializer(converter);
scf.setSingleUse(true);
TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter();
adapter.setConnectionFactory(scf);
@@ -235,8 +237,8 @@ public class TcpReceivingChannelAdapterTests {
final int port = SocketUtils.findAvailableServerSocket();
TcpNioServerConnectionFactory scf = new TcpNioServerConnectionFactory(port);
ByteArrayCrLfConverter converter = new ByteArrayCrLfConverter();
scf.setInputConverter(converter);
scf.setOutputConverter(converter);
scf.setSerializer(converter);
scf.setDeserializer(converter);
scf.setSingleUse(true);
TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter();
adapter.setConnectionFactory(scf);
@@ -281,8 +283,8 @@ public class TcpReceivingChannelAdapterTests {
final int port = SocketUtils.findAvailableServerSocket();
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(port);
ByteArrayCrLfConverter converter = new ByteArrayCrLfConverter();
scf.setInputConverter(converter);
scf.setOutputConverter(converter);
scf.setSerializer(converter);
scf.setDeserializer(converter);
scf.setSingleUse(true);
TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
handler.setConnectionFactory(scf);
@@ -322,8 +324,8 @@ public class TcpReceivingChannelAdapterTests {
final int port = SocketUtils.findAvailableServerSocket();
TcpNioServerConnectionFactory scf = new TcpNioServerConnectionFactory(port);
ByteArrayCrLfConverter converter = new ByteArrayCrLfConverter();
scf.setInputConverter(converter);
scf.setOutputConverter(converter);
scf.setSerializer(converter);
scf.setDeserializer(converter);
scf.setSingleUse(true);
TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
handler.setConnectionFactory(scf);
@@ -363,8 +365,8 @@ public class TcpReceivingChannelAdapterTests {
final int port = SocketUtils.findAvailableServerSocket();
TcpNioServerConnectionFactory scf = new TcpNioServerConnectionFactory(port);
ByteArrayCrLfConverter converter = new ByteArrayCrLfConverter();
scf.setInputConverter(converter);
scf.setOutputConverter(converter);
scf.setSerializer(converter);
scf.setDeserializer(converter);
scf.setSingleUse(true);
scf.setPoolSize(100);
TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
@@ -444,11 +446,9 @@ public class TcpReceivingChannelAdapterTests {
singleSharedInterceptorsGuts(port, scf);
}
private void interceptorsGuts(final int port,
AbstractServerConnectionFactory scf) throws Exception {
JavaStreamingConverter converter = new JavaStreamingConverter();
scf.setInputConverter(converter);
scf.setOutputConverter(converter);
private void interceptorsGuts(final int port, AbstractServerConnectionFactory scf) throws Exception {
scf.setSerializer(new DefaultSerializer());
scf.setDeserializer(new DefaultDeserializer());
scf.setSingleUse(false);
TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter();
adapter.setConnectionFactory(scf);
@@ -487,11 +487,9 @@ public class TcpReceivingChannelAdapterTests {
assertTrue(results.contains("Test2"));
}
private void singleNoOutboundInterceptorsGuts(final int port,
AbstractServerConnectionFactory scf) throws Exception {
JavaStreamingConverter converter = new JavaStreamingConverter();
scf.setInputConverter(converter);
scf.setOutputConverter(converter);
private void singleNoOutboundInterceptorsGuts(final int port, AbstractServerConnectionFactory scf) throws Exception {
scf.setSerializer(new DefaultSerializer());
scf.setDeserializer(new DefaultDeserializer());
scf.setSingleUse(true);
scf.setSoTimeout(10000);
TcpConnectionInterceptorFactoryChain fc = new TcpConnectionInterceptorFactoryChain();
@@ -536,11 +534,9 @@ public class TcpReceivingChannelAdapterTests {
assertTrue(results.contains("Test2"));
}
private void singleSharedInterceptorsGuts(final int port,
AbstractServerConnectionFactory scf) throws Exception {
JavaStreamingConverter converter = new JavaStreamingConverter();
scf.setInputConverter(converter);
scf.setOutputConverter(converter);
private void singleSharedInterceptorsGuts(final int port, AbstractServerConnectionFactory scf) throws Exception {
scf.setSerializer(new DefaultSerializer());
scf.setDeserializer(new DefaultDeserializer());
scf.setSingleUse(true);
scf.setSoTimeout(60000);
TcpConnectionInterceptorFactoryChain fc = new TcpConnectionInterceptorFactoryChain();
@@ -588,7 +584,5 @@ public class TcpReceivingChannelAdapterTests {
assertEquals("Test1", new ObjectInputStream(socket1.getInputStream()).readObject());
assertEquals("Test2", new ObjectInputStream(socket2.getInputStream()).readObject());
}
}

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.ip.tcp;
import static org.junit.Assert.assertEquals;
@@ -38,7 +39,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
import javax.net.ServerSocketFactory;
import org.junit.Test;
import org.springframework.commons.serializer.java.JavaStreamingConverter;
import org.springframework.commons.serializer.DefaultDeserializer;
import org.springframework.commons.serializer.DefaultSerializer;
import org.springframework.integration.Message;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory;
@@ -53,11 +56,9 @@ import org.springframework.integration.ip.tcp.converter.ByteArrayStxEtxConverter
import org.springframework.integration.ip.util.SocketUtils;
import org.springframework.integration.support.MessageBuilder;
/**
* @author Gary Russell
* @since 2.0
*
*/
public class TcpSendingMessageHandlerTests {
@@ -94,8 +95,8 @@ public class TcpSendingMessageHandlerTests {
});
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost", port);
ByteArrayCrLfConverter converter = new ByteArrayCrLfConverter();
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(converter);
ccf.setDeserializer(converter);
ccf.setSoTimeout(10000);
TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
handler.setConnectionFactory(ccf);
@@ -142,8 +143,8 @@ public class TcpSendingMessageHandlerTests {
});
AbstractConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost", port);
ByteArrayCrLfConverter converter = new ByteArrayCrLfConverter();
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(converter);
ccf.setDeserializer(converter);
ccf.setSoTimeout(10000);
ccf.start();
TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
@@ -194,8 +195,8 @@ public class TcpSendingMessageHandlerTests {
});
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost", port);
ByteArrayStxEtxConverter converter = new ByteArrayStxEtxConverter();
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(converter);
ccf.setDeserializer(converter);
ccf.setSoTimeout(10000);
ccf.start();
TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
@@ -243,8 +244,8 @@ public class TcpSendingMessageHandlerTests {
});
AbstractConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost", port);
ByteArrayStxEtxConverter converter = new ByteArrayStxEtxConverter();
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(converter);
ccf.setDeserializer(converter);
ccf.setSoTimeout(10000);
ccf.start();
TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
@@ -298,8 +299,8 @@ public class TcpSendingMessageHandlerTests {
});
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost", port);
ByteArrayLengthHeaderConverter converter = new ByteArrayLengthHeaderConverter();
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(converter);
ccf.setDeserializer(converter);
ccf.setSoTimeout(10000);
ccf.start();
TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
@@ -350,8 +351,8 @@ public class TcpSendingMessageHandlerTests {
});
AbstractConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost", port);
ByteArrayLengthHeaderConverter converter = new ByteArrayLengthHeaderConverter();
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(converter);
ccf.setDeserializer(converter);
ccf.setSoTimeout(10000);
ccf.start();
TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
@@ -401,9 +402,8 @@ public class TcpSendingMessageHandlerTests {
}
});
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost", port);
JavaStreamingConverter converter = new JavaStreamingConverter();
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(new DefaultSerializer());
ccf.setDeserializer(new DefaultDeserializer());
ccf.setSoTimeout(10000);
ccf.start();
TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
@@ -450,9 +450,8 @@ public class TcpSendingMessageHandlerTests {
}
});
AbstractConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost", port);
JavaStreamingConverter converter = new JavaStreamingConverter();
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(new DefaultSerializer());
ccf.setDeserializer(new DefaultDeserializer());
ccf.setSoTimeout(10000);
ccf.start();
TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
@@ -503,8 +502,8 @@ public class TcpSendingMessageHandlerTests {
});
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost", port);
ByteArrayCrLfConverter converter = new ByteArrayCrLfConverter();
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(converter);
ccf.setDeserializer(converter);
ccf.setSoTimeout(10000);
ccf.start();
ccf.setSingleUse(true);
@@ -544,8 +543,8 @@ public class TcpSendingMessageHandlerTests {
});
AbstractConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost", port);
ByteArrayCrLfConverter converter = new ByteArrayCrLfConverter();
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(converter);
ccf.setDeserializer(converter);
ccf.setSoTimeout(10000);
ccf.start();
ccf.setSingleUse(true);
@@ -587,8 +586,8 @@ public class TcpSendingMessageHandlerTests {
});
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost", port);
ByteArrayCrLfConverter converter = new ByteArrayCrLfConverter();
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(converter);
ccf.setDeserializer(converter);
ccf.setSoTimeout(10000);
ccf.start();
ccf.setSingleUse(true);
@@ -642,8 +641,8 @@ public class TcpSendingMessageHandlerTests {
});
AbstractConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost", port);
ByteArrayCrLfConverter converter = new ByteArrayCrLfConverter();
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(converter);
ccf.setDeserializer(converter);
ccf.setSoTimeout(10000);
ccf.start();
ccf.setSingleUse(true);
@@ -697,8 +696,8 @@ public class TcpSendingMessageHandlerTests {
});
AbstractConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost", port);
ByteArrayCrLfConverter converter = new ByteArrayCrLfConverter();
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(converter);
ccf.setDeserializer(converter);
ccf.setSoTimeout(10000);
ccf.setSingleUse(true);
ccf.setTaskExecutor(Executors.newFixedThreadPool(100));
@@ -771,9 +770,8 @@ public class TcpSendingMessageHandlerTests {
}
});
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost", port);
JavaStreamingConverter converter = new JavaStreamingConverter();
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(new DefaultSerializer());
ccf.setDeserializer(new DefaultDeserializer());
ccf.setSoTimeout(10000);
TcpConnectionInterceptorFactoryChain fc = new TcpConnectionInterceptorFactoryChain();
fc.setInterceptors(new TcpConnectionInterceptorFactory[]
@@ -834,9 +832,8 @@ public class TcpSendingMessageHandlerTests {
}
});
AbstractConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost", port);
JavaStreamingConverter converter = new JavaStreamingConverter();
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(new DefaultSerializer());
ccf.setDeserializer(new DefaultDeserializer());
ccf.setSoTimeout(10000);
TcpConnectionInterceptorFactoryChain fc = new TcpConnectionInterceptorFactoryChain();
fc.setInterceptors(new TcpConnectionInterceptorFactory[] {new HelloWorldInterceptorFactory()});
@@ -904,9 +901,8 @@ public class TcpSendingMessageHandlerTests {
}
});
AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost", port);
JavaStreamingConverter converter = new JavaStreamingConverter();
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(new DefaultSerializer());
ccf.setDeserializer(new DefaultDeserializer());
ccf.setSoTimeout(10000);
TcpConnectionInterceptorFactoryChain fc = new TcpConnectionInterceptorFactoryChain();
fc.setInterceptors(new TcpConnectionInterceptorFactory[]
@@ -961,9 +957,8 @@ public class TcpSendingMessageHandlerTests {
}
});
AbstractConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost", port);
JavaStreamingConverter converter = new JavaStreamingConverter();
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(new DefaultSerializer());
ccf.setDeserializer(new DefaultDeserializer());
ccf.setSoTimeout(10000);
TcpConnectionInterceptorFactoryChain fc = new TcpConnectionInterceptorFactoryChain();
fc.setInterceptors(new TcpConnectionInterceptorFactory[]

View File

@@ -15,119 +15,119 @@
<bean id="crLfConverter" class="org.springframework.integration.ip.tcp.converter.ByteArrayCrLfConverter" />
<bean id="stxEtxConverter" class="org.springframework.integration.ip.tcp.converter.ByteArrayStxEtxConverter" />
<bean id="lengthHeaderConverter" class="org.springframework.integration.ip.tcp.converter.ByteArrayLengthHeaderConverter" />
<bean id="javaConverter" class="org.springframework.commons.serializer.java.JavaStreamingConverter" />
<bean id="javaSerializer" class="org.springframework.commons.serializer.DefaultSerializer" />
<bean id="javaDeserializer" class="org.springframework.commons.serializer.DefaultDeserializer" />
<ip:tcp-connection-factory id="crLfServer"
type="server"
port="#{tcpIpUtils.findAvailableServerSocket(7000)}"
input-converter="crLfConverter"
output-converter="crLfConverter"/>
serializer="crLfConverter"
deserializer="crLfConverter"/>
<ip:tcp-connection-factory id="stxEtxServer"
type="server"
port="#{tcpIpUtils.findAvailableServerSocket(7100)}"
input-converter="stxEtxConverter"
output-converter="stxEtxConverter"/>
serializer="stxEtxConverter"
deserializer="stxEtxConverter"/>
<ip:tcp-connection-factory id="lengthHeaderServer"
type="server"
port="#{tcpIpUtils.findAvailableServerSocket(7200)}"
input-converter="lengthHeaderConverter"
output-converter="lengthHeaderConverter"/>
serializer="lengthHeaderConverter"
deserializer="lengthHeaderConverter"/>
<ip:tcp-connection-factory id="javaSerialServer"
type="server"
port="#{tcpIpUtils.findAvailableServerSocket(7300)}"
input-converter="javaConverter"
output-converter="javaConverter"/>
serializer="javaSerializer"
deserializer="javaDeserializer"/>
<ip:tcp-connection-factory id="crLfClient"
type="client"
host="localhost"
port="#{crLfServer.port}"
input-converter="crLfConverter"
output-converter="crLfConverter"/>
serializer="crLfConverter"
deserializer="crLfConverter"/>
<ip:tcp-connection-factory id="stxEtxClient"
type="client"
host="localhost"
port="#{stxEtxServer.port}"
input-converter="stxEtxConverter"
output-converter="stxEtxConverter"/>
serializer="stxEtxConverter"
deserializer="stxEtxConverter"/>
<ip:tcp-connection-factory id="lengthHeaderClient"
type="client"
host="localhost"
port="#{lengthHeaderServer.port}"
input-converter="lengthHeaderConverter"
output-converter="lengthHeaderConverter"/>
serializer="lengthHeaderConverter"
deserializer="lengthHeaderConverter"/>
<ip:tcp-connection-factory id="javaSerialClient"
type="client"
host="localhost"
port="#{javaSerialServer.port}"
input-converter="javaConverter"
output-converter="javaConverter"/>
serializer="javaSerializer"
deserializer="javaDeserializer"/>
<ip:tcp-connection-factory id="crLfServerNio"
type="server"
port="#{tcpIpUtils.findAvailableServerSocket(7400)}"
input-converter="crLfConverter"
output-converter="crLfConverter"
serializer="crLfConverter"
deserializer="crLfConverter"
using-nio="true"/>
<ip:tcp-connection-factory id="stxEtxServerNio"
type="server"
port="#{tcpIpUtils.findAvailableServerSocket(7500)}"
input-converter="stxEtxConverter"
output-converter="stxEtxConverter"
serializer="stxEtxConverter"
deserializer="stxEtxConverter"
using-nio="true"/>
<ip:tcp-connection-factory id="lengthHeaderServerNio"
type="server"
port="#{tcpIpUtils.findAvailableServerSocket(7600)}"
input-converter="lengthHeaderConverter"
output-converter="lengthHeaderConverter"
serializer="lengthHeaderConverter"
deserializer="lengthHeaderConverter"
using-nio="true"/>
<ip:tcp-connection-factory id="javaSerialServerNio"
type="server"
port="#{tcpIpUtils.findAvailableServerSocket(7700)}"
input-converter="javaConverter"
output-converter="javaConverter"
serializer="javaSerializer"
deserializer="javaDeserializer"
using-nio="true"/>
<ip:tcp-connection-factory id="crLfClientNio"
type="client"
host="localhost"
port="#{crLfServer.port}"
input-converter="crLfConverter"
output-converter="crLfConverter"
serializer="crLfConverter"
deserializer="crLfConverter"
using-nio="true"/>
<ip:tcp-connection-factory id="stxEtxClientNio"
type="client"
host="localhost"
port="#{stxEtxServer.port}"
input-converter="stxEtxConverter"
output-converter="stxEtxConverter"
serializer="stxEtxConverter"
deserializer="stxEtxConverter"
using-nio="true"/>
<ip:tcp-connection-factory id="lengthHeaderClientNio"
type="client"
host="localhost"
port="#{lengthHeaderServer.port}"
input-converter="lengthHeaderConverter"
output-converter="lengthHeaderConverter"
serializer="lengthHeaderConverter"
deserializer="lengthHeaderConverter"
using-nio="true"/>
<ip:tcp-connection-factory id="javaSerialClientNio"
type="client"
host="localhost"
port="#{javaSerialServer.port}"
input-converter="javaConverter"
output-converter="javaConverter"
serializer="javaSerializer"
deserializer="javaDeserializer"
using-nio="true"/>
</beans>

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.ip.tcp.connection;
import static org.junit.Assert.assertEquals;
@@ -31,6 +32,7 @@ import java.util.concurrent.TimeUnit;
import javax.net.SocketFactory;
import org.junit.Test;
import org.springframework.integration.Message;
import org.springframework.integration.ip.tcp.converter.AbstractByteArrayStreamingConverter;
import org.springframework.integration.ip.tcp.converter.ByteArrayCrLfConverter;
@@ -40,7 +42,7 @@ import org.springframework.integration.ip.util.SocketUtils;
/**
* @author Gary Russell
*
* @since 2.0
*/
public class TcpNioConnectionReadTests {
@@ -54,8 +56,8 @@ public class TcpNioConnectionReadTests {
private AbstractServerConnectionFactory getConnectionFactory(int port,
AbstractByteArrayStreamingConverter converter, TcpListener listener, TcpSender sender) throws Exception {
AbstractServerConnectionFactory scf = new TcpNioServerConnectionFactory(port);
scf.setInputConverter(converter);
scf.setOutputConverter(converter);
scf.setSerializer(converter);
scf.setDeserializer(converter);
scf.registerListener(listener);
if (sender != null) {
scf.registerSender(sender);

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.ip.tcp.connection;
import static org.junit.Assert.assertEquals;
@@ -26,6 +27,7 @@ import java.nio.ByteBuffer;
import javax.net.ServerSocketFactory;
import org.junit.Test;
import org.springframework.integration.ip.tcp.converter.AbstractByteArrayStreamingConverter;
import org.springframework.integration.ip.tcp.converter.ByteArrayCrLfConverter;
import org.springframework.integration.ip.tcp.converter.ByteArrayLengthHeaderConverter;
@@ -35,15 +37,15 @@ import org.springframework.integration.support.MessageBuilder;
/**
* @author Gary Russell
*
* @since 2.0
*/
public class TcpNioConnectionWriteTests {
private AbstractConnectionFactory getClientConnectionFactory(boolean direct,
final int port, AbstractByteArrayStreamingConverter converter) {
TcpNioClientConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost", port);
ccf.setInputConverter(converter);
ccf.setOutputConverter(converter);
ccf.setSerializer(converter);
ccf.setDeserializer(converter);
ccf.setSoTimeout(10000);
ccf.setUsingDirectBuffers(direct);
ccf.start();

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.ip.tcp.converter;
import static org.junit.Assert.assertEquals;
@@ -25,14 +26,15 @@ import java.net.Socket;
import javax.net.ServerSocketFactory;
import org.junit.Test;
import org.springframework.commons.serializer.java.JavaStreamingConverter;
import org.springframework.commons.serializer.DefaultDeserializer;
import org.springframework.integration.ip.util.SocketUtils;
/**
* @author Gary Russell
*
* @since 2.0
*/
public class InputConverterTests {
public class DeserializationTests {
@Test
public void testReadLength() throws Exception {
@@ -43,10 +45,10 @@ public class InputConverterTests {
Socket socket = server.accept();
socket.setSoTimeout(5000);
ByteArrayLengthHeaderConverter converter = new ByteArrayLengthHeaderConverter();
byte[] out = converter.convert(socket.getInputStream());
byte[] out = converter.deserialize(socket.getInputStream());
assertEquals("Data", SocketUtils.TEST_STRING + SocketUtils.TEST_STRING,
new String(out));
out = converter.convert(socket.getInputStream());
out = converter.deserialize(socket.getInputStream());
assertEquals("Data", SocketUtils.TEST_STRING + SocketUtils.TEST_STRING,
new String(out));
server.close();
@@ -61,10 +63,10 @@ public class InputConverterTests {
Socket socket = server.accept();
socket.setSoTimeout(5000);
ByteArrayStxEtxConverter converter = new ByteArrayStxEtxConverter();
byte[] out = converter.convert(socket.getInputStream());
byte[] out = converter.deserialize(socket.getInputStream());
assertEquals("Data", SocketUtils.TEST_STRING + SocketUtils.TEST_STRING,
new String(out));
out = converter.convert(socket.getInputStream());
out = converter.deserialize(socket.getInputStream());
assertEquals("Data", SocketUtils.TEST_STRING + SocketUtils.TEST_STRING,
new String(out));
server.close();
@@ -79,10 +81,10 @@ public class InputConverterTests {
Socket socket = server.accept();
socket.setSoTimeout(5000);
ByteArrayCrLfConverter converter = new ByteArrayCrLfConverter();
byte[] out = converter.convert(socket.getInputStream());
byte[] out = converter.deserialize(socket.getInputStream());
assertEquals("Data", SocketUtils.TEST_STRING + SocketUtils.TEST_STRING,
new String(out));
out = converter.convert(socket.getInputStream());
out = converter.deserialize(socket.getInputStream());
assertEquals("Data", SocketUtils.TEST_STRING + SocketUtils.TEST_STRING,
new String(out));
server.close();
@@ -96,10 +98,10 @@ public class InputConverterTests {
SocketUtils.testSendSerialized(port);
Socket socket = server.accept();
socket.setSoTimeout(5000);
JavaStreamingConverter converter = new JavaStreamingConverter();
Object out = converter.convert(socket.getInputStream());
DefaultDeserializer deserializer = new DefaultDeserializer();
Object out = deserializer.deserialize(socket.getInputStream());
assertEquals("Data", SocketUtils.TEST_STRING, out);
out = converter.convert(socket.getInputStream());
out = deserializer.deserialize(socket.getInputStream());
assertEquals("Data", SocketUtils.TEST_STRING, out);
server.close();
}
@@ -114,7 +116,7 @@ public class InputConverterTests {
socket.setSoTimeout(5000);
ByteArrayLengthHeaderConverter converter = new ByteArrayLengthHeaderConverter();
try {
converter.convert(socket.getInputStream());
converter.deserialize(socket.getInputStream());
fail("Expected message length exceeded exception");
} catch (IOException e) {
if (!e.getMessage().startsWith("Message length")) {
@@ -135,7 +137,7 @@ public class InputConverterTests {
socket.setSoTimeout(500);
ByteArrayStxEtxConverter converter = new ByteArrayStxEtxConverter();
try {
converter.convert(socket.getInputStream());
converter.deserialize(socket.getInputStream());
fail("Expected timeout exception");
} catch (IOException e) {
if (!e.getMessage().startsWith("Read timed out")) {
@@ -157,7 +159,7 @@ public class InputConverterTests {
ByteArrayStxEtxConverter converter = new ByteArrayStxEtxConverter();
converter.setMaxMessageSize(1024);
try {
converter.convert(socket.getInputStream());
converter.deserialize(socket.getInputStream());
fail("Expected message length exceeded exception");
} catch (IOException e) {
if (!e.getMessage().startsWith("ETX not found")) {
@@ -178,7 +180,7 @@ public class InputConverterTests {
socket.setSoTimeout(500);
ByteArrayCrLfConverter converter = new ByteArrayCrLfConverter();
try {
converter.convert(socket.getInputStream());
converter.deserialize(socket.getInputStream());
fail("Expected timout exception");
} catch (IOException e) {
if (!e.getMessage().startsWith("Read timed out")) {
@@ -200,7 +202,7 @@ public class InputConverterTests {
ByteArrayCrLfConverter converter = new ByteArrayCrLfConverter();
converter.setMaxMessageSize(1024);
try {
converter.convert(socket.getInputStream());
converter.deserialize(socket.getInputStream());
fail("Expected message length exceeded exception");
} catch (IOException e) {
if (!e.getMessage().startsWith("CRLF not found")) {
@@ -210,5 +212,5 @@ public class InputConverterTests {
}
server.close();
}
}

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.ip.tcp.converter;
import static org.junit.Assert.assertEquals;
@@ -28,14 +29,15 @@ import javax.net.ServerSocketFactory;
import javax.net.SocketFactory;
import org.junit.Test;
import org.springframework.commons.serializer.java.JavaStreamingConverter;
import org.springframework.commons.serializer.DefaultSerializer;
import org.springframework.integration.ip.util.SocketUtils;
/**
* @author Gary Russell
*
* @since 2.0
*/
public class OutputConverterTests {
public class SerializationTests {
@Test
public void testWriteLengthHeader() throws Exception {
@@ -50,7 +52,7 @@ public class OutputConverterTests {
ByteBuffer buffer = ByteBuffer.allocate(testString.length());
buffer.put(testString.getBytes());
ByteArrayLengthHeaderConverter converter = new ByteArrayLengthHeaderConverter();
converter.convert(buffer.array(), socket.getOutputStream());
converter.serialize(buffer.array(), socket.getOutputStream());
Thread.sleep(1000000000L);
} catch (Exception e) {
e.printStackTrace();
@@ -83,7 +85,7 @@ public class OutputConverterTests {
ByteBuffer buffer = ByteBuffer.allocate(testString.length());
buffer.put(testString.getBytes());
ByteArrayStxEtxConverter converter = new ByteArrayStxEtxConverter();
converter.convert(buffer.array(), socket.getOutputStream());
converter.serialize(buffer.array(), socket.getOutputStream());
Thread.sleep(1000000000L);
} catch (Exception e) {
e.printStackTrace();
@@ -116,7 +118,7 @@ public class OutputConverterTests {
ByteBuffer buffer = ByteBuffer.allocate(testString.length());
buffer.put(testString.getBytes());
ByteArrayCrLfConverter converter = new ByteArrayCrLfConverter();
converter.convert(buffer.array(), socket.getOutputStream());
converter.serialize(buffer.array(), socket.getOutputStream());
Thread.sleep(1000000000L);
} catch (Exception e) {
e.printStackTrace();
@@ -146,9 +148,9 @@ public class OutputConverterTests {
public void run() {
try {
Socket socket = SocketFactory.getDefault().createSocket("localhost", port);
JavaStreamingConverter converter = new JavaStreamingConverter();
converter.convert(testString, socket.getOutputStream());
converter.convert(testString, socket.getOutputStream());
DefaultSerializer serializer = new DefaultSerializer();
serializer.serialize(testString, socket.getOutputStream());
serializer.serialize(testString, socket.getOutputStream());
Thread.sleep(1000000000L);
} catch (Exception e) {
e.printStackTrace();