Class ContentEnricher

All Implemented Interfaces:
org.reactivestreams.Subscriber<Message<?>>, Aware, BeanClassLoaderAware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, Lifecycle, Ordered, ComponentSourceAware, ExpressionCapable, Orderable, MessageProducer, HeaderPropagationAware, IntegrationPattern, NamedComponent, IntegrationManagement, ManageableLifecycle, TrackableComponent, MessageHandler, reactor.core.CoreSubscriber<Message<?>>

public class ContentEnricher extends AbstractReplyProducingMessageHandler implements ManageableLifecycle
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, Artem Bilan, Liujiong, Kris Jacyna
  • Constructor Details

    • ContentEnricher

      public ContentEnricher()
  • Method Details

    • setNullResultPropertyExpressions

      public void setNullResultPropertyExpressions(Map<String,Expression> nullResultPropertyExpressions)
    • setNullResultHeaderExpressions

      public void setNullResultHeaderExpressions(Map<String,HeaderValueMessageProcessor<?>> nullResultHeaderExpressions)
    • setPropertyExpressions

      public void setPropertyExpressions(Map<String,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.
      Parameters:
      propertyExpressions - The property expressions.
    • setHeaderExpressions

      public void setHeaderExpressions(Map<String,HeaderValueMessageProcessor<?>> headerExpressions)
      Provide the map of HeaderValueMessageProcessor to evaluate when enriching the target MessageHeaders. The keys should simply be header names, and the values should be Expressions that will evaluate against the reply Message as the root object.
      Parameters:
      headerExpressions - The header expressions.
    • setRequestChannel

      public void setRequestChannel(MessageChannel requestChannel)
      Set the content enricher 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.
      Parameters:
      requestChannel - The request channel.
    • setRequestChannelName

      public void setRequestChannelName(String requestChannelName)
    • setReplyChannel

      public void setReplyChannel(MessageChannel replyChannel)
      Set the content enricher reply channel. If not specified, yet the request channel is set, an anonymous reply channel will automatically created for each request.
      Parameters:
      replyChannel - The reply channel.
    • setReplyChannelName

      public void setReplyChannelName(String replyChannelName)
    • setErrorChannel

      public void setErrorChannel(MessageChannel errorChannel)
      Set the content enricher error channel to allow the error handling flow to return of an alternative object to use for enrichment if exceptions occur in the downstream flow.
      Parameters:
      errorChannel - The error channel.
      Since:
      4.1
    • setErrorChannelName

      public void setErrorChannelName(String errorChannelName)
    • setRequestTimeout

      public void setRequestTimeout(Long requestTimeout)
      Set the timeout value for sending request messages. If not explicitly configured, the default is 30 seconds.
      Parameters:
      requestTimeout - the timeout value in milliseconds. Must not be null.
    • setReplyTimeout

      public void setReplyTimeout(Long replyTimeout)
      Set the timeout value for receiving reply messages. If not explicitly configured, the default is 30 seconds.
      Parameters:
      replyTimeout - the timeout value in milliseconds. Must not be null.
    • setRequestPayloadExpression

      public void setRequestPayloadExpression(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:

      • payload.foo
      • headers.foobar
      • new java.util.Date()
      • 'foo' + 'bar'

      If more sophisticated logic is required (e.g. changing the message headers etc.) please use additional downstream transformers.

      Parameters:
      requestPayloadExpression - The request payload expression.
    • 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.
      Parameters:
      shouldClonePayload - true if the payload should be cloned.
    • setIntegrationEvaluationContext

      public void setIntegrationEvaluationContext(EvaluationContext evaluationContext)
    • getComponentType

      public String getComponentType()
      Description copied from class: IntegrationObjectSupport
      Subclasses may implement this method to provide component type information.
      Specified by:
      getComponentType in interface NamedComponent
      Overrides:
      getComponentType in class MessageHandlerSupport
    • getIntegrationPatternType

      public IntegrationPatternType getIntegrationPatternType()
      Description copied from interface: IntegrationPattern
      Return a pattern type this component implements.
      Specified by:
      getIntegrationPatternType in interface IntegrationPattern
      Overrides:
      getIntegrationPatternType in class AbstractReplyProducingMessageHandler
      Returns:
      the IntegrationPatternType this component implements.
    • doInit

      protected void doInit()
      Initialize the Content Enricher. Will instantiate an internal Gateway if the requestChannel is set.
      Overrides:
      doInit in class AbstractReplyProducingMessageHandler
    • handleRequestMessage

      protected 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
      Parameters:
      requestMessage - The request message.
      Returns:
      The result of handling the message, or null.
    • 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 Lifecycle
      Specified by:
      start in interface ManageableLifecycle
    • 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 Lifecycle
      Specified by:
      stop in interface ManageableLifecycle
    • 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 Lifecycle
      Specified by:
      isRunning in interface ManageableLifecycle