Search in sources :

Example 21 with DefaultDeserializer

use of org.springframework.core.serializer.DefaultDeserializer in project spring-integration by spring-projects.

the class TcpOutboundGatewayTests method testNetGWPropagatesSocketClose.

@Test
public void testNetGWPropagatesSocketClose() throws Exception {
    ServerSocket serverSocket = ServerSocketFactory.getDefault().createServerSocket(0);
    final int port = serverSocket.getLocalPort();
    AbstractClientConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost", port);
    ccf.setSerializer(new DefaultSerializer());
    ccf.setDeserializer(new DefaultDeserializer());
    ccf.setSoTimeout(10000);
    ccf.setSingleUse(false);
    ccf.start();
    testGWPropagatesSocketCloseGuts(port, ccf, serverSocket);
    serverSocket.close();
}
Also used : AbstractClientConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory) DefaultSerializer(org.springframework.core.serializer.DefaultSerializer) DefaultDeserializer(org.springframework.core.serializer.DefaultDeserializer) ServerSocket(java.net.ServerSocket) TcpNetClientConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory) LongRunningIntegrationTest(org.springframework.integration.test.support.LongRunningIntegrationTest) Test(org.junit.Test)

Example 22 with DefaultDeserializer

use of org.springframework.core.serializer.DefaultDeserializer in project spring-integration by spring-projects.

the class TcpOutboundGatewayTests method testNioGWPropagatesSocketClose.

@Test
public void testNioGWPropagatesSocketClose() throws Exception {
    ServerSocket serverSocket = ServerSocketFactory.getDefault().createServerSocket(0);
    final int port = serverSocket.getLocalPort();
    AbstractClientConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost", port);
    ccf.setSerializer(new DefaultSerializer());
    ccf.setDeserializer(new DefaultDeserializer());
    ccf.setSoTimeout(10000);
    ccf.setSingleUse(false);
    ccf.start();
    testGWPropagatesSocketCloseGuts(port, ccf, serverSocket);
    serverSocket.close();
}
Also used : AbstractClientConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory) DefaultSerializer(org.springframework.core.serializer.DefaultSerializer) DefaultDeserializer(org.springframework.core.serializer.DefaultDeserializer) ServerSocket(java.net.ServerSocket) TcpNioClientConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory) LongRunningIntegrationTest(org.springframework.integration.test.support.LongRunningIntegrationTest) Test(org.junit.Test)

Example 23 with DefaultDeserializer

use of org.springframework.core.serializer.DefaultDeserializer in project spring-integration by spring-projects.

the class TcpSendingMessageHandlerTests method testNioNegotiate.

@Test
public void testNioNegotiate() throws Exception {
    final AtomicReference<ServerSocket> serverSocket = new AtomicReference<ServerSocket>();
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicBoolean done = new AtomicBoolean();
    this.executor.execute(() -> {
        try {
            ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(0);
            serverSocket.set(server);
            latch.countDown();
            Socket socket = server.accept();
            int i = 100;
            while (true) {
                ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
                Object in;
                ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
                if (i == 100) {
                    in = ois.readObject();
                    logger.debug("read object: " + in);
                    oos.writeObject("world!");
                    ois = new ObjectInputStream(socket.getInputStream());
                    oos = new ObjectOutputStream(socket.getOutputStream());
                    Thread.sleep(500);
                }
                in = ois.readObject();
                oos.writeObject("Reply" + (i++));
            }
        } catch (Exception e) {
            if (!done.get()) {
                e.printStackTrace();
            }
        }
    });
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    AbstractConnectionFactory ccf = new TcpNioClientConnectionFactory("localhost", serverSocket.get().getLocalPort());
    noopPublisher(ccf);
    ccf.setSerializer(new DefaultSerializer());
    ccf.setDeserializer(new DefaultDeserializer());
    ccf.setSoTimeout(10000);
    TcpConnectionInterceptorFactoryChain fc = new TcpConnectionInterceptorFactoryChain();
    fc.setInterceptors(new TcpConnectionInterceptorFactory[] { newInterceptorFactory() });
    ccf.setInterceptorFactoryChain(fc);
    ccf.start();
    TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
    handler.setConnectionFactory(ccf);
    TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter();
    adapter.setConnectionFactory(ccf);
    QueueChannel channel = new QueueChannel();
    adapter.setOutputChannel(channel);
    for (int i = 0; i < 1000; i++) {
        handler.handleMessage(MessageBuilder.withPayload("Test").build());
    }
    Set<String> results = new TreeSet<String>();
    for (int i = 0; i < 1000; i++) {
        Message<?> mOut = channel.receive(10000);
        assertNotNull(mOut);
        results.add((String) mOut.getPayload());
    }
    logger.debug("results: " + results);
    for (int i = 100; i < 1100; i++) {
        assertTrue("Missing Reply" + i, results.remove("Reply" + i));
    }
    done.set(true);
    ccf.stop();
    serverSocket.get().close();
}
Also used : AbstractConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory) QueueChannel(org.springframework.integration.channel.QueueChannel) ServerSocket(java.net.ServerSocket) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) ObjectOutputStream(java.io.ObjectOutputStream) TcpNioClientConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory) MessagingException(org.springframework.messaging.MessagingException) SocketException(java.net.SocketException) IOException(java.io.IOException) DefaultSerializer(org.springframework.core.serializer.DefaultSerializer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultDeserializer(org.springframework.core.serializer.DefaultDeserializer) TreeSet(java.util.TreeSet) TcpConnectionInterceptorFactoryChain(org.springframework.integration.ip.tcp.connection.TcpConnectionInterceptorFactoryChain) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 24 with DefaultDeserializer

use of org.springframework.core.serializer.DefaultDeserializer in project spring-integration by spring-projects.

the class TcpSendingMessageHandlerTests method testNetNegotiate.

@Test
public void testNetNegotiate() throws Exception {
    final AtomicReference<ServerSocket> serverSocket = new AtomicReference<ServerSocket>();
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicBoolean done = new AtomicBoolean();
    this.executor.execute(() -> {
        try {
            ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(0);
            serverSocket.set(server);
            latch.countDown();
            Socket socket = server.accept();
            int i = 0;
            while (true) {
                ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
                Object in = null;
                ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
                if (i == 0) {
                    in = ois.readObject();
                    logger.debug("read object: " + in);
                    oos.writeObject("world!");
                    ois = new ObjectInputStream(socket.getInputStream());
                    oos = new ObjectOutputStream(socket.getOutputStream());
                    in = ois.readObject();
                    logger.debug("read object: " + in);
                    oos.writeObject("world!");
                    ois = new ObjectInputStream(socket.getInputStream());
                    oos = new ObjectOutputStream(socket.getOutputStream());
                }
                in = ois.readObject();
                oos.writeObject("Reply" + (++i));
            }
        } catch (Exception e) {
            if (!done.get()) {
                e.printStackTrace();
            }
        }
    });
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    AbstractConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost", serverSocket.get().getLocalPort());
    noopPublisher(ccf);
    ccf.setSerializer(new DefaultSerializer());
    ccf.setDeserializer(new DefaultDeserializer());
    ccf.setSoTimeout(10000);
    TcpConnectionInterceptorFactoryChain fc = new TcpConnectionInterceptorFactoryChain();
    fc.setInterceptors(new TcpConnectionInterceptorFactory[] { newInterceptorFactory(), newInterceptorFactory() });
    ccf.setInterceptorFactoryChain(fc);
    ccf.start();
    TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
    handler.setConnectionFactory(ccf);
    TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter();
    adapter.setConnectionFactory(ccf);
    QueueChannel channel = new QueueChannel();
    adapter.setOutputChannel(channel);
    handler.handleMessage(MessageBuilder.withPayload("Test").build());
    handler.handleMessage(MessageBuilder.withPayload("Test").build());
    Message<?> mOut = channel.receive(10000);
    assertNotNull(mOut);
    assertEquals("Reply1", mOut.getPayload());
    mOut = channel.receive(10000);
    assertNotNull(mOut);
    assertEquals("Reply2", mOut.getPayload());
    done.set(true);
    ccf.stop();
    serverSocket.get().close();
}
Also used : AbstractConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory) QueueChannel(org.springframework.integration.channel.QueueChannel) ServerSocket(java.net.ServerSocket) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) ObjectOutputStream(java.io.ObjectOutputStream) TcpNetClientConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory) MessagingException(org.springframework.messaging.MessagingException) SocketException(java.net.SocketException) IOException(java.io.IOException) DefaultSerializer(org.springframework.core.serializer.DefaultSerializer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultDeserializer(org.springframework.core.serializer.DefaultDeserializer) TcpConnectionInterceptorFactoryChain(org.springframework.integration.ip.tcp.connection.TcpConnectionInterceptorFactoryChain) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 25 with DefaultDeserializer

use of org.springframework.core.serializer.DefaultDeserializer in project spring-integration by spring-projects.

the class DeserializationTests method testReadSerialized.

@Test
public void testReadSerialized() throws Exception {
    ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(0);
    int port = server.getLocalPort();
    server.setSoTimeout(10000);
    CountDownLatch done = SocketTestUtils.testSendSerialized(port);
    Socket socket = server.accept();
    socket.setSoTimeout(5000);
    DefaultDeserializer deserializer = new DefaultDeserializer();
    Object out = deserializer.deserialize(socket.getInputStream());
    assertEquals("Data", SocketTestUtils.TEST_STRING, out);
    out = deserializer.deserialize(socket.getInputStream());
    assertEquals("Data", SocketTestUtils.TEST_STRING, out);
    server.close();
    done.countDown();
}
Also used : DefaultDeserializer(org.springframework.core.serializer.DefaultDeserializer) ServerSocket(java.net.ServerSocket) CountDownLatch(java.util.concurrent.CountDownLatch) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) LongRunningIntegrationTest(org.springframework.integration.test.support.LongRunningIntegrationTest) Test(org.junit.Test)

Aggregations

DefaultDeserializer (org.springframework.core.serializer.DefaultDeserializer)25 DefaultSerializer (org.springframework.core.serializer.DefaultSerializer)24 ServerSocket (java.net.ServerSocket)23 Test (org.junit.Test)21 Socket (java.net.Socket)15 ObjectInputStream (java.io.ObjectInputStream)14 ObjectOutputStream (java.io.ObjectOutputStream)14 AbstractClientConnectionFactory (org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory)14 TcpNetClientConnectionFactory (org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory)14 LongRunningIntegrationTest (org.springframework.integration.test.support.LongRunningIntegrationTest)14 CountDownLatch (java.util.concurrent.CountDownLatch)12 QueueChannel (org.springframework.integration.channel.QueueChannel)12 IOException (java.io.IOException)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 AtomicReference (java.util.concurrent.atomic.AtomicReference)11 TcpConnectionInterceptorFactoryChain (org.springframework.integration.ip.tcp.connection.TcpConnectionInterceptorFactoryChain)7 SocketException (java.net.SocketException)6 HashSet (java.util.HashSet)6 AbstractConnectionFactory (org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory)6 TcpNioClientConnectionFactory (org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory)6