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:
@@ -52,23 +52,23 @@ public class EndpointInterceptorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void testInterceptors(MessageEndpoint endpoint, ClassPathXmlApplicationContext context, boolean innerBeans) {
|
||||
TestPreSendInterceptor preInterceptor = null;
|
||||
TestAroundSendEndpointInterceptor aroundInterceptor = null;
|
||||
TestPreHandleInterceptor preInterceptor = null;
|
||||
TestPostHandleInterceptor postInterceptor = null;
|
||||
if (innerBeans) {
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(endpoint);
|
||||
List<EndpointInterceptor> interceptors = (List<EndpointInterceptor>) accessor.getPropertyValue("interceptors");
|
||||
preInterceptor = (TestPreSendInterceptor) interceptors.get(0);
|
||||
aroundInterceptor = (TestAroundSendEndpointInterceptor) interceptors.get(1);
|
||||
preInterceptor = (TestPreHandleInterceptor) interceptors.get(0);
|
||||
postInterceptor = (TestPostHandleInterceptor) interceptors.get(1);
|
||||
}
|
||||
else {
|
||||
preInterceptor = (TestPreSendInterceptor) context.getBean("preInterceptor");
|
||||
aroundInterceptor = (TestAroundSendEndpointInterceptor) context.getBean("aroundInterceptor");
|
||||
preInterceptor = (TestPreHandleInterceptor) context.getBean("preInterceptor");
|
||||
postInterceptor = (TestPostHandleInterceptor) context.getBean("postInterceptor");
|
||||
}
|
||||
assertEquals(0, preInterceptor.getCount());
|
||||
assertEquals(0, aroundInterceptor.getCount());
|
||||
assertEquals(0, postInterceptor.getCount());
|
||||
endpoint.send(new StringMessage("test"));
|
||||
assertEquals(1, preInterceptor.getCount());
|
||||
assertEquals(2, aroundInterceptor.getCount());
|
||||
assertEquals(1, postInterceptor.getCount());
|
||||
context.stop();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,13 +19,12 @@ package org.springframework.integration.config;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.springframework.integration.endpoint.interceptor.EndpointInterceptorAdapter;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class TestAroundSendEndpointInterceptor extends EndpointInterceptorAdapter {
|
||||
public class TestPostHandleInterceptor extends EndpointInterceptorAdapter {
|
||||
|
||||
private AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
@@ -35,11 +34,9 @@ public class TestAroundSendEndpointInterceptor extends EndpointInterceptorAdapte
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message<?> aroundHandle(Message<?> message, MessageHandler handler) {
|
||||
public Message<?> postHandle(Message<?> replyMessage) {
|
||||
this.counter.incrementAndGet();
|
||||
Message<?> reply = handler.handle(message);
|
||||
this.counter.incrementAndGet();
|
||||
return reply;
|
||||
return replyMessage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import org.springframework.integration.message.Message;
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class TestPreSendInterceptor extends EndpointInterceptorAdapter {
|
||||
public class TestPreHandleInterceptor extends EndpointInterceptorAdapter {
|
||||
|
||||
private AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
output-channel="replyChannel">
|
||||
<poller period="100"/>
|
||||
<interceptors>
|
||||
<beans:bean class="org.springframework.integration.config.TestPreSendInterceptor"/>
|
||||
<beans:bean class="org.springframework.integration.config.TestAroundSendEndpointInterceptor"/>
|
||||
<beans:bean class="org.springframework.integration.config.TestPreHandleInterceptor"/>
|
||||
<beans:bean class="org.springframework.integration.config.TestPostHandleInterceptor"/>
|
||||
</interceptors>
|
||||
</service-activator>
|
||||
|
||||
@@ -31,15 +31,15 @@
|
||||
<poller period="100"/>
|
||||
<interceptors>
|
||||
<ref bean="preInterceptor"/>
|
||||
<ref bean="aroundInterceptor"/>
|
||||
<ref bean="postInterceptor"/>
|
||||
</interceptors>
|
||||
</service-activator>
|
||||
|
||||
|
||||
<beans:bean id="testHandler" class="org.springframework.integration.config.TestHandler"/>
|
||||
|
||||
<beans:bean id="preInterceptor" class="org.springframework.integration.config.TestPreSendInterceptor"/>
|
||||
<beans:bean id="preInterceptor" class="org.springframework.integration.config.TestPreHandleInterceptor"/>
|
||||
|
||||
<beans:bean id="aroundInterceptor" class="org.springframework.integration.config.TestAroundSendEndpointInterceptor"/>
|
||||
<beans:bean id="postInterceptor" class="org.springframework.integration.config.TestPostHandleInterceptor"/>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -40,11 +40,11 @@ public class MessageHandlerChainTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChainWithInterceptors() {
|
||||
public void testChainWithDecorators() {
|
||||
MessageHandler handler1 = new TestHandler("*");
|
||||
MessageHandler handler2 = new TestInterceptingHandler("2", handler1);
|
||||
MessageHandler handler3 = new TestInterceptingHandler("3", handler2);
|
||||
MessageHandler handler4 = new TestInterceptingHandler("4", handler3);
|
||||
MessageHandler handler2 = new TestHandlerDecorator("2", handler1);
|
||||
MessageHandler handler3 = new TestHandlerDecorator("3", handler2);
|
||||
MessageHandler handler4 = new TestHandlerDecorator("4", handler3);
|
||||
MessageHandlerChain chain = new MessageHandlerChain();
|
||||
chain.add(new TestHandler("a"));
|
||||
chain.add(handler4);
|
||||
@@ -68,17 +68,18 @@ public class MessageHandlerChainTests {
|
||||
}
|
||||
|
||||
|
||||
private static class TestInterceptingHandler extends InterceptingMessageHandler {
|
||||
private static class TestHandlerDecorator extends MessageHandlerDecorator {
|
||||
|
||||
private String text;
|
||||
|
||||
TestInterceptingHandler(String text, MessageHandler target) {
|
||||
super(target);
|
||||
TestHandlerDecorator(String text, MessageHandler handler) {
|
||||
super(handler);
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public Message<?> handle(Message<?> message, MessageHandler target) {
|
||||
message = target.handle(new StringMessage(text + message.getPayload()));
|
||||
@Override
|
||||
public Message<?> handleInternal(Message<?> message, MessageHandler handler) {
|
||||
message = handler.handle(new StringMessage(text + message.getPayload()));
|
||||
return new StringMessage(message.getPayload() + text);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user