use of org.springframework.integration.handler.ServiceActivatingHandler in project spring-integration by spring-projects.
the class TcpInboundGatewayTests method testErrorFlow.
@Test
public void testErrorFlow() throws Exception {
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(0);
scf.setSingleUse(true);
TcpInboundGateway gateway = new TcpInboundGateway();
gateway.setConnectionFactory(scf);
SubscribableChannel errorChannel = new DirectChannel();
final String errorMessage = "An error occurred";
errorChannel.subscribe(message -> {
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
replyChannel.send(new GenericMessage<String>(errorMessage));
});
gateway.setErrorChannel(errorChannel);
scf.start();
TestingUtilities.waitListening(scf, 20000L);
int port = scf.getPort();
final SubscribableChannel channel = new DirectChannel();
gateway.setRequestChannel(channel);
gateway.setBeanFactory(mock(BeanFactory.class));
ServiceActivatingHandler handler = new ServiceActivatingHandler(new FailingService());
channel.subscribe(handler);
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());
byte[] bytes = new byte[errorMessage.length() + 2];
readFully(socket1.getInputStream(), bytes);
assertEquals(errorMessage + "\r\n", new String(bytes));
readFully(socket2.getInputStream(), bytes);
assertEquals(errorMessage + "\r\n", new String(bytes));
}
use of org.springframework.integration.handler.ServiceActivatingHandler 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.handler.ServiceActivatingHandler in project spring-integration by spring-projects.
the class GroovyControlBusFactoryBean method createHandler.
@Override
protected MessageHandler createHandler() {
Binding binding = new ManagedBeansBinding(this.getBeanFactory());
GroovyCommandMessageProcessor processor = new GroovyCommandMessageProcessor(binding, message -> {
Map<String, Object> variables = new HashMap<>();
variables.put("headers", message.getHeaders());
return variables;
});
if (this.customizer != null) {
processor.setCustomizer(this.customizer);
}
if (this.beanClassLoader != null) {
processor.setBeanClassLoader(this.beanClassLoader);
}
if (getBeanFactory() != null) {
processor.setBeanFactory(getBeanFactory());
}
return this.configureHandler(new ServiceActivatingHandler(processor));
}
use of org.springframework.integration.handler.ServiceActivatingHandler in project spring-integration by spring-projects.
the class DirectChannelSubscriptionTests method sendAndReceiveForRegisteredEndpoint.
@Test
public void sendAndReceiveForRegisteredEndpoint() {
TestApplicationContext context = TestUtils.createTestApplicationContext();
ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "handle");
serviceActivator.setOutputChannel(targetChannel);
EventDrivenConsumer endpoint = new EventDrivenConsumer(sourceChannel, serviceActivator);
context.registerEndpoint("testEndpoint", endpoint);
context.refresh();
this.sourceChannel.send(new GenericMessage<String>("foo"));
Message<?> response = this.targetChannel.receive();
assertEquals("foo!", response.getPayload());
context.stop();
}
use of org.springframework.integration.handler.ServiceActivatingHandler in project spring-integration by spring-projects.
the class ServiceActivatorEndpointTests method noReplyTarget.
@Test(expected = MessagingException.class)
public void noReplyTarget() {
ServiceActivatingHandler endpoint = this.createEndpoint();
Message<?> message = MessageBuilder.withPayload("foo").build();
endpoint.handleMessage(message);
}
Aggregations