EndpointInterceptor postHandle now accepts the replyMessage only. InterceptingMessageHandler has been renamed MessageHandlerDecorator. Either the decorator or the interceptor's aroundHandle method may be removed since they are redundant.
This commit is contained in:
@@ -229,7 +229,7 @@ public abstract class AbstractEndpoint implements MessageEndpoint, ChannelRegist
|
||||
Message<?> reply = this.handleMessage(message);
|
||||
for (int i = index - 1; i >= 0; i--) {
|
||||
EndpointInterceptor interceptor = this.interceptors.get(i);
|
||||
reply = interceptor.postHandle(message, reply);
|
||||
reply = interceptor.postHandle(reply);
|
||||
}
|
||||
if (reply != null) {
|
||||
this.getMessageExchangeTemplate().send(message, this.target);
|
||||
|
||||
@@ -26,8 +26,8 @@ public interface EndpointInterceptor {
|
||||
|
||||
Message<?> preHandle(Message<?> requestMessage);
|
||||
|
||||
Message<?> aroundHandle(Message<?> message, MessageHandler handler);
|
||||
Message<?> aroundHandle(Message<?> requestMessage, MessageHandler handler);
|
||||
|
||||
Message<?> postHandle(Message<?> requestMessage, Message<?> replyMessage);
|
||||
Message<?> postHandle(Message<?> replyMessage);
|
||||
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ public class SimpleEndpoint<T extends MessageHandler> implements MessageEndpoint
|
||||
Message<?> replyMessage = this.handler.handle(requestMessage);
|
||||
for (int i = index - 1; i >= 0; i--) {
|
||||
EndpointInterceptor interceptor = this.interceptors.get(i);
|
||||
replyMessage = interceptor.postHandle(requestMessage, replyMessage);
|
||||
replyMessage = interceptor.postHandle(replyMessage);
|
||||
}
|
||||
return replyMessage;
|
||||
}
|
||||
|
||||
@@ -31,11 +31,11 @@ public class EndpointInterceptorAdapter implements EndpointInterceptor {
|
||||
return requestMessage;
|
||||
}
|
||||
|
||||
public Message<?> aroundHandle(Message<?> message, MessageHandler handler) {
|
||||
return handler.handle(message);
|
||||
public Message<?> aroundHandle(Message<?> requestMessage, MessageHandler handler) {
|
||||
return handler.handle(requestMessage);
|
||||
}
|
||||
|
||||
public Message<?> postHandle(Message<?> requestMessage, Message<?> replyMessage) {
|
||||
public Message<?> postHandle(Message<?> replyMessage) {
|
||||
return replyMessage;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.integration.handler;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -24,18 +25,31 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public abstract class InterceptingMessageHandler implements MessageHandler {
|
||||
public abstract class MessageHandlerDecorator implements MessageHandler {
|
||||
|
||||
private MessageHandler target;
|
||||
private MessageHandler handler;
|
||||
|
||||
|
||||
public InterceptingMessageHandler(MessageHandler target) {
|
||||
Assert.notNull(target, "target must not be null");
|
||||
this.target = target;
|
||||
public MessageHandlerDecorator(MessageHandler handler) {
|
||||
Assert.notNull(handler, "handler must not be null");
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public MessageHandlerDecorator() {
|
||||
}
|
||||
|
||||
|
||||
public void setHandler(MessageHandler handler) {
|
||||
Assert.notNull(handler, "handler must not be null");
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public final Message<?> handle(Message<?> message) {
|
||||
return handle(message, this.target);
|
||||
if (this.handler == null) {
|
||||
throw new MessageHandlingException(message,
|
||||
"MessageHandlerDecorator's handler must not be null");
|
||||
}
|
||||
return this.handleInternal(message, this.handler);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,9 +57,9 @@ public abstract class InterceptingMessageHandler implements MessageHandler {
|
||||
* The handler method for subclasses to implement.
|
||||
*
|
||||
* @param message the message to handle
|
||||
* @param target the intercepted handler
|
||||
* @param handler the intercepted handler
|
||||
* @return a reply message or null
|
||||
*/
|
||||
public abstract Message<?> handle(Message<?> message, MessageHandler target);
|
||||
public abstract Message<?> handleInternal(Message<?> message, MessageHandler handler);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user