use of org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory in project spring-integration by spring-projects.
the class TcpReceivingChannelAdapterTests method testException.
@Test
public void testException() throws Exception {
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(0);
noopPublisher(scf);
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
scf.setSerializer(serializer);
scf.setDeserializer(serializer);
TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter();
adapter.setConnectionFactory(scf);
scf.start();
TestingUtilities.waitListening(scf, null);
int port = scf.getPort();
SubscribableChannel channel = new DirectChannel();
adapter.setOutputChannel(channel);
ServiceActivatingHandler handler = new ServiceActivatingHandler(new FailingService());
channel.subscribe(handler);
QueueChannel errorChannel = new QueueChannel();
adapter.setErrorChannel(errorChannel);
Socket socket = SocketFactory.getDefault().createSocket("localhost", port);
socket.getOutputStream().write("Test1\r\n".getBytes());
socket.getOutputStream().write("Test2\r\n".getBytes());
Message<?> message = errorChannel.receive(10000);
assertNotNull(message);
assertEquals("Failed", ((Exception) message.getPayload()).getCause().getMessage());
message = errorChannel.receive(10000);
assertNotNull(message);
assertEquals("Failed", ((Exception) message.getPayload()).getCause().getMessage());
scf.stop();
}
use of org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory in project spring-integration by spring-projects.
the class TcpReceivingChannelAdapterTests method testNioInterceptors.
@Test
public void testNioInterceptors() throws Exception {
AbstractServerConnectionFactory scf = new TcpNioServerConnectionFactory(0);
noopPublisher(scf);
interceptorsGuts(scf);
scf.stop();
}
use of org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory in project spring-integration by spring-projects.
the class TcpReceivingChannelAdapterTests method testNioSingleNoOutboundInterceptors.
@Test
public void testNioSingleNoOutboundInterceptors() throws Exception {
AbstractServerConnectionFactory scf = new TcpNioServerConnectionFactory(0);
noopPublisher(scf);
singleNoOutboundInterceptorsGuts(scf);
scf.stop();
}
use of org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory in project spring-integration by spring-projects.
the class ConnectionFacforyTests method shouldReturnNetFlavor.
@Test
public void shouldReturnNetFlavor() throws Exception {
AbstractServerConnectionFactory server = Tcp.netServer(0).get();
assertTrue(server instanceof TcpNetServerConnectionFactory);
AbstractClientConnectionFactory client = Tcp.netClient("localhost", server.getPort()).get();
assertTrue(client instanceof TcpNetClientConnectionFactory);
}
use of org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory in project spring-integration by spring-projects.
the class ConnectionFacforyTests method test.
@Test
public void test() throws Exception {
ApplicationEventPublisher publisher = e -> {
};
AbstractServerConnectionFactory server = Tcp.netServer(0).backlog(2).soTimeout(5000).get();
final AtomicReference<Message<?>> received = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
server.registerListener(m -> {
received.set(new ObjectToStringTransformer().transform(m));
latch.countDown();
return false;
});
server.setApplicationEventPublisher(publisher);
server.afterPropertiesSet();
server.start();
TestingUtilities.waitListening(server, null);
AbstractClientConnectionFactory client = Tcp.netClient("localhost", server.getPort()).get();
client.setApplicationEventPublisher(publisher);
client.afterPropertiesSet();
client.start();
client.getConnection().send(new GenericMessage<>("foo"));
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals("foo", received.get().getPayload());
client.stop();
server.stop();
}
Aggregations