Search in sources :

Example 6 with MessageDeliveryException

use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.

the class ErrorMessageExceptionTypeRouterTests method noMatchAndNoDefaultChannel.

@Test
public void noMatchAndNoDefaultChannel() {
    Message<?> failedMessage = new GenericMessage<String>("foo");
    IllegalArgumentException rootCause = new IllegalArgumentException("bad argument");
    RuntimeException middleCause = new RuntimeException(rootCause);
    MessageHandlingException error = new MessageHandlingException(failedMessage, "failed", middleCause);
    ErrorMessage message = new ErrorMessage(error);
    ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter();
    router.setBeanFactory(beanFactory);
    router.setApplicationContext(TestUtils.createTestApplicationContext());
    router.setChannelMapping(MessageDeliveryException.class.getName(), "messageDeliveryExceptionChannel");
    router.setResolutionRequired(true);
    router.setBeanName("fooRouter");
    try {
        router.handleMessage(message);
        fail("MessageDeliveryException expected");
    } catch (Exception e) {
        assertThat(e, instanceOf(MessageDeliveryException.class));
        assertThat(e.getMessage(), containsString("'fooRouter'"));
    }
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) ErrorMessage(org.springframework.messaging.support.ErrorMessage) MessageHandlingException(org.springframework.messaging.MessageHandlingException) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) MessageRejectedException(org.springframework.integration.MessageRejectedException) MessageHandlingException(org.springframework.messaging.MessageHandlingException) Test(org.junit.Test)

Example 7 with MessageDeliveryException

use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.

the class MethodInvokingRouterTests method doTestChannelNameResolutionByMessage.

private void doTestChannelNameResolutionByMessage(MethodInvokingRouter router) {
    QueueChannel fooChannel = new QueueChannel();
    QueueChannel barChannel = new QueueChannel();
    TestChannelResolver channelResolver = new TestChannelResolver();
    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 */
    }
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) QueueChannel(org.springframework.integration.channel.QueueChannel) TestChannelResolver(org.springframework.integration.channel.TestChannelResolver) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException)

Example 8 with MessageDeliveryException

use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.

the class MethodInvokingRouterTests method doTestMultiChannelArrayResolutionByMessage.

private void doTestMultiChannelArrayResolutionByMessage(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 */
    }
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) QueueChannel(org.springframework.integration.channel.QueueChannel) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException)

Example 9 with MessageDeliveryException

use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.

the class MethodInvokingRouterTests method doTestMultiChannelNameArrayResolutionByMessage.

private void doTestMultiChannelNameArrayResolutionByMessage(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);
    assertNotNull(result1a);
    assertEquals("foo", result1a.getPayload());
    Message<?> result1b = barChannel.receive(0);
    assertNotNull(result1b);
    assertEquals("foo", result1b.getPayload());
    router.handleMessage(barMessage);
    Message<?> result2a = fooChannel.receive(0);
    assertNotNull(result2a);
    assertEquals("bar", result2a.getPayload());
    Message<?> result2b = barChannel.receive(0);
    assertNotNull(result2b);
    assertEquals("bar", result2b.getPayload());
    try {
        router.handleMessage(badMessage);
        fail();
    } catch (MessageDeliveryException e) {
    /* Success */
    }
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) QueueChannel(org.springframework.integration.channel.QueueChannel) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException)

Example 10 with MessageDeliveryException

use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.

the class MethodInvokingRouterTests method doTestMultiChannelNameResolutionByMessage.

private void doTestMultiChannelNameResolutionByMessage(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);
    assertNotNull(result1a);
    assertEquals("foo", result1a.getPayload());
    Message<?> result1b = barChannel.receive(0);
    assertNotNull(result1b);
    assertEquals("foo", result1b.getPayload());
    router.handleMessage(barMessage);
    Message<?> result2a = fooChannel.receive(0);
    assertNotNull(result2a);
    assertEquals("bar", result2a.getPayload());
    Message<?> result2b = barChannel.receive(0);
    assertNotNull(result2b);
    assertEquals("bar", result2b.getPayload());
    try {
        router.handleMessage(badMessage);
        fail();
    } catch (MessageDeliveryException e) {
    /* Success */
    }
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) QueueChannel(org.springframework.integration.channel.QueueChannel) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException)

Aggregations

MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)47 Test (org.junit.Test)19 GenericMessage (org.springframework.messaging.support.GenericMessage)17 QueueChannel (org.springframework.integration.channel.QueueChannel)13 MessagingException (org.springframework.messaging.MessagingException)10 MessageChannel (org.springframework.messaging.MessageChannel)8 Message (org.springframework.messaging.Message)6 BeanFactory (org.springframework.beans.factory.BeanFactory)5 DirectChannel (org.springframework.integration.channel.DirectChannel)5 MessageHandler (org.springframework.messaging.MessageHandler)5 MessageHeaders (org.springframework.messaging.MessageHeaders)4 PollableChannel (org.springframework.messaging.PollableChannel)4 IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 SubscribableChannel (org.springframework.messaging.SubscribableChannel)3 MessageHeaderAccessor (org.springframework.messaging.support.MessageHeaderAccessor)3 FileNotFoundException (java.io.FileNotFoundException)2 Date (java.util.Date)2 List (java.util.List)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2