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

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

Introduction

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

Prototype

TcpInboundGateway

Source Link

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;//  w  w  w. jav  a2s.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//from   w w w .  jav  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());
}