Search in sources :

Example 6 with ErrorMessage

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

the class ErrorMessageExceptionTypeRouterTests method intermediateCauseHasNoMappingButMostSpecificCauseDoes.

@Test
public void intermediateCauseHasNoMappingButMostSpecificCauseDoes() {
    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(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 7 with ErrorMessage

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

the class PollingEndpointErrorHandlingTests method checkExceptionPlacedOnErrorChannel.

@SuppressWarnings("rawtypes")
@Test
public void checkExceptionPlacedOnErrorChannel() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("pollingEndpointErrorHandlingTests.xml", this.getClass());
    PollableChannel errorChannel = (PollableChannel) context.getBean("errorChannel");
    Message errorMessage = errorChannel.receive(5000);
    assertNotNull("No error message received", errorMessage);
    assertEquals("Message received was not an ErrorMessage", ErrorMessage.class, errorMessage.getClass());
    context.close();
}
Also used : Message(org.springframework.messaging.Message) ErrorMessage(org.springframework.messaging.support.ErrorMessage) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 8 with ErrorMessage

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

the class MessageHistoryTests method testCorrectErrorMessageAfterWrite.

@Test
public void testCorrectErrorMessageAfterWrite() {
    RuntimeException payload = new RuntimeException();
    ErrorMessage original = new ErrorMessage(payload);
    assertNull(MessageHistory.read(original));
    Message<Throwable> result1 = MessageHistory.write(original, new TestComponent(1));
    assertThat(result1, instanceOf(ErrorMessage.class));
    assertNotSame(original, result1);
    assertSame(original.getPayload(), result1.getPayload());
    MessageHistory history1 = MessageHistory.read(result1);
    assertNotNull(history1);
    assertEquals("testComponent-1", history1.toString());
    Message<Throwable> result2 = MessageHistory.write(result1, new TestComponent(2));
    assertThat(result2, instanceOf(ErrorMessage.class));
    assertNotSame(original, result2);
    assertNotSame(result1, result2);
    assertSame(original.getPayload(), result2.getPayload());
    MessageHistory history2 = MessageHistory.read(result2);
    assertNotNull(history2);
    assertEquals("testComponent-1,testComponent-2", history2.toString());
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) ErrorMessage(org.springframework.messaging.support.ErrorMessage) Test(org.junit.Test)

Example 9 with ErrorMessage

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

the class RouterTests method testExceptionTypeRouteFlow.

@Test
public void testExceptionTypeRouteFlow() {
    Message<?> failedMessage = new GenericMessage<>("foo");
    IllegalArgumentException rootCause = new IllegalArgumentException("bad argument");
    RuntimeException middleCause = new RuntimeException(rootCause);
    MessageHandlingException error = new MessageHandlingException(failedMessage, "failed", middleCause);
    ErrorMessage message = new ErrorMessage(error);
    this.exceptionTypeRouteFlowInput.send(message);
    assertNotNull(this.illegalArgumentChannel.receive(1000));
    assertNull(this.exceptionRouterDefaultChannel.receive(0));
    assertNull(this.runtimeExceptionChannel.receive(0));
    assertNull(this.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 10 with ErrorMessage

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

the class ErrorMessageExceptionTypeRouterParserTests method validateExceptionTypeRouterConfig.

@Test
public void validateExceptionTypeRouterConfig() {
    inputChannel.send(new ErrorMessage(new NullPointerException()));
    assertTrue(npeChannel.receive(1000).getPayload() instanceof NullPointerException);
    inputChannel.send(new ErrorMessage(new IllegalArgumentException()));
    assertTrue(illegalChannel.receive(1000).getPayload() instanceof IllegalArgumentException);
    inputChannel.send(new ErrorMessage(new RuntimeException()));
    assertTrue(defaultChannel.receive(1000).getPayload() instanceof RuntimeException);
}
Also used : ErrorMessage(org.springframework.messaging.support.ErrorMessage) 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