Search in sources :

Example 6 with TcpNetServerConnectionFactory

use of org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory in project spring-integration by spring-projects.

the class TcpReceivingChannelAdapterTests method testException.

@Test
public void testException() throws Exception {
    AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(0);
    noopPublisher(scf);
    ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
    scf.setSerializer(serializer);
    scf.setDeserializer(serializer);
    TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter();
    adapter.setConnectionFactory(scf);
    scf.start();
    TestingUtilities.waitListening(scf, null);
    int port = scf.getPort();
    SubscribableChannel channel = new DirectChannel();
    adapter.setOutputChannel(channel);
    ServiceActivatingHandler handler = new ServiceActivatingHandler(new FailingService());
    channel.subscribe(handler);
    QueueChannel errorChannel = new QueueChannel();
    adapter.setErrorChannel(errorChannel);
    Socket socket = SocketFactory.getDefault().createSocket("localhost", port);
    socket.getOutputStream().write("Test1\r\n".getBytes());
    socket.getOutputStream().write("Test2\r\n".getBytes());
    Message<?> message = errorChannel.receive(10000);
    assertNotNull(message);
    assertEquals("Failed", ((Exception) message.getPayload()).getCause().getMessage());
    message = errorChannel.receive(10000);
    assertNotNull(message);
    assertEquals("Failed", ((Exception) message.getPayload()).getCause().getMessage());
    scf.stop();
}
Also used : ByteArrayCrLfSerializer(org.springframework.integration.ip.tcp.serializer.ByteArrayCrLfSerializer) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) IOException(java.io.IOException) TcpNetServerConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory) AbstractServerConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory) SubscribableChannel(org.springframework.messaging.SubscribableChannel) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Example 7 with TcpNetServerConnectionFactory

use of org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory in project spring-integration by spring-projects.

the class ParserUnitTests method testConnServer2.

@Test
public void testConnServer2() {
    assertTrue(server2 instanceof TcpNetServerConnectionFactory);
    assertEquals(55, server1.getSoLinger());
    assertEquals(1234, server1.getSoReceiveBufferSize());
    assertEquals(1235, server1.getSoSendBufferSize());
    assertEquals(1236, server1.getSoTimeout());
    assertEquals(12, server1.getSoTrafficClass());
    DirectFieldAccessor dfa = new DirectFieldAccessor(server1);
    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"));
    assertEquals(123, dfa.getPropertyValue("backlog"));
    assertNotNull(dfa.getPropertyValue("interceptorFactoryChain"));
}
Also used : TcpNetServerConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 8 with TcpNetServerConnectionFactory

use of org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory in project spring-integration by spring-projects.

the class ConnectionFacforyTests method shouldReturnNetFlavor.

@Test
public void shouldReturnNetFlavor() throws Exception {
    AbstractServerConnectionFactory server = Tcp.netServer(0).get();
    assertTrue(server instanceof TcpNetServerConnectionFactory);
    AbstractClientConnectionFactory client = Tcp.netClient("localhost", server.getPort()).get();
    assertTrue(client instanceof TcpNetClientConnectionFactory);
}
Also used : AbstractClientConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory) TcpNetServerConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory) AbstractServerConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory) TcpNetClientConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory) Test(org.junit.Test)

Example 9 with TcpNetServerConnectionFactory

use of org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory in project spring-integration by spring-projects.

the class FactoryStopStartTests method testRestart.

@Test
public void testRestart() {
    AbstractServerConnectionFactory factory = new TcpNetServerConnectionFactory(0);
    factory.setSoTimeout(10000);
    factory.start();
    factory.stop();
    factory.start();
    factory.stop();
}
Also used : TcpNetServerConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory) AbstractServerConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory) Test(org.junit.Test)

Example 10 with TcpNetServerConnectionFactory

use of org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory in project spring-integration by spring-projects.

the class TcpInboundGatewayTests method testNetSingle.

@Test
public void testNetSingle() throws Exception {
    AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(0);
    scf.setSingleUse(true);
    TcpInboundGateway gateway = new TcpInboundGateway();
    gateway.setConnectionFactory(scf);
    gateway.setBeanFactory(mock(BeanFactory.class));
    scf.start();
    TestingUtilities.waitListening(scf, 20000L);
    int port = scf.getPort();
    final QueueChannel channel = new QueueChannel();
    gateway.setRequestChannel(channel);
    ServiceActivatingHandler handler = new ServiceActivatingHandler(new Service());
    handler.setChannelResolver(channelName -> channel);
    Socket socket1 = SocketFactory.getDefault().createSocket("localhost", port);
    socket1.getOutputStream().write("Test1\r\n".getBytes());
    Socket socket2 = SocketFactory.getDefault().createSocket("localhost", port);
    socket2.getOutputStream().write("Test2\r\n".getBytes());
    handler.handleMessage(channel.receive(10000));
    handler.handleMessage(channel.receive(10000));
    byte[] bytes = new byte[12];
    readFully(socket1.getInputStream(), bytes);
    assertEquals("Echo:Test1\r\n", new String(bytes));
    readFully(socket2.getInputStream(), bytes);
    assertEquals("Echo:Test2\r\n", new String(bytes));
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) TcpNetServerConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory) AbstractServerConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory) BeanFactory(org.springframework.beans.factory.BeanFactory) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Aggregations

TcpNetServerConnectionFactory (org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory)15 Test (org.junit.Test)14 AbstractServerConnectionFactory (org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory)13 ServerSocket (java.net.ServerSocket)8 Socket (java.net.Socket)8 QueueChannel (org.springframework.integration.channel.QueueChannel)7 ByteArrayCrLfSerializer (org.springframework.integration.ip.tcp.serializer.ByteArrayCrLfSerializer)5 BeanFactory (org.springframework.beans.factory.BeanFactory)4 ServiceActivatingHandler (org.springframework.integration.handler.ServiceActivatingHandler)4 DirectChannel (org.springframework.integration.channel.DirectChannel)2 TcpNetClientConnectionFactory (org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory)2 SubscribableChannel (org.springframework.messaging.SubscribableChannel)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 AbstractClientConnectionFactory (org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory)1 TcpNioClientConnectionFactory (org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory)1 TcpNioServerConnectionFactory (org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory)1 MessageChannel (org.springframework.messaging.MessageChannel)1