Example usage for org.springframework.integration.ip.tcp TcpInboundGateway setConnectionFactory

List of usage examples for org.springframework.integration.ip.tcp TcpInboundGateway setConnectionFactory

Introduction

In this page you can find the example usage for org.springframework.integration.ip.tcp TcpInboundGateway setConnectionFactory.

Prototype

public void setConnectionFactory(AbstractConnectionFactory connectionFactory) 

Source Link

Document

Must be AbstractClientConnectionFactory or AbstractServerConnectionFactory .

Usage

From source file:org.openwms.common.comm.app.DriverConfig.java

@Bean
TcpInboundGateway inboundAdapter(AbstractConnectionFactory tcpConnectionFactory) {
    TcpInboundGateway gate = new TcpInboundGateway();
    gate.setConnectionFactory(tcpConnectionFactory);
    gate.setRequestChannel(inboundChannel());
    gate.setReplyChannel(enrichedOutboundChannel());
    return gate;//from   w w w.j a v  a  2s  . c  o  m
}

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

@Test
public void testInboundGatewayNoConnectionEvents() {
    TcpInboundGateway gw = new TcpInboundGateway();
    AbstractServerConnectionFactory scf = new AbstractServerConnectionFactory(0) {

        @Override//w  ww . j  a v  a 2 s.c om
        public void run() {
        }
    };
    final AtomicReference<ApplicationEvent> theEvent = new AtomicReference<ApplicationEvent>();
    scf.setApplicationEventPublisher(new ApplicationEventPublisher() {

        @Override
        public void publishEvent(Object event) {
        }

        @Override
        public void publishEvent(ApplicationEvent event) {
            theEvent.set(event);
        }

    });
    gw.setConnectionFactory(scf);
    DirectChannel requestChannel = new DirectChannel();
    requestChannel.subscribe(new MessageHandler() {

        @Override
        public void handleMessage(Message<?> message) throws MessagingException {
            ((MessageChannel) message.getHeaders().getReplyChannel()).send(message);
        }
    });
    gw.setRequestChannel(requestChannel);
    gw.start();
    Message<String> message = MessageBuilder.withPayload("foo").setHeader(IpHeaders.CONNECTION_ID, "bar")
            .build();
    gw.onMessage(message);
    assertNotNull(theEvent.get());
    TcpConnectionFailedCorrelationEvent event = (TcpConnectionFailedCorrelationEvent) theEvent.get();
    assertEquals("bar", event.getConnectionId());
    assertSame(message, ((MessagingException) event.getCause()).getFailedMessage());
}