Search in sources :

Example 41 with ErrorMessage

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

the class ErrorMessageExceptionTypeRouterTests method fallbackToErrorMessageType.

@Test
public void fallbackToErrorMessageType() {
    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(MessageHandlingException.class.getName(), "messageHandlingExceptionChannel");
    router.setDefaultOutputChannel(defaultChannel);
    router.handleMessage(message);
    assertNotNull(messageHandlingExceptionChannel.receive(1000));
    assertNull(runtimeExceptionChannel.receive(0));
    assertNull(illegalArgumentChannel.receive(0));
    assertNull(defaultChannel.receive(0));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) ErrorMessage(org.springframework.messaging.support.ErrorMessage) MessageHandlingException(org.springframework.messaging.MessageHandlingException) Test(org.junit.Test)

Example 42 with ErrorMessage

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

the class ErrorMessageExceptionTypeRouterTests method mostSpecificCause.

@Test
public void mostSpecificCause() {
    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(IllegalArgumentException.class.getName(), "illegalArgumentChannel");
    router.setChannelMapping(RuntimeException.class.getName(), "runtimeExceptionChannel");
    router.setChannelMapping(MessageHandlingException.class.getName(), "messageHandlingExceptionChannel");
    router.setDefaultOutputChannel(defaultChannel);
    router.handleMessage(message);
    assertNotNull(illegalArgumentChannel.receive(1000));
    assertNull(defaultChannel.receive(0));
    assertNull(runtimeExceptionChannel.receive(0));
    assertNull(messageHandlingExceptionChannel.receive(0));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) ErrorMessage(org.springframework.messaging.support.ErrorMessage) MessageHandlingException(org.springframework.messaging.MessageHandlingException) Test(org.junit.Test)

Example 43 with ErrorMessage

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

the class ErrorMessageExceptionTypeRouterTests method fallbackToNextMostSpecificCause.

@Test
public void fallbackToNextMostSpecificCause() {
    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(RuntimeException.class.getName(), "runtimeExceptionChannel");
    router.setChannelMapping(MessageHandlingException.class.getName(), "runtimeExceptionChannel");
    router.setDefaultOutputChannel(defaultChannel);
    router.handleMessage(message);
    assertNotNull(runtimeExceptionChannel.receive(1000));
    assertNull(illegalArgumentChannel.receive(0));
    assertNull(defaultChannel.receive(0));
    assertNull(messageHandlingExceptionChannel.receive(0));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) ErrorMessage(org.springframework.messaging.support.ErrorMessage) MessageHandlingException(org.springframework.messaging.MessageHandlingException) Test(org.junit.Test)

Example 44 with ErrorMessage

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

the class ErrorMessageExceptionTypeRouterTests method fallbackToDefaultChannel.

@Test
public void fallbackToDefaultChannel() {
    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.setApplicationContext(TestUtils.createTestApplicationContext());
    router.setDefaultOutputChannel(defaultChannel);
    router.handleMessage(message);
    assertNotNull(defaultChannel.receive(1000));
    assertNull(runtimeExceptionChannel.receive(0));
    assertNull(illegalArgumentChannel.receive(0));
    assertNull(messageHandlingExceptionChannel.receive(0));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) ErrorMessage(org.springframework.messaging.support.ErrorMessage) MessageHandlingException(org.springframework.messaging.MessageHandlingException) Test(org.junit.Test)

Example 45 with ErrorMessage

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

the class ErrorMessageExceptionTypeRouterTests method testHierarchicalMapping.

@Test
public void testHierarchicalMapping() {
    IllegalArgumentException rootCause = new IllegalArgumentException("bad argument");
    MessageHandlingException error = new MessageRejectedException(new GenericMessage<Object>("foo"), "failed", rootCause);
    ErrorMessage message = new ErrorMessage(error);
    ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter();
    router.setBeanFactory(beanFactory);
    router.setApplicationContext(TestUtils.createTestApplicationContext());
    router.setChannelMapping(MessageHandlingException.class.getName(), "messageHandlingExceptionChannel");
    router.setDefaultOutputChannel(defaultChannel);
    router.handleMessage(message);
    assertNotNull(messageHandlingExceptionChannel.receive(1000));
    assertNull(defaultChannel.receive(0));
}
Also used : ErrorMessage(org.springframework.messaging.support.ErrorMessage) MessageRejectedException(org.springframework.integration.MessageRejectedException) MessageHandlingException(org.springframework.messaging.MessageHandlingException) Test(org.junit.Test)

Aggregations

ErrorMessage (org.springframework.messaging.support.ErrorMessage)59 Test (org.junit.Test)47 CountDownLatch (java.util.concurrent.CountDownLatch)17 GenericMessage (org.springframework.messaging.support.GenericMessage)17 MessagingException (org.springframework.messaging.MessagingException)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 Message (org.springframework.messaging.Message)12 QueueChannel (org.springframework.integration.channel.QueueChannel)11 MessageHandlingException (org.springframework.messaging.MessageHandlingException)11 Socket (java.net.Socket)9 ArrayList (java.util.ArrayList)7 LongRunningIntegrationTest (org.springframework.integration.test.support.LongRunningIntegrationTest)7 Semaphore (java.util.concurrent.Semaphore)6 Log (org.apache.commons.logging.Log)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)6 BeanFactory (org.springframework.beans.factory.BeanFactory)5 MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 ServerSocket (java.net.ServerSocket)3