Search in sources :

Example 6 with AbstractServerConnectionFactory

use of org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory 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 AbstractServerConnectionFactory

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

the class TcpReceivingChannelAdapterTests method testNioInterceptors.

@Test
public void testNioInterceptors() throws Exception {
    AbstractServerConnectionFactory scf = new TcpNioServerConnectionFactory(0);
    noopPublisher(scf);
    interceptorsGuts(scf);
    scf.stop();
}
Also used : TcpNioServerConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory) AbstractServerConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory) Test(org.junit.Test)

Example 8 with AbstractServerConnectionFactory

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

the class TcpReceivingChannelAdapterTests method testNioSingleNoOutboundInterceptors.

@Test
public void testNioSingleNoOutboundInterceptors() throws Exception {
    AbstractServerConnectionFactory scf = new TcpNioServerConnectionFactory(0);
    noopPublisher(scf);
    singleNoOutboundInterceptorsGuts(scf);
    scf.stop();
}
Also used : TcpNioServerConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory) AbstractServerConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory) Test(org.junit.Test)

Example 9 with AbstractServerConnectionFactory

use of org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory 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 10 with AbstractServerConnectionFactory

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

the class ConnectionFacforyTests method test.

@Test
public void test() throws Exception {
    ApplicationEventPublisher publisher = e -> {
    };
    AbstractServerConnectionFactory server = Tcp.netServer(0).backlog(2).soTimeout(5000).get();
    final AtomicReference<Message<?>> received = new AtomicReference<>();
    final CountDownLatch latch = new CountDownLatch(1);
    server.registerListener(m -> {
        received.set(new ObjectToStringTransformer().transform(m));
        latch.countDown();
        return false;
    });
    server.setApplicationEventPublisher(publisher);
    server.afterPropertiesSet();
    server.start();
    TestingUtilities.waitListening(server, null);
    AbstractClientConnectionFactory client = Tcp.netClient("localhost", server.getPort()).get();
    client.setApplicationEventPublisher(publisher);
    client.afterPropertiesSet();
    client.start();
    client.getConnection().send(new GenericMessage<>("foo"));
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    assertEquals("foo", received.get().getPayload());
    client.stop();
    server.stop();
}
Also used : TcpNioClientConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AbstractServerConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory) AtomicReference(java.util.concurrent.atomic.AtomicReference) TimeUnit(java.util.concurrent.TimeUnit) ObjectToStringTransformer(org.springframework.integration.transformer.ObjectToStringTransformer) CountDownLatch(java.util.concurrent.CountDownLatch) TestingUtilities(org.springframework.integration.ip.util.TestingUtilities) AbstractClientConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory) TcpNetServerConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) TcpNioServerConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) Assert.assertEquals(org.junit.Assert.assertEquals) TcpNetClientConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory) AbstractClientConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) ObjectToStringTransformer(org.springframework.integration.transformer.ObjectToStringTransformer) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) AbstractServerConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

AbstractServerConnectionFactory (org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory)26 Test (org.junit.Test)25 TcpNetServerConnectionFactory (org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory)14 Socket (java.net.Socket)13 QueueChannel (org.springframework.integration.channel.QueueChannel)12 ServerSocket (java.net.ServerSocket)10 BeanFactory (org.springframework.beans.factory.BeanFactory)8 TcpNioServerConnectionFactory (org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory)8 ServiceActivatingHandler (org.springframework.integration.handler.ServiceActivatingHandler)6 AbstractClientConnectionFactory (org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)4 ByteArrayCrLfSerializer (org.springframework.integration.ip.tcp.serializer.ByteArrayCrLfSerializer)4 DatagramSocket (java.net.DatagramSocket)3 MessageChannel (org.springframework.messaging.MessageChannel)3 PollableChannel (org.springframework.messaging.PollableChannel)3 HashSet (java.util.HashSet)2 TimeUnit (java.util.concurrent.TimeUnit)2 Log (org.apache.commons.logging.Log)2 Assert.assertEquals (org.junit.Assert.assertEquals)2