@Bean public TcpInboundGateway tcpInGate(AbstractServerConnectionFactory connectionFactory) { TcpInboundGateway inGate = new TcpInboundGateway(); inGate.setConnectionFactory(connectionFactory); inGate.setRequestChannel(fromTcp()); return inGate; }
/** * Construct an instance using an existing spring-managed connection factory. * @param connectionFactoryBean the spring-managed bean. */ TcpInboundGatewaySpec(AbstractConnectionFactory connectionFactoryBean) { super(new TcpInboundGateway()); this.connectionFactory = null; this.target.setConnectionFactory(connectionFactoryBean); }
/** * Construct an instance using a connection factory spec. * @param connectionFactorySpec the spec. */ TcpInboundGatewaySpec(AbstractConnectionFactorySpec<?, ?> connectionFactorySpec) { super(new TcpInboundGateway()); this.connectionFactory = connectionFactorySpec.get(); this.target.setConnectionFactory(this.connectionFactory); }
@Bean public TcpInboundGateway inGate(TcpNioServerConnectionFactory sf) { TcpInboundGateway inGate = new TcpInboundGateway(); inGate.setConnectionFactory(sf); inGate.setRequestChannelName("in"); return inGate; }
@Bean public TcpInboundGateway inGate() { TcpInboundGateway inGate = new TcpInboundGateway(); inGate.setConnectionFactory(sf()); inGate.setRequestChannelName("in"); return inGate; }
@Bean public TcpInboundGateway inGate() { TcpInboundGateway inGate = new TcpInboundGateway(); inGate.setConnectionFactory(sf()); inGate.setRequestChannelName("in"); return inGate; }
@Bean public TcpInboundGateway inGate() { TcpInboundGateway inGate = new TcpInboundGateway(); inGate.setConnectionFactory(sf()); inGate.setRequestChannelName("in"); return inGate; }
@Bean public TcpInboundGateway inGate() { TcpInboundGateway inGate = new TcpInboundGateway(); inGate.setConnectionFactory(sf()); inGate.setRequestChannelName("in"); return inGate; }
AbstractServerConnectionFactory scf = new TcpNioServerConnectionFactory(0); scf.setSingleUse(false); TcpInboundGateway gateway = new TcpInboundGateway(); gateway.setConnectionFactory(scf); scf.start();
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(0); scf.setSingleUse(true); TcpInboundGateway gateway = new TcpInboundGateway(); gateway.setConnectionFactory(scf); SubscribableChannel errorChannel = new DirectChannel();
@Test public void testNetNotSingle() throws Exception { AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(0); scf.setSingleUse(false); TcpInboundGateway gateway = new TcpInboundGateway(); gateway.setConnectionFactory(scf); scf.start(); TestingUtilities.waitListening(scf, 20000L); int port = scf.getPort(); final QueueChannel channel = new QueueChannel(); gateway.setRequestChannel(channel); gateway.setBeanFactory(mock(BeanFactory.class)); ServiceActivatingHandler handler = new ServiceActivatingHandler(new Service()); handler.setBeanFactory(mock(BeanFactory.class)); handler.afterPropertiesSet(); Socket socket = SocketFactory.getDefault().createSocket("localhost", port); socket.getOutputStream().write("Test1\r\n".getBytes()); socket.getOutputStream().write("Test2\r\n".getBytes()); handler.handleMessage(channel.receive(10000)); handler.handleMessage(channel.receive(10000)); byte[] bytes = new byte[12]; readFully(socket.getInputStream(), bytes); assertEquals("Echo:Test1\r\n", new String(bytes)); readFully(socket.getInputStream(), bytes); assertEquals("Echo:Test2\r\n", new String(bytes)); gateway.stop(); scf.stop(); }
@Test public void testNioSingle() throws Exception { AbstractServerConnectionFactory scf = new TcpNioServerConnectionFactory(0); scf.setSingleUse(true); TcpInboundGateway gateway = new TcpInboundGateway(); gateway.setConnectionFactory(scf); scf.start(); TestingUtilities.waitListening(scf, 20000L); int port = scf.getPort(); final QueueChannel channel = new QueueChannel(); gateway.setRequestChannel(channel); gateway.setBeanFactory(mock(BeanFactory.class)); ServiceActivatingHandler handler = new ServiceActivatingHandler(new Service()); handler.setChannelResolver(channelName -> channel); handler.setBeanFactory(mock(BeanFactory.class)); handler.afterPropertiesSet(); Socket socket1 = SocketFactory.getDefault().createSocket("localhost", port); socket1.getOutputStream().write("Test1\r\n".getBytes()); Socket socket2 = SocketFactory.getDefault().createSocket("localhost", port); socket2.getOutputStream().write("Test2\r\n".getBytes()); handler.handleMessage(channel.receive(10000)); handler.handleMessage(channel.receive(10000)); byte[] bytes = new byte[12]; readFully(socket1.getInputStream(), bytes); assertEquals("Echo:Test1\r\n", new String(bytes)); readFully(socket2.getInputStream(), bytes); assertEquals("Echo:Test2\r\n", new String(bytes)); gateway.stop(); scf.stop(); }
@Test public void testNetSingle() throws Exception { AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(0); scf.setSingleUse(true); TcpInboundGateway gateway = new TcpInboundGateway(); gateway.setConnectionFactory(scf); gateway.setBeanFactory(mock(BeanFactory.class)); scf.start(); TestingUtilities.waitListening(scf, 20000L); int port = scf.getPort(); final QueueChannel channel = new QueueChannel(); gateway.setRequestChannel(channel); ServiceActivatingHandler handler = new ServiceActivatingHandler(new Service()); handler.setChannelResolver(channelName -> channel); handler.setBeanFactory(mock(BeanFactory.class)); handler.afterPropertiesSet(); Socket socket1 = SocketFactory.getDefault().createSocket("localhost", port); socket1.getOutputStream().write("Test1\r\n".getBytes()); Socket socket2 = SocketFactory.getDefault().createSocket("localhost", port); socket2.getOutputStream().write("Test2\r\n".getBytes()); handler.handleMessage(channel.receive(10000)); handler.handleMessage(channel.receive(10000)); byte[] bytes = new byte[12]; readFully(socket1.getInputStream(), bytes); assertEquals("Echo:Test1\r\n", new String(bytes)); readFully(socket2.getInputStream(), bytes); assertEquals("Echo:Test2\r\n", new String(bytes)); gateway.stop(); scf.stop(); }
AbstractClientConnectionFactory ccf = new TcpNetClientConnectionFactory("localhost", port.get()); ccf.setSingleUse(false); TcpInboundGateway gateway = new TcpInboundGateway(); gateway.setConnectionFactory(ccf); final QueueChannel channel = new QueueChannel();
server1.setApplicationEventPublisher(NULL_PUBLISHER); server2.setApplicationEventPublisher(NULL_PUBLISHER); TcpInboundGateway gateway1 = new TcpInboundGateway(); gateway1.setConnectionFactory(server1); SubscribableChannel channel = new DirectChannel(); gateway1.afterPropertiesSet(); gateway1.start(); TcpInboundGateway gateway2 = new TcpInboundGateway(); gateway2.setConnectionFactory(server2); gateway2.setRequestChannel(channel);
/** * Construct an instance using an existing spring-managed connection factory. * @param connectionFactoryBean the spring-managed bean. */ TcpInboundGatewaySpec(AbstractConnectionFactory connectionFactoryBean) { super(new TcpInboundGateway()); this.connectionFactory = null; this.target.setConnectionFactory(connectionFactoryBean); }
@Test public void testInboundGatewayNoConnectionEvents() { TcpInboundGateway gw = new TcpInboundGateway(); AbstractServerConnectionFactory scf = new AbstractServerConnectionFactory(0) {
serverNio.setSerializer(serializer); serverNio.afterPropertiesSet(); TcpInboundGateway in = new TcpInboundGateway(); in.setConnectionFactory(serverNio); QueueChannel serverSideChannel = new QueueChannel();
/** * Construct an instance using a connection factory spec. * @param connectionFactorySpec the spec. */ TcpInboundGatewaySpec(AbstractConnectionFactorySpec<?, ?> connectionFactorySpec) { super(new TcpInboundGateway()); this.connectionFactory = connectionFactorySpec.get(); this.target.setConnectionFactory(this.connectionFactory); }
DirectChannel inChannel = new DirectChannel(); inChannel.setBeanName("inChannel"); TcpInboundGateway inbound = new TcpInboundGateway(); inbound.setConnectionFactory(server); inbound.setRequestChannel(inChannel);