use of org.springframework.integration.handler.ServiceActivatingHandler in project spring-integration by spring-projects.
the class ServiceActivatorEndpointTests method returnAddressHeader.
@Test
public void returnAddressHeader() {
QueueChannel channel = new QueueChannel(1);
ServiceActivatingHandler endpoint = this.createEndpoint();
Message<?> message = MessageBuilder.withPayload("foo").setReplyChannel(channel).build();
endpoint.handleMessage(message);
Message<?> reply = channel.receive(0);
assertNotNull(reply);
assertEquals("FOO", reply.getPayload());
}
use of org.springframework.integration.handler.ServiceActivatingHandler in project spring-integration by spring-projects.
the class MessageProducerSupportTests method validateSuccessfulErrorFlowDoesNotThrowErrors.
@Test
public void validateSuccessfulErrorFlowDoesNotThrowErrors() {
TestApplicationContext testApplicationContext = TestUtils.createTestApplicationContext();
testApplicationContext.refresh();
DirectChannel outChannel = new DirectChannel();
outChannel.subscribe(message -> {
throw new RuntimeException("problems");
});
PublishSubscribeChannel errorChannel = new PublishSubscribeChannel();
SuccessfulErrorService errorService = new SuccessfulErrorService();
ServiceActivatingHandler handler = new ServiceActivatingHandler(errorService);
handler.setBeanFactory(testApplicationContext);
handler.afterPropertiesSet();
errorChannel.subscribe(handler);
MessageProducerSupport mps = new MessageProducerSupport() {
};
mps.setOutputChannel(outChannel);
mps.setErrorChannel(errorChannel);
mps.setBeanFactory(testApplicationContext);
mps.afterPropertiesSet();
mps.start();
Message<?> message = new GenericMessage<String>("hello");
mps.sendMessage(message);
assertThat(errorService.lastMessage, instanceOf(ErrorMessage.class));
ErrorMessage errorMessage = (ErrorMessage) errorService.lastMessage;
assertEquals(MessageDeliveryException.class, errorMessage.getPayload().getClass());
MessageDeliveryException exception = (MessageDeliveryException) errorMessage.getPayload();
assertEquals(message, exception.getFailedMessage());
testApplicationContext.close();
}
use of org.springframework.integration.handler.ServiceActivatingHandler in project spring-integration by spring-projects.
the class CorrelationIdTests method testCorrelationNotPassedFromRequestHeaderIfAlreadySetByHandler.
@Test
public void testCorrelationNotPassedFromRequestHeaderIfAlreadySetByHandler() throws Exception {
Object correlationId = "123-ABC";
Message<String> message = MessageBuilder.withPayload("test").setCorrelationId(correlationId).build();
DirectChannel inputChannel = new DirectChannel();
QueueChannel outputChannel = new QueueChannel(1);
ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "createMessage");
serviceActivator.setOutputChannel(outputChannel);
EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, serviceActivator);
endpoint.start();
assertTrue(inputChannel.send(message));
Message<?> reply = outputChannel.receive(0);
assertEquals("456-XYZ", new IntegrationMessageHeaderAccessor(reply).getCorrelationId());
}
use of org.springframework.integration.handler.ServiceActivatingHandler in project spring-integration by spring-projects.
the class CorrelationIdTests method testCorrelationNotCopiedFromRequestMessgeIdIfAlreadySetByHandler.
@Test
public void testCorrelationNotCopiedFromRequestMessgeIdIfAlreadySetByHandler() throws Exception {
Message<?> message = new GenericMessage<String>("test");
DirectChannel inputChannel = new DirectChannel();
QueueChannel outputChannel = new QueueChannel(1);
ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "createMessage");
serviceActivator.setOutputChannel(outputChannel);
EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, serviceActivator);
endpoint.start();
assertTrue(inputChannel.send(message));
Message<?> reply = outputChannel.receive(0);
assertEquals("456-XYZ", new IntegrationMessageHeaderAccessor(reply).getCorrelationId());
}
use of org.springframework.integration.handler.ServiceActivatingHandler in project spring-integration by spring-projects.
the class CorrelationIdTests method testCorrelationIdCopiedFromMessageCorrelationIdIfAvailable.
@Test
public void testCorrelationIdCopiedFromMessageCorrelationIdIfAvailable() {
Message<String> message = MessageBuilder.withPayload("test").setCorrelationId("correlationId").build();
DirectChannel inputChannel = new DirectChannel();
QueueChannel outputChannel = new QueueChannel(1);
ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "upperCase");
serviceActivator.setOutputChannel(outputChannel);
EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, serviceActivator);
endpoint.start();
assertTrue(inputChannel.send(message));
Message<?> reply = outputChannel.receive(0);
assertEquals(new IntegrationMessageHeaderAccessor(message).getCorrelationId(), new IntegrationMessageHeaderAccessor(reply).getCorrelationId());
assertTrue(new IntegrationMessageHeaderAccessor(message).getCorrelationId().equals(new IntegrationMessageHeaderAccessor(reply).getCorrelationId()));
}
Aggregations