use of org.springframework.messaging.MessageDeliveryException 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.messaging.MessageDeliveryException in project spring-integration by spring-projects.
the class EnableIntegrationTests method testBridgeAnnotations.
@Test
public void testBridgeAnnotations() {
GenericMessage<?> testMessage = new GenericMessage<Object>("foo");
this.bridgeInput.send(testMessage);
Message<?> receive = this.bridgeOutput.receive(2000);
assertNotNull(receive);
assertSame(receive, testMessage);
assertNull(this.bridgeOutput.receive(10));
this.pollableBridgeInput.send(testMessage);
receive = this.pollableBridgeOutput.receive(2000);
assertNotNull(receive);
assertSame(receive, testMessage);
assertNull(this.pollableBridgeOutput.receive(10));
try {
this.metaBridgeInput.send(testMessage);
fail("MessageDeliveryException expected");
} catch (Exception e) {
assertThat(e, Matchers.instanceOf(MessageDeliveryException.class));
assertThat(e.getMessage(), Matchers.containsString("Dispatcher has no subscribers"));
}
this.context.getBean("enableIntegrationTests.ContextConfiguration.metaBridgeOutput.bridgeFrom", Lifecycle.class).start();
this.metaBridgeInput.send(testMessage);
receive = this.metaBridgeOutput.receive(2000);
assertNotNull(receive);
assertSame(receive, testMessage);
assertNull(this.metaBridgeOutput.receive(10));
this.bridgeToInput.send(testMessage);
receive = this.bridgeToOutput.receive(2000);
assertNotNull(receive);
assertSame(receive, testMessage);
assertNull(this.bridgeToOutput.receive(10));
PollableChannel replyChannel = new QueueChannel();
Message<?> bridgeMessage = MessageBuilder.fromMessage(testMessage).setReplyChannel(replyChannel).build();
this.pollableBridgeToInput.send(bridgeMessage);
receive = replyChannel.receive(2000);
assertNotNull(receive);
assertSame(receive, bridgeMessage);
assertNull(replyChannel.receive(10));
try {
this.myBridgeToInput.send(testMessage);
fail("MessageDeliveryException expected");
} catch (Exception e) {
assertThat(e, Matchers.instanceOf(MessageDeliveryException.class));
assertThat(e.getMessage(), Matchers.containsString("Dispatcher has no subscribers"));
}
this.context.getBean("enableIntegrationTests.ContextConfiguration.myBridgeToInput.bridgeTo", Lifecycle.class).start();
this.myBridgeToInput.send(bridgeMessage);
receive = replyChannel.receive(2000);
assertNotNull(receive);
assertSame(receive, bridgeMessage);
assertNull(replyChannel.receive(10));
}
use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.
the class DelayHandlerTests method errorChannelHeaderAndHandlerThrowsExceptionWithDelay.
@Test
public void errorChannelHeaderAndHandlerThrowsExceptionWithDelay() throws Exception {
DirectChannel errorChannel = new DirectChannel();
MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler();
errorHandler.setDefaultErrorChannel(errorChannel);
taskScheduler.setErrorHandler(errorHandler);
this.setDelayExpression();
this.startDelayerHandler();
output.unsubscribe(resultHandler);
errorChannel.subscribe(resultHandler);
output.subscribe(message -> {
throw new UnsupportedOperationException("intentional test failure");
});
Message<?> message = MessageBuilder.withPayload("test").setHeader("delay", "10").setErrorChannel(errorChannel).build();
input.send(message);
waitForLatch(10000);
Message<?> errorMessage = resultHandler.lastMessage;
assertEquals(MessageDeliveryException.class, errorMessage.getPayload().getClass());
MessageDeliveryException exceptionPayload = (MessageDeliveryException) errorMessage.getPayload();
assertSame(message.getPayload(), exceptionPayload.getFailedMessage().getPayload());
assertEquals(UnsupportedOperationException.class, exceptionPayload.getCause().getClass());
assertNotSame(Thread.currentThread(), resultHandler.lastThread);
}
use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.
the class MethodInvokingRouterTests method doTestMultiChannelListResolutionByPayload.
private void doTestMultiChannelListResolutionByPayload(MethodInvokingRouter router, TestChannelResolver channelResolver) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelResolver.addChannel("foo-channel", fooChannel);
channelResolver.addChannel("bar-channel", barChannel);
router.setChannelResolver(channelResolver);
Message<String> fooMessage = new GenericMessage<String>("foo");
Message<String> barMessage = new GenericMessage<String>("bar");
Message<String> badMessage = new GenericMessage<String>("bad");
router.handleMessage(fooMessage);
Message<?> result1a = fooChannel.receive(0);
Message<?> result1b = barChannel.receive(0);
assertNotNull(result1a);
assertEquals("foo", result1a.getPayload());
assertNotNull(result1b);
assertEquals("foo", result1b.getPayload());
router.handleMessage(barMessage);
Message<?> result2a = fooChannel.receive(0);
Message<?> result2b = barChannel.receive(0);
assertNotNull(result2a);
assertEquals("bar", result2a.getPayload());
assertNotNull(result2b);
assertEquals("bar", result2b.getPayload());
try {
router.handleMessage(badMessage);
fail();
} catch (MessageDeliveryException e) {
/* Success */
}
}
use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.
the class MethodInvokingRouterTests method doTestChannelInstanceResolutionByMessage.
private void doTestChannelInstanceResolutionByMessage(MethodInvokingRouter router, TestChannelResolver channelResolver) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelResolver.addChannel("foo-channel", fooChannel);
channelResolver.addChannel("bar-channel", barChannel);
router.setChannelResolver(channelResolver);
Message<String> fooMessage = new GenericMessage<String>("foo");
Message<String> barMessage = new GenericMessage<String>("bar");
Message<String> badMessage = new GenericMessage<String>("bad");
router.handleMessage(fooMessage);
Message<?> result1 = fooChannel.receive(0);
assertNotNull(result1);
assertEquals("foo", result1.getPayload());
router.handleMessage(barMessage);
Message<?> result2 = barChannel.receive(0);
assertNotNull(result2);
assertEquals("bar", result2.getPayload());
try {
router.handleMessage(badMessage);
fail();
} catch (MessageDeliveryException e) {
/* Success */
}
}
Aggregations