Class ExpressionEvaluatingRequestHandlerAdvice
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice
org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice
- All Implemented Interfaces:
Advice
,Interceptor
,MethodInterceptor
,Aware
,BeanFactoryAware
,BeanNameAware
,InitializingBean
,ApplicationContextAware
,ExpressionCapable
,NamedComponent
Used to advise
MessageHandler
s.
Two expressions 'onSuccessExpression' and 'onFailureExpression' are evaluated when
appropriate. If the evaluation returns a result, a message is sent to the onSuccessChannel
or onFailureChannel as appropriate; the message is an AdviceMessage
containing the evaluation result in its payload and the inputMessage
property containing
the original message that was sent to the endpoint.
The failure expression is NOT evaluated if the success expression throws an exception.
When expressions are not configured, but channels are, the default expression is evaluated
just into a payload
from the message.
- Since:
- 2.2
- Author:
- Gary Russell, Artem Bilan
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Nested classes/interfaces inherited from class org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice
AbstractRequestHandlerAdvice.ExecutionCallback, AbstractRequestHandlerAdvice.ThrowableHolderException
-
Field Summary
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected StandardEvaluationContext
protected Object
doInvoke
(AbstractRequestHandlerAdvice.ExecutionCallback callback, Object target, Message<?> message) Subclasses implement this method to apply behavior to theMessageHandler
.protected void
onInit()
Subclasses may implement this for initialization logic.void
setFailureChannel
(MessageChannel failureChannel) Set the channel to which to send theErrorMessage
after evaluating the failure expression.void
setFailureChannelName
(String failureChannelName) Set the channel name to which to send theErrorMessage
after evaluating the failure expression.void
setOnFailureExpression
(Expression onFailureExpression) Set the expression to evaluate against the root message after a failed handler invocation.void
setOnFailureExpressionString
(String onFailureExpression) Set the expression to evaluate against the root message after a failed handler invocation.void
setOnSuccessExpression
(Expression onSuccessExpression) Set the expression to evaluate against the message after a successful handler invocation.void
setOnSuccessExpressionString
(String onSuccessExpression) Set the expression to evaluate against the message after a successful handler invocation.void
setPropagateEvaluationFailures
(boolean propagateOnSuccessEvaluationFailures) If true and an onSuccess expression evaluation fails with an exception, the exception will be thrown to the caller.void
setReturnFailureExpressionResult
(boolean returnFailureExpressionResult) If true, the result of evaluating the onFailureExpression will be returned as the result of AbstractReplyProducingMessageHandler.handleRequestMessage(Message).void
setSuccessChannel
(MessageChannel successChannel) Set the channel to which to send theAdviceMessage
after evaluating the success expression.void
setSuccessChannelName
(String successChannelName) Set the channel name to which to send theAdviceMessage
after evaluating the success expression.void
setTrapException
(boolean trapException) If true, any exception will be caught and null returned.Methods inherited from class org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice
invoke, unwrapExceptionIfNecessary, unwrapThrowableIfNecessary
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getComponentType, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
-
Constructor Details
-
ExpressionEvaluatingRequestHandlerAdvice
public ExpressionEvaluatingRequestHandlerAdvice()
-
-
Method Details
-
setOnSuccessExpressionString
Set the expression to evaluate against the message after a successful handler invocation. Defaults topayload
, ifsuccessChannel
is configured.- Parameters:
onSuccessExpression
- the SpEL expression.- Since:
- 4.3.7
-
setOnSuccessExpression
Set the expression to evaluate against the message after a successful handler invocation. Defaults topayload
, ifsuccessChannel
is configured.- Parameters:
onSuccessExpression
- the SpEL expression.- Since:
- 5.0
-
setOnFailureExpressionString
Set the expression to evaluate against the root message after a failed handler invocation. The exception is available as the variable#exception
. Defaults topayload
, iffailureChannel
is configured.- Parameters:
onFailureExpression
- the SpEL expression.- Since:
- 4.3.7
-
setOnFailureExpression
Set the expression to evaluate against the root message after a failed handler invocation. The exception is available as the variable#exception
. Defaults topayload
, iffailureChannel
is configured.- Parameters:
onFailureExpression
- the SpEL expression.- Since:
- 5.0
-
setSuccessChannel
Set the channel to which to send theAdviceMessage
after evaluating the success expression.- Parameters:
successChannel
- the channel.
-
setSuccessChannelName
Set the channel name to which to send theAdviceMessage
after evaluating the success expression.- Parameters:
successChannelName
- the channel name.- Since:
- 4.3.7
-
setFailureChannel
Set the channel to which to send theErrorMessage
after evaluating the failure expression.- Parameters:
failureChannel
- the channel.
-
setFailureChannelName
Set the channel name to which to send theErrorMessage
after evaluating the failure expression.- Parameters:
failureChannelName
- the channel name.- Since:
- 4.3.7
-
setTrapException
public void setTrapException(boolean trapException) If true, any exception will be caught and null returned. Default false.- Parameters:
trapException
- true to trap Exceptions.
-
setReturnFailureExpressionResult
public void setReturnFailureExpressionResult(boolean returnFailureExpressionResult) If true, the result of evaluating the onFailureExpression will be returned as the result of AbstractReplyProducingMessageHandler.handleRequestMessage(Message).- Parameters:
returnFailureExpressionResult
- true to return the result of the evaluation.
-
setPropagateEvaluationFailures
public void setPropagateEvaluationFailures(boolean propagateOnSuccessEvaluationFailures) If true and an onSuccess expression evaluation fails with an exception, the exception will be thrown to the caller. If false, the exception is caught. Default false. Ignored for onFailure expression evaluation - the original exception will be propagated (unless trapException is true).- Parameters:
propagateOnSuccessEvaluationFailures
- The propagateOnSuccessEvaluationFailures to set.
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupport
Subclasses may implement this for initialization logic.- Overrides:
onInit
in classIntegrationObjectSupport
-
doInvoke
protected Object doInvoke(AbstractRequestHandlerAdvice.ExecutionCallback callback, Object target, Message<?> message) Description copied from class:AbstractRequestHandlerAdvice
Subclasses implement this method to apply behavior to theMessageHandler
.callback.execute() invokes the handler method and returns its result, or null.
- Specified by:
doInvoke
in classAbstractRequestHandlerAdvice
- Parameters:
callback
- Subclasses invoke the execute() method on this interface to invoke the handler method.target
- The target handler.message
- The message that will be sent to the handler.- Returns:
- the result after invoking the
MessageHandler
.
-
createEvaluationContext
-