Class ContentEnricher
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.MessageHandlerSupport
org.springframework.integration.handler.AbstractMessageHandler
org.springframework.integration.handler.AbstractMessageProducingHandler
org.springframework.integration.handler.AbstractReplyProducingMessageHandler
org.springframework.integration.transformer.ContentEnricher
- All Implemented Interfaces:
org.reactivestreams.Subscriber<Message<?>>
,Aware
,BeanClassLoaderAware
,BeanFactoryAware
,BeanNameAware
,DisposableBean
,InitializingBean
,ApplicationContextAware
,Lifecycle
,Ordered
,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
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
AbstractReplyProducingMessageHandler.RequestHandler
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides
-
Field Summary
Fields inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler
messagingTemplate
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
doInit()
Initialize the Content Enricher.Subclasses may implement this method to provide component type information.Return a pattern type this component implements.protected Object
handleRequestMessage
(Message<?> requestMessage) Subclasses must implement this method to handle the request Message.boolean
Lifecycle implementation.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.void
setErrorChannelName
(String errorChannelName) void
setHeaderExpressions
(Map<String, HeaderValueMessageProcessor<?>> headerExpressions) Provide the map ofHeaderValueMessageProcessor
to evaluate when enriching the target MessageHeaders.void
setIntegrationEvaluationContext
(EvaluationContext evaluationContext) void
setNullResultHeaderExpressions
(Map<String, HeaderValueMessageProcessor<?>> nullResultHeaderExpressions) void
setNullResultPropertyExpressions
(Map<String, Expression> nullResultPropertyExpressions) void
setPropertyExpressions
(Map<String, Expression> propertyExpressions) Provide the map of expressions to evaluate when enriching the target payload.void
setReplyChannel
(MessageChannel replyChannel) Set the content enricher reply channel.void
setReplyChannelName
(String replyChannelName) void
setReplyTimeout
(Long replyTimeout) Set the timeout value for receiving reply messages.void
setRequestChannel
(MessageChannel requestChannel) Set the content enricher request channel.void
setRequestChannelName
(String requestChannelName) 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.void
setRequestTimeout
(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
doInvokeAdvisedRequestHandler, getBeanClassLoader, getRequiresReply, handleMessageInternal, hasAdviceChain, onInit, setAdviceChain, setBeanClassLoader, setRequiresReply
Methods inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler
addNotPropagatedHeaders, createOutputMessage, getNotPropagatedHeaders, getOutputChannel, isAsync, messageBuilderForReply, produceOutput, resolveErrorChannel, sendErrorMessage, sendOutput, sendOutputs, setAsync, setNotPropagatedHeaders, setOutputChannel, setOutputChannelName, setSendTimeout, setupMessageProcessor, shouldCopyRequestHeaders, shouldSplitOutput, updateNotPropagatedHeaders
Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribe, setObservationConvention
Methods inherited from class org.springframework.integration.handler.MessageHandlerSupport
buildSendTimer, destroy, getManagedName, getManagedType, getMetricsCaptor, getObservationRegistry, getOrder, getOverrides, isLoggingEnabled, isObserved, registerMetricsCaptor, registerObservationRegistry, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrack
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface reactor.core.CoreSubscriber
currentContext
Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAs
Methods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Constructor Details
-
ContentEnricher
public ContentEnricher()
-
-
Method Details
-
setNullResultPropertyExpressions
-
setNullResultHeaderExpressions
public void setNullResultHeaderExpressions(Map<String, HeaderValueMessageProcessor<?>> nullResultHeaderExpressions) -
setPropertyExpressions
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
Provide the map ofHeaderValueMessageProcessor
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
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
-
setReplyChannel
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
-
setErrorChannel
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
-
setRequestTimeout
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
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
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
-
getComponentType
Description copied from class:IntegrationObjectSupport
Subclasses may implement this method to provide component type information.- Specified by:
getComponentType
in interfaceNamedComponent
- Overrides:
getComponentType
in classMessageHandlerSupport
-
getIntegrationPatternType
Description copied from interface:IntegrationPattern
Return a pattern type this component implements.- Specified by:
getIntegrationPatternType
in interfaceIntegrationPattern
- Overrides:
getIntegrationPatternType
in classAbstractReplyProducingMessageHandler
- 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 classAbstractReplyProducingMessageHandler
-
handleRequestMessage
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 classAbstractReplyProducingMessageHandler
- 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 interfaceLifecycle
- Specified by:
start
in interfaceManageableLifecycle
-
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 interfaceLifecycle
- Specified by:
stop
in interfaceManageableLifecycle
-
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 interfaceLifecycle
- Specified by:
isRunning
in interfaceManageableLifecycle
-