Modified the 'onFailure' method signature in MessageDeliveryAware so that any Exception can be passed along with a separate Message parameter instead of always expecting a MessagingException.

This commit is contained in:
Mark Fisher
2008-08-18 18:40:39 +00:00
parent 80935d3bd0
commit 30fd7decc8
6 changed files with 39 additions and 29 deletions

View File

@@ -116,7 +116,7 @@ public abstract class AbstractEndpoint implements MessageEndpoint, BeanNameAware
}
else {
this.handleException(new MessageHandlingException(message,
"failure occurred in endpoint's send operation", e));
"failure occurred in endpoint '" + this.toString() + "'", e));
}
return false;
}

View File

@@ -41,12 +41,11 @@ public class InboundChannelAdapter extends AbstractEndpoint {
return sent;
}
catch (Exception e) {
MessagingException exception = (e instanceof MessagingException) ? (MessagingException) e
: new MessageDeliveryException(message, "channel-adapter failed to send message to target");
if (this.getSource() instanceof MessageDeliveryAware) {
((MessageDeliveryAware) this.getSource()).onFailure(exception);
((MessageDeliveryAware) this.getSource()).onFailure(message, e);
}
return false;
throw (e instanceof MessagingException) ? (MessagingException) e
: new MessageDeliveryException(message, "channel adapter failed to send message to target", e);
}
}

View File

@@ -32,6 +32,6 @@ public interface MessageDeliveryAware {
/**
* Callback method invoked after a message delivery failure.
*/
void onFailure(MessagingException exception);
void onFailure(Message<?> failedMessage, Throwable t);
}

View File

@@ -226,8 +226,9 @@ public class MessageExchangeTemplate implements InitializingBean {
}
private boolean doReceiveAndForward(PollableSource<?> source, MessageTarget target) {
Message<?> message = null;
try {
Message<?> message = this.doReceive(source);
message = this.doReceive(source);
if (message == null) {
return false;
}
@@ -237,18 +238,23 @@ public class MessageExchangeTemplate implements InitializingBean {
((MessageDeliveryAware) source).onSend(message);
}
else {
((MessageDeliveryAware) source).onFailure(new MessageDeliveryException(message, "failed to send message"));
((MessageDeliveryAware) source).onFailure(message, new MessageDeliveryException(message, "failed to send message"));
}
}
return sent;
}
catch (Exception e) {
MessagingException exception = (e instanceof MessagingException) ? (MessagingException) e
: new MessagingException("exception occurred in receive-and-forward exchange", e);
if (source instanceof MessageDeliveryAware) {
((MessageDeliveryAware) source).onFailure(exception);
((MessageDeliveryAware) source).onFailure(message, e);
}
throw exception;
if (e instanceof MessagingException) {
throw (MessagingException) e;
}
String description = "exception occurred in receive-and-forward exchange";
if (message != null) {
throw new MessagingException(message, description, e);
}
throw new MessagingException(description, e);
}
}