org.springframework.integration.handler
Class MessageHandlerChain

java.lang.Object
  extended by org.springframework.integration.context.IntegrationObjectSupport
      extended by org.springframework.integration.handler.MessageHandlerChain
All Implemented Interfaces:
org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.core.Ordered, MessageHandler

public class MessageHandlerChain
extends IntegrationObjectSupport
implements MessageHandler, org.springframework.core.Ordered

A composite 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.

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 messages in the middle of the chain, for example using a MessageFilter. A MessageHandler returning null will have the same effect, although this option is less expressive.

This component can be used from the namespace to improve the readability of the configuration by removing channels that can be created implicitly.

 <chain>
     <filter ref="someFilter"/>
     <bean class="SomeMessageHandlerImplementation"/>
     <transformer ref="someTransformer"/>
     <aggregator ... />
 </chain>
 

Author:
Mark Fisher, Iwein Fuld

Field Summary
 
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
logger
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
MessageHandlerChain()
           
 
Method Summary
 void afterPropertiesSet()
           
 int getOrder()
           
 void handleMessage(Message<?> message)
          Handles the message if possible.
 void setHandlers(java.util.List<MessageHandler> handlers)
           
 void setOrder(int order)
           
 void setOutputChannel(MessageChannel outputChannel)
           
 
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
getBeanFactory, getBeanName, getChannelResolver, getTaskScheduler, setBeanFactory, setBeanName, setTaskScheduler, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MessageHandlerChain

public MessageHandlerChain()
Method Detail

setHandlers

public void setHandlers(java.util.List<MessageHandler> handlers)

setOutputChannel

public void setOutputChannel(MessageChannel outputChannel)

setOrder

public void setOrder(int order)

getOrder

public int getOrder()
Specified by:
getOrder in interface org.springframework.core.Ordered

afterPropertiesSet

public final void afterPropertiesSet()

handleMessage

public void handleMessage(Message<?> message)
Description copied from interface: MessageHandler
Handles the message if possible. If the handler cannot deal with the message this will result in a MessageRejectedException e.g. in case of a Selective Consumer. When a consumer tries to handle a message, but fails to do so, a MessageHandlingException is thrown. In the last case it is recommended to treat the message as tainted and go into an error scenario.

When the handling results in a message being sent failure to send that message will result in a MessageDeliveryException.

Specified by:
handleMessage in interface MessageHandler
Parameters:
message - the message to be handled