INT-4260: MessagePublishingErrorHandler Orig. Msg

JIRA: https://jira.spring.io/browse/INT-4260

MPEH: Populate the `ErrorMessage.originalMessage`,
if available and not the same as the `failedMessage`.

Polishing - rename exception to `MessagingExceptionWrapper`;
 make `MPEH` a subclass of `ErrorMessagePublisher`

PR Comments

Polishing - PR Comments
This commit is contained in:
Gary Russell
2017-04-20 13:45:21 -04:00
committed by Artem Bilan
parent 18f9fcbb59
commit 572467b1c4
17 changed files with 172 additions and 91 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2016 the original author or authors.
* Copyright 2013-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package org.springframework.integration.channel.registry;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.instanceOf;
@@ -48,6 +49,7 @@ import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.support.MessagingExceptionWrapper;
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
import org.springframework.integration.support.channel.HeaderChannelRegistry;
import org.springframework.integration.test.util.TestUtils;
@@ -177,6 +179,8 @@ public class HeaderChannelRegistryTests {
Message<?> reply = template.sendAndReceive(new GenericMessage<String>("bar"));
assertNotNull(reply);
assertTrue(reply instanceof ErrorMessage);
assertNotNull(((ErrorMessage) reply).getOriginalMessage());
assertThat(reply.getPayload(), not(instanceOf(MessagingExceptionWrapper.class)));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -71,10 +71,12 @@ public class DefaultConfiguringBeanFactoryPostProcessorTests {
assertEquals(ThreadPoolTaskScheduler.class, taskScheduler.getClass());
ErrorHandler errorHandler = TestUtils.getPropertyValue(taskScheduler, "errorHandler", ErrorHandler.class);
assertEquals(MessagePublishingErrorHandler.class, errorHandler.getClass());
MessageChannel defaultErrorChannel = TestUtils.getPropertyValue(errorHandler, "defaultErrorChannel", MessageChannel.class);
MessageChannel defaultErrorChannel = TestUtils.getPropertyValue(errorHandler,
"messagingTemplate.defaultDestination", MessageChannel.class);
assertNull(defaultErrorChannel);
errorHandler.handleError(new Throwable());
defaultErrorChannel = TestUtils.getPropertyValue(errorHandler, "defaultErrorChannel", MessageChannel.class);
defaultErrorChannel = TestUtils.getPropertyValue(errorHandler, "messagingTemplate.defaultDestination",
MessageChannel.class);
assertNotNull(defaultErrorChannel);
assertEquals(context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME), defaultErrorChannel);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@ import org.mockito.Mockito;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.integration.MessageRejectedException;
import org.springframework.integration.support.MessagingExceptionWrapper;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.PollableChannel;
@@ -243,6 +244,9 @@ public class PollingConsumerEndpointTests {
}
public void throwLastErrorIfAvailable() throws Throwable {
if (this.lastError instanceof MessagingExceptionWrapper) {
this.lastError = this.lastError.getCause();
}
Throwable t = this.lastError;
this.lastError = null;
throw t;