Spring Integration

org.springframework.integration.transformer
Class ContentEnricher

java.lang.Object
  extended by org.springframework.integration.context.IntegrationObjectSupport
      extended by org.springframework.integration.handler.AbstractMessageHandler
          extended by org.springframework.integration.handler.AbstractReplyProducingMessageHandler
              extended by org.springframework.integration.transformer.ContentEnricher
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.Lifecycle, org.springframework.core.Ordered, NamedComponent, Orderable, MessageHandler, MessageProducer, TrackableComponent

public class ContentEnricher
extends AbstractReplyProducingMessageHandler
implements org.springframework.context.Lifecycle

Content Enricher is a Message Transformer that can augment a message's payload with either static values or by optionally invoking a downstream message flow via its request channel and then applying values from the reply Message to the original payload.

Since:
2.1
Author:
Mark Fisher, Gunnar Hillert, Gary Russell

Nested Class Summary
 
Nested classes/interfaces inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
AbstractReplyProducingMessageHandler.RequestHandler
 
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
ContentEnricher()
           
 
Method Summary
protected  java.lang.Object handleRequestMessage(Message<?> requestMessage)
          Subclasses must implement this method to handle the request Message.
 boolean isRunning()
          Lifecycle implementation.
 void onInit()
          Initializes the Content Enricher.
 void setPropertyExpressions(java.util.Map<java.lang.String,org.springframework.expression.Expression> propertyExpressions)
          Provide the map of expressions to evaluate when enriching the target payload.
 void setReplyChannel(MessageChannel replyChannel)
          Sets the content enricher's reply channel.
 void setReplyTimeout(java.lang.Long replyTimeout)
          Set the timeout value for receiving reply messages.
 void setRequestChannel(MessageChannel requestChannel)
          Sets the content enricher's request channel.
 void setRequestPayloadExpression(org.springframework.expression.Expression requestPayloadExpression)
          By default the original message's payload will be used as the actual payload that will be send to the request-channel.
 void setRequestTimeout(java.lang.Long requestTimeout)
          Set the timeout value for sending request messages.
 void setShouldClonePayload(boolean shouldClonePayload)
          Specify whether to clone payload objects to create the target object.
 void start()
          Lifecycle implementation.
 void stop()
          Lifecycle implementation.
 
Methods inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
getMessagingTemplate, handleMessageInternal, setAdviceChain, setBeanClassLoader, setChannelResolver, setOutputChannel, setRequiresReply, setSendTimeout, shouldCopyRequestHeaders
 
Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler
getComponentType, getOrder, handleMessage, setOrder, setShouldTrack
 
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, getBeanFactory, getComponentName, getConversionService, getTaskScheduler, setBeanFactory, setBeanName, setComponentName, setConversionService, setTaskScheduler, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.integration.context.NamedComponent
getComponentName
 

Constructor Detail

ContentEnricher

public ContentEnricher()
Method Detail

setPropertyExpressions

public void setPropertyExpressions(java.util.Map<java.lang.String,org.springframework.expression.Expression> propertyExpressions)
Provide the map of expressions to evaluate when enriching the target payload. The keys should simply be property names, and the values should be Expressions that will evaluate against the reply Message as the root object.


setRequestChannel

public void setRequestChannel(MessageChannel requestChannel)
Sets the content enricher's request channel. If specified, then an internal Gateway will be initialized. Setting a request channel is optional. Not setting a request channel is useful in situations where message payloads shall be enriched with static values only.


setReplyChannel

public void setReplyChannel(MessageChannel replyChannel)
Sets the content enricher's reply channel. If not specified, yet the request channel is set, an anonymous reply channel will automatically created for each request.


setRequestTimeout

public void setRequestTimeout(java.lang.Long requestTimeout)
Set the timeout value for sending request messages. If not explicitly configured, the default is one second.

Parameters:
requestTimeout - the timeout value in milliseconds. Must not be null.

setReplyTimeout

public void setReplyTimeout(java.lang.Long replyTimeout)
Set the timeout value for receiving reply messages. If not explicitly configured, the default is one second.

Parameters:
replyTimeout - the timeout value in milliseconds. Must not be null.

setRequestPayloadExpression

public void setRequestPayloadExpression(org.springframework.expression.Expression requestPayloadExpression)
By default the original message's payload will be used as the actual payload that will be send to the request-channel. By providing a SpEL expression as value for this setter, a subset of the original payload, a header value or any other resolvable SpEL expression can be used as the basis for the payload, that will be send to the request-channel. For the Expression evaluation the full message is available as the root object. For instance the following SpEL expressions (among others) are possible: If more sophisticated logic is required (e.g. changing the message headers etc.) please use additional downstream transformers.


setShouldClonePayload

public void setShouldClonePayload(boolean shouldClonePayload)
Specify whether to clone payload objects to create the target object. This is only applicable for payload types that implement Cloneable.


onInit

public void onInit()
Initializes the Content Enricher. Will instantiate an internal Gateway if the requestChannel is set.

Overrides:
onInit in class AbstractReplyProducingMessageHandler

handleRequestMessage

protected java.lang.Object handleRequestMessage(Message<?> requestMessage)
Description copied from class: AbstractReplyProducingMessageHandler
Subclasses must implement this method to handle the request Message. The return value may be a Message, a MessageBuilder, or any plain Object. The base class will handle the final creation of a reply Message from any of those starting points. If the return value is null, the Message flow will end here.

Specified by:
handleRequestMessage in class AbstractReplyProducingMessageHandler

start

public void start()
Lifecycle implementation. If no requestChannel is defined, this method has no effect as in that case no Gateway is initialized.

Specified by:
start in interface org.springframework.context.Lifecycle

stop

public void stop()
Lifecycle implementation. If no requestChannel is defined, this method has no effect as in that case no Gateway is initialized.

Specified by:
stop in interface org.springframework.context.Lifecycle

isRunning

public boolean isRunning()
Lifecycle implementation. If no requestChannel is defined, this method will return always return true as no Gateway is initialized.

Specified by:
isRunning in interface org.springframework.context.Lifecycle

Spring Integration