@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; }
scf.setSingleUse(false); TcpInboundGateway gateway = new TcpInboundGateway(); gateway.setConnectionFactory(scf); scf.start(); TestingUtilities.waitListening(scf, 20000L);
scf.setSingleUse(true); TcpInboundGateway gateway = new TcpInboundGateway(); gateway.setConnectionFactory(scf); SubscribableChannel errorChannel = new DirectChannel(); final String errorMessage = "An error occurred";
@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(); }
ccf.setSingleUse(false); TcpInboundGateway gateway = new TcpInboundGateway(); gateway.setConnectionFactory(ccf); final QueueChannel channel = new QueueChannel(); gateway.setRequestChannel(channel);
server2.setApplicationEventPublisher(NULL_PUBLISHER); TcpInboundGateway gateway1 = new TcpInboundGateway(); gateway1.setConnectionFactory(server1); SubscribableChannel channel = new DirectChannel(); final AtomicReference<String> connectionId = new AtomicReference<String>(); gateway1.start(); TcpInboundGateway gateway2 = new TcpInboundGateway(); gateway2.setConnectionFactory(server2); gateway2.setRequestChannel(channel); gateway2.setBeanFactory(mock(BeanFactory.class));
/** * 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); }
gw.setConnectionFactory(scf); DirectChannel requestChannel = new DirectChannel(); requestChannel.subscribe(message -> ((MessageChannel) message.getHeaders().getReplyChannel()).send(message));
serverNio.afterPropertiesSet(); TcpInboundGateway in = new TcpInboundGateway(); in.setConnectionFactory(serverNio); QueueChannel serverSideChannel = new QueueChannel(); in.setRequestChannel(serverSideChannel);
/** * 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); }
inChannel.setBeanName("inChannel"); TcpInboundGateway inbound = new TcpInboundGateway(); inbound.setConnectionFactory(server); inbound.setRequestChannel(inChannel); inbound.afterPropertiesSet();