INT-1110 Add Message to MessageMappingException in outbound tcp adapter. Add code to the dispatchers to do the same if a handler does not.

This commit is contained in:
Gary Russell
2010-05-01 00:35:37 +00:00
parent 6aea96e2b2
commit efa7d7fd88
6 changed files with 106 additions and 4 deletions

View File

@@ -20,11 +20,12 @@ package org.springframework.integration.core;
* The base exception for any failures within the messaging system.
*
* @author Mark Fisher
* @author Gary Russell
*/
@SuppressWarnings("serial")
public class MessagingException extends RuntimeException {
private final Message<?> failedMessage;
private Message<?> failedMessage;
public MessagingException(Message<?> message) {
@@ -57,9 +58,12 @@ public class MessagingException extends RuntimeException {
this.failedMessage = message;
}
public Message<?> getFailedMessage() {
return this.failedMessage;
}
public void setFailedMessage(Message<?> message) {
this.failedMessage = message;
}
}

View File

@@ -22,6 +22,7 @@ import java.util.concurrent.Executor;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessageHeaders;
import org.springframework.integration.core.MessagingException;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.integration.message.MessageHandler;
@@ -41,6 +42,7 @@ import org.springframework.integration.message.MessageHandler;
*
* @author Mark Fisher
* @author Iwein Fuld
* @author Gary Russell
*/
public class BroadcastingDispatcher extends AbstractDispatcher {
@@ -121,6 +123,10 @@ public class BroadcastingDispatcher extends AbstractDispatcher {
}
catch (RuntimeException e) {
if (!this.ignoreFailures) {
if (e instanceof MessagingException &&
((MessagingException) e).getFailedMessage() == null) {
((MessagingException) e).setFailedMessage(message);
}
throw e;
}
else if (this.logger.isWarnEnabled()) {

View File

@@ -21,6 +21,7 @@ import java.util.List;
import java.util.concurrent.Executor;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessagingException;
import org.springframework.integration.message.MessageDeliveryException;
import org.springframework.integration.message.MessageHandler;
import org.springframework.util.Assert;
@@ -41,6 +42,7 @@ import org.springframework.util.Assert;
*
* @author Iwein Fuld
* @author Mark Fisher
* @author Gary Russell
* @since 1.0.2
*/
public class UnicastingDispatcher extends AbstractDispatcher {
@@ -108,6 +110,10 @@ public class UnicastingDispatcher extends AbstractDispatcher {
? (RuntimeException) e
: new MessageDeliveryException(message,
"Dispatcher failed to deliver Message.", e);
if (e instanceof MessagingException &&
((MessagingException) e).getFailedMessage() == null) {
((MessagingException) e).setFailedMessage(message);
}
exceptions.add(runtimeException);
this.handleExceptions(exceptions, message, !handlerIterator.hasNext());
}