Example usage for org.springframework.integration.ip IpHeaders ACTUAL_CONNECTION_ID

List of usage examples for org.springframework.integration.ip IpHeaders ACTUAL_CONNECTION_ID

Introduction

In this page you can find the example usage for org.springframework.integration.ip IpHeaders ACTUAL_CONNECTION_ID.

Prototype

String ACTUAL_CONNECTION_ID

To view the source code for org.springframework.integration.ip IpHeaders ACTUAL_CONNECTION_ID.

Click Source Link

Document

For information only - when using a cached or failover client connection factory, contains the actual underlying connection id.

Usage

From source file:org.springframework.integration.ip.tcp.connection.CachingClientConnectionFactoryTests.java

@Test // INT-3728
public void testEarlyReceive() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    final AbstractClientConnectionFactory factory = new TcpNetClientConnectionFactory("", 0) {

        @Override/* w w  w  .  j ava2  s  . c o  m*/
        protected Socket createSocket(String host, int port) throws IOException {
            Socket mock = mock(Socket.class);
            when(mock.getInputStream()).thenReturn(new ByteArrayInputStream("foo\r\n".getBytes()));
            return mock;
        }

        @Override
        public boolean isActive() {
            return true;
        }

    };
    factory.setApplicationEventPublisher(mock(ApplicationEventPublisher.class));
    final CachingClientConnectionFactory cachingFactory = new CachingClientConnectionFactory(factory, 1);
    final AtomicReference<Message<?>> received = new AtomicReference<Message<?>>();
    cachingFactory.registerListener(message -> {
        if (!(message instanceof ErrorMessage)) {
            received.set(message);
            latch.countDown();
        }
        return false;
    });
    cachingFactory.start();

    cachingFactory.getConnection();
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    assertNotNull(received.get());
    assertNotNull(received.get().getHeaders().get(IpHeaders.ACTUAL_CONNECTION_ID));
    cachingFactory.stop();
}