From 221221aae72225ed53be983ab8eb43deacd3c704 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Tue, 9 Mar 2010 20:17:33 +0000 Subject: [PATCH] INT-919, INT-975 MessageHandlerChain no longer uses PropertyAccessor to check for an "outputChannel" property. Instead, it expects the handlers to implement the new MessageProducer interface. The chain has also been simplified to use anonymous channels between handlers instead of requiring a DirectChannel and EventDrivenConsumer for each. --- .../handler/MessageHandlerChain.java | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/handler/MessageHandlerChain.java b/org.springframework.integration/src/main/java/org/springframework/integration/handler/MessageHandlerChain.java index 6c43fdafad..4c8b5be27c 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/handler/MessageHandlerChain.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/handler/MessageHandlerChain.java @@ -18,8 +18,6 @@ package org.springframework.integration.handler; import java.util.List; -import org.springframework.beans.BeanWrapperImpl; -import org.springframework.beans.PropertyAccessor; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.BeanNameAware; @@ -28,6 +26,7 @@ import org.springframework.integration.channel.BeanFactoryChannelResolver; import org.springframework.integration.channel.ChannelResolver; import org.springframework.integration.core.Message; import org.springframework.integration.core.MessageChannel; +import org.springframework.integration.core.MessageProducer; import org.springframework.integration.filter.MessageFilter; import org.springframework.integration.message.MessageHandler; import org.springframework.integration.message.MessageHandlingException; @@ -37,11 +36,10 @@ import org.springframework.util.Assert; * A composite {@link MessageHandler} implementation that invokes a chain of * MessageHandler instances in order. *

- * Each of the handlers has to implement - * public void setOutputChannel(MessageChannel outputChannel);. An - * exception is made for the last handler in the case that the chain itself does - * not have an output channel. No other assumptions about the type of handler - * are made. + * Each of the handlers except for the last one must implement the + * {@link MessageProducer} interface. The last handler must also if + * the chain itself has an output channel configured. No other assumptions + * are made about the type of handler. *

* It is expected that each handler will produce reply messages and send them to * its output channel, although this is not enforced. It is possible to filter @@ -65,9 +63,7 @@ import org.springframework.util.Assert; * @author Mark Fisher * @author Iwein Fuld */ -public class MessageHandlerChain implements MessageHandler, Ordered, BeanFactoryAware, BeanNameAware { - - private static final String OUTPUT_CHANNEL_PROPERTY = "outputChannel"; +public class MessageHandlerChain implements MessageHandler, MessageProducer, Ordered, BeanFactoryAware, BeanNameAware { private volatile List handlers; @@ -139,11 +135,9 @@ public class MessageHandlerChain implements MessageHandler, Ordered, BeanFactory for (int i = 0; i < handlers.size(); i++) { boolean last = (i == handlers.size() - 1); MessageHandler handler = handlers.get(i); - PropertyAccessor accessor = new BeanWrapperImpl(handler); if (!last) { - Assert.notNull(accessor.getPropertyType(OUTPUT_CHANNEL_PROPERTY), - "All handlers except for the last one in the chain must implement property '" - + OUTPUT_CHANNEL_PROPERTY + "' of type 'MessageChannel'"); + Assert.isTrue(handler instanceof MessageProducer, "All handlers except for " + + "the last one in the chain must implement the MessageProducer interface."); final MessageHandler nextHandler = handlers.get(i + 1); final MessageChannel nextChannel = new MessageChannel() { public boolean send(Message message, long timeout) { @@ -157,17 +151,17 @@ public class MessageHandlerChain implements MessageHandler, Ordered, BeanFactory return null; } }; - accessor.setPropertyValue(OUTPUT_CHANNEL_PROPERTY, nextChannel); + ((MessageProducer) handler).setOutputChannel(nextChannel); } - else if (accessor.getPropertyType(OUTPUT_CHANNEL_PROPERTY) != null) { + else if (handler instanceof MessageProducer) { MessageChannel replyChannel = (this.outputChannel != null) ? this.outputChannel : new ReplyForwardingMessageChannel(); - accessor.setPropertyValue(OUTPUT_CHANNEL_PROPERTY, replyChannel); + ((MessageProducer) handler).setOutputChannel(replyChannel); } else { Assert.isNull(this.outputChannel, - "An output channel was provided, but the final handler in the chain does not implement property '" - + OUTPUT_CHANNEL_PROPERTY + "' of type 'MessageChannel'"); + "An output channel was provided, but the final handler in " + + "the chain does not implement the MessageProducer interface."); } } }