Class ExpressionEvaluatingRequestHandlerAdvice

All Implemented Interfaces:
Advice, Interceptor, MethodInterceptor, Aware, BeanFactoryAware, BeanNameAware, InitializingBean, ApplicationContextAware, ExpressionCapable, NamedComponent

public class ExpressionEvaluatingRequestHandlerAdvice extends AbstractRequestHandlerAdvice
Used to advise MessageHandlers. 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
  • Constructor Details

    • ExpressionEvaluatingRequestHandlerAdvice

      public ExpressionEvaluatingRequestHandlerAdvice()
  • Method Details

    • setOnSuccessExpressionString

      public void setOnSuccessExpressionString(String onSuccessExpression)
      Set the expression to evaluate against the message after a successful handler invocation. Defaults to payload, if successChannel is configured.
      Parameters:
      onSuccessExpression - the SpEL expression.
      Since:
      4.3.7
    • setOnSuccessExpression

      public void setOnSuccessExpression(@Nullable Expression onSuccessExpression)
      Set the expression to evaluate against the message after a successful handler invocation. Defaults to payload, if successChannel is configured.
      Parameters:
      onSuccessExpression - the SpEL expression.
      Since:
      5.0
    • setOnFailureExpressionString

      public void setOnFailureExpressionString(String onFailureExpression)
      Set the expression to evaluate against the root message after a failed handler invocation. The exception is available as the variable #exception. Defaults to payload, if failureChannel is configured.
      Parameters:
      onFailureExpression - the SpEL expression.
      Since:
      4.3.7
    • setOnFailureExpression

      public void setOnFailureExpression(@Nullable Expression onFailureExpression)
      Set the expression to evaluate against the root message after a failed handler invocation. The exception is available as the variable #exception. Defaults to payload, if failureChannel is configured.
      Parameters:
      onFailureExpression - the SpEL expression.
      Since:
      5.0
    • setSuccessChannel

      public void setSuccessChannel(MessageChannel successChannel)
      Set the channel to which to send the AdviceMessage after evaluating the success expression.
      Parameters:
      successChannel - the channel.
    • setSuccessChannelName

      public void setSuccessChannelName(String successChannelName)
      Set the channel name to which to send the AdviceMessage after evaluating the success expression.
      Parameters:
      successChannelName - the channel name.
      Since:
      4.3.7
    • setFailureChannel

      public void setFailureChannel(MessageChannel failureChannel)
      Set the channel to which to send the ErrorMessage after evaluating the failure expression.
      Parameters:
      failureChannel - the channel.
    • setFailureChannelName

      public void setFailureChannelName(String failureChannelName)
      Set the channel name to which to send the ErrorMessage 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 class IntegrationObjectSupport
    • doInvoke

      protected Object doInvoke(AbstractRequestHandlerAdvice.ExecutionCallback callback, Object target, Message<?> message)
      Description copied from class: AbstractRequestHandlerAdvice
      Subclasses implement this method to apply behavior to the MessageHandler.

      callback.execute() invokes the handler method and returns its result, or null.

      Specified by:
      doInvoke in class AbstractRequestHandlerAdvice
      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

      protected StandardEvaluationContext createEvaluationContext()