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.RequestHandlerNested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides -
Field Summary
Fields inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler
messagingTemplateFields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, loggerFields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoInit()Initialize the Content Enricher.Subclasses may implement this method to provide component type information.Return a pattern type this component implements.protected ObjecthandleRequestMessage(Message<?> requestMessage) Subclasses must implement this method to handle the request Message.booleanLifecycle implementation.voidsetErrorChannel(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.voidsetErrorChannelName(String errorChannelName) voidsetHeaderExpressions(Map<String, HeaderValueMessageProcessor<?>> headerExpressions) Provide the map ofHeaderValueMessageProcessorto evaluate when enriching the target MessageHeaders.voidsetIntegrationEvaluationContext(EvaluationContext evaluationContext) voidsetNullResultHeaderExpressions(Map<String, HeaderValueMessageProcessor<?>> nullResultHeaderExpressions) voidsetNullResultPropertyExpressions(Map<String, Expression> nullResultPropertyExpressions) voidsetPropertyExpressions(Map<String, Expression> propertyExpressions) Provide the map of expressions to evaluate when enriching the target payload.voidsetReplyChannel(MessageChannel replyChannel) Set the content enricher reply channel.voidsetReplyChannelName(String replyChannelName) voidsetReplyTimeout(Long replyTimeout) Set the timeout value for receiving reply messages.voidsetRequestChannel(MessageChannel requestChannel) Set the content enricher request channel.voidsetRequestChannelName(String requestChannelName) voidsetRequestPayloadExpression(Expression requestPayloadExpression) By default the original message's payload will be used as the actual payload that will be send to the request-channel.voidsetRequestTimeout(Long requestTimeout) Set the timeout value for sending request messages.voidsetShouldClonePayload(boolean shouldClonePayload) Specify whether to clone payload objects to create the target object.voidstart()Lifecycle implementation.voidstop()Lifecycle implementation.Methods inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
doInvokeAdvisedRequestHandler, getBeanClassLoader, getRequiresReply, handleMessageInternal, hasAdviceChain, onInit, setAdviceChain, setBeanClassLoader, setRequiresReplyMethods 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, updateNotPropagatedHeadersMethods inherited from class org.springframework.integration.handler.AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribe, setObservationConventionMethods 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, shouldTrackMethods 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, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface reactor.core.CoreSubscriber
currentContextMethods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAsMethods 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 ofHeaderValueMessageProcessorto 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:IntegrationObjectSupportSubclasses may implement this method to provide component type information.- Specified by:
getComponentTypein interfaceNamedComponent- Overrides:
getComponentTypein classMessageHandlerSupport
-
getIntegrationPatternType
Description copied from interface:IntegrationPatternReturn a pattern type this component implements.- Specified by:
getIntegrationPatternTypein interfaceIntegrationPattern- Overrides:
getIntegrationPatternTypein classAbstractReplyProducingMessageHandler- Returns:
- the
IntegrationPatternTypethis component implements.
-
doInit
protected void doInit()Initialize the Content Enricher. Will instantiate an internal Gateway if the requestChannel is set.- Overrides:
doInitin classAbstractReplyProducingMessageHandler
-
handleRequestMessage
Description copied from class:AbstractReplyProducingMessageHandlerSubclasses 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:
handleRequestMessagein 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:
startin interfaceLifecycle- Specified by:
startin 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:
stopin interfaceLifecycle- Specified by:
stopin 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:
isRunningin interfaceLifecycle- Specified by:
isRunningin interfaceManageableLifecycle
-