Class OnExceptionDefinition

All Implemented Interfaces:
org.apache.camel.CamelContextAware, org.apache.camel.LineNumberAware, Block, OutputNode, org.apache.camel.NamedNode, org.apache.camel.spi.HasCamelContext, org.apache.camel.spi.HasId, org.apache.camel.spi.IdAware

@Metadata(label="error") public class OnExceptionDefinition extends OutputDefinition<OnExceptionDefinition>
Route to be executed when an exception is thrown
  • Constructor Details

    • OnExceptionDefinition

      public OnExceptionDefinition()
    • OnExceptionDefinition

      public OnExceptionDefinition(List<Class<? extends Throwable>> exceptionClasses)
    • OnExceptionDefinition

      public OnExceptionDefinition(Class<? extends Throwable> exceptionType)
  • Method Details

    • setRouteScoped

      public void setRouteScoped(boolean routeScoped)
    • isRouteScoped

      public boolean isRouteScoped()
    • setParent

      public void setParent(ProcessorDefinition<?> parent)
      Overrides:
      setParent in class ProcessorDefinition<OnExceptionDefinition>
    • toString

      public String toString()
      Overrides:
      toString in class OutputDefinition<OnExceptionDefinition>
    • description

      protected String description()
    • getShortName

      public String getShortName()
      Specified by:
      getShortName in interface org.apache.camel.NamedNode
      Overrides:
      getShortName in class OutputDefinition<OnExceptionDefinition>
    • getLabel

      public String getLabel()
      Description copied from class: ProcessorDefinition
      Returns a label to describe this node such as the expression if some kind of expression node
      Specified by:
      getLabel in interface org.apache.camel.NamedNode
      Overrides:
      getLabel in class ProcessorDefinition<OnExceptionDefinition>
    • isAbstract

      public boolean isAbstract()
      Description copied from class: ProcessorDefinition
      Whether this model is abstract or not.

      An abstract model is something that is used for configuring cross cutting concerns such as error handling, transaction policies, interceptors etc.

      Regular definitions is what is part of the route, such as ToDefinition, WireTapDefinition and the likes.

      Will by default return false to indicate regular definition, so all the abstract definitions must override this method and return true instead.

      This information is used in camel-spring to let Camel work a bit on the model provided by JAXB from the Spring XML file. This is needed to handle those cross cutting concerns properly. The Java DSL does not have this issue as it can work this out directly using the fluent builder methods.

      Overrides:
      isAbstract in class ProcessorDefinition<OnExceptionDefinition>
      Returns:
      true for abstract, otherwise false for regular.
    • isTopLevelOnly

      public boolean isTopLevelOnly()
      Description copied from class: ProcessorDefinition
      Whether this definition can only be added as top-level directly on the route itself (such as onException,onCompletion,intercept, etc.)

      If trying to add a top-level only definition to a nested output would fail in the ProcessorDefinition.addOutput(ProcessorDefinition) method.

      Overrides:
      isTopLevelOnly in class ProcessorDefinition<OnExceptionDefinition>
    • validateConfiguration

      public void validateConfiguration()
    • onException

      public OnExceptionDefinition onException(Class<? extends Throwable> exceptionType)
      Description copied from class: ProcessorDefinition
      Exception clause for catching certain exceptions and handling them.
      Overrides:
      onException in class ProcessorDefinition<OnExceptionDefinition>
      Parameters:
      exceptionType - the exception to catch
      Returns:
      the exception builder to configure
    • handled

      public OnExceptionDefinition handled(boolean handled)
      Sets whether the exchange should be marked as handled or not.
      Parameters:
      handled - handled or not
      Returns:
      the builder
    • handled

      public OnExceptionDefinition handled(@AsPredicate org.apache.camel.Predicate handled)
      Sets whether the exchange should be marked as handled or not.
      Parameters:
      handled - predicate that determines true or false
      Returns:
      the builder
    • handled

      public OnExceptionDefinition handled(@AsPredicate org.apache.camel.Expression handled)
      Sets whether the exchange should be marked as handled or not.
      Parameters:
      handled - expression that determines true or false
      Returns:
      the builder
    • continued

      public OnExceptionDefinition continued(boolean continued)
      Sets whether the exchange should handle and continue routing from the point of failure.

      If this option is enabled then its considered handled as well.

      Parameters:
      continued - continued or not
      Returns:
      the builder
    • continued

      public OnExceptionDefinition continued(@AsPredicate org.apache.camel.Predicate continued)
      Sets whether the exchange should be marked as handled or not.

      If this option is enabled then its considered handled as well.

      Parameters:
      continued - predicate that determines true or false
      Returns:
      the builder
    • continued

      public OnExceptionDefinition continued(@AsPredicate org.apache.camel.Expression continued)
      Sets whether the exchange should be marked as handled or not.

      If this option is enabled then its considered handled as well.

      Parameters:
      continued - expression that determines true or false
      Returns:
      the builder
    • onWhen

      public OnExceptionDefinition onWhen(@AsPredicate org.apache.camel.Predicate predicate)
      Sets an additional predicate that should be true before the onException is triggered.

      To be used for fine grained controlling whether a thrown exception should be intercepted by this exception type or not.

      Parameters:
      predicate - predicate that determines true or false
      Returns:
      the builder
    • retryWhile

      public OnExceptionDefinition retryWhile(@AsPredicate org.apache.camel.Predicate retryWhile)
      Sets the retry while predicate.

      Will continue retrying until predicate returns false.

      Parameters:
      retryWhile - predicate that determines when to stop retrying
      Returns:
      the builder
    • backOffMultiplier

      public OnExceptionDefinition backOffMultiplier(double backOffMultiplier)
      Sets the back off multiplier
      Parameters:
      backOffMultiplier - the back off multiplier
      Returns:
      the builder
    • backOffMultiplier

      public OnExceptionDefinition backOffMultiplier(String backOffMultiplier)
      Sets the back off multiplier (supports property placeholders)
      Parameters:
      backOffMultiplier - the back off multiplier
      Returns:
      the builder
    • collisionAvoidanceFactor

      public OnExceptionDefinition collisionAvoidanceFactor(double collisionAvoidanceFactor)
      Sets the collision avoidance factor
      Parameters:
      collisionAvoidanceFactor - the factor
      Returns:
      the builder
    • collisionAvoidanceFactor

      public OnExceptionDefinition collisionAvoidanceFactor(String collisionAvoidanceFactor)
      Sets the collision avoidance factor (supports property placeholders)
      Parameters:
      collisionAvoidanceFactor - the factor
      Returns:
      the builder
    • collisionAvoidancePercent

      public OnExceptionDefinition collisionAvoidancePercent(double collisionAvoidancePercent)
      Sets the collision avoidance percentage
      Parameters:
      collisionAvoidancePercent - the percentage
      Returns:
      the builder
    • redeliveryDelay

      public OnExceptionDefinition redeliveryDelay(long delay)
      Sets the initial redelivery delay
      Parameters:
      delay - delay in millis
      Returns:
      the builder
    • redeliveryDelay

      public OnExceptionDefinition redeliveryDelay(String delay)
      Sets the initial redelivery delay (supports property placeholders)
      Parameters:
      delay - delay in millis
      Returns:
      the builder
    • asyncDelayedRedelivery

      public OnExceptionDefinition asyncDelayedRedelivery()
      Allow asynchronous delayed redelivery.
      Returns:
      the builder
    • retriesExhaustedLogLevel

      public OnExceptionDefinition retriesExhaustedLogLevel(org.apache.camel.LoggingLevel retriesExhaustedLogLevel)
      Sets the logging level to use when retries have been exhausted
      Parameters:
      retriesExhaustedLogLevel - the logging level
      Returns:
      the builder
    • retryAttemptedLogLevel

      public OnExceptionDefinition retryAttemptedLogLevel(org.apache.camel.LoggingLevel retryAttemptedLogLevel)
      Sets the logging level to use for logging retry attempts
      Parameters:
      retryAttemptedLogLevel - the logging level
      Returns:
      the builder
    • logStackTrace

      public OnExceptionDefinition logStackTrace(boolean logStackTrace)
      Sets whether to log stacktrace for failed messages.
    • logStackTrace

      public OnExceptionDefinition logStackTrace(String logStackTrace)
      Sets whether to log stacktrace for failed messages (supports property placeholders)
    • logRetryStackTrace

      public OnExceptionDefinition logRetryStackTrace(boolean logRetryStackTrace)
      Sets whether to log stacktrace for failed redelivery attempts
    • logRetryStackTrace

      public OnExceptionDefinition logRetryStackTrace(String logRetryStackTrace)
      Sets whether to log stacktrace for failed redelivery attempts (supports property placeholders)
    • logHandled

      public OnExceptionDefinition logHandled(boolean logHandled)
      Sets whether to log errors even if its handled
    • logHandled

      public OnExceptionDefinition logHandled(String logHandled)
      Sets whether to log errors even if its handled (supports property placeholders)
    • logNewException

      public OnExceptionDefinition logNewException(boolean logNewException)
      Sets whether new exceptions should be logged or not (supports property placeholders). Can be used to include or reduce verbose.

      A new exception is an exception that was thrown while handling a previous exception.

    • logNewException

      public OnExceptionDefinition logNewException(String logNewException)
      Sets whether new exceptions should be logged or not (supports property placeholders). Can be used to include or reduce verbose.

      A new exception is an exception that was thrown while handling a previous exception.

    • logContinued

      public OnExceptionDefinition logContinued(boolean logContinued)
      Sets whether to log errors even if its continued
    • logContinued

      public OnExceptionDefinition logContinued(String logContinued)
      Sets whether to log errors even if its continued (supports property placeholders)
    • logRetryAttempted

      public OnExceptionDefinition logRetryAttempted(boolean logRetryAttempted)
      Sets whether to log retry attempts
    • logRetryAttempted

      public OnExceptionDefinition logRetryAttempted(String logRetryAttempted)
      Sets whether to log retry attempts (supports property placeholders)
    • logExhausted

      public OnExceptionDefinition logExhausted(boolean logExhausted)
      Sets whether to log exhausted exceptions
    • logExhausted

      public OnExceptionDefinition logExhausted(String logExhausted)
      Sets whether to log exhausted exceptions (supports property placeholders)
    • logExhaustedMessageHistory

      public OnExceptionDefinition logExhaustedMessageHistory(boolean logExhaustedMessageHistory)
      Sets whether to log exhausted exceptions with message history
    • logExhaustedMessageHistory

      public OnExceptionDefinition logExhaustedMessageHistory(String logExhaustedMessageHistory)
      Sets whether to log exhausted exceptions with message history
    • logExhaustedMessageBody

      public OnExceptionDefinition logExhaustedMessageBody(boolean logExhaustedMessageBody)
      Sets whether to log exhausted message body with message history. Requires logExhaustedMessageHistory to be enabled.
    • logExhaustedMessageBody

      public OnExceptionDefinition logExhaustedMessageBody(String logExhaustedMessageBody)
      Sets whether to log exhausted message body with message history. Requires logExhaustedMessageHistory to be enabled.
    • maximumRedeliveries

      public OnExceptionDefinition maximumRedeliveries(int maximumRedeliveries)
      Sets the maximum redeliveries
      • 5 = default value
      • 0 = no redeliveries
      • -1 = redeliver forever
      Parameters:
      maximumRedeliveries - the value
      Returns:
      the builder
    • maximumRedeliveries

      public OnExceptionDefinition maximumRedeliveries(String maximumRedeliveries)
      Sets the maximum redeliveries (supports property placeholders)
      • 5 = default value
      • 0 = no redeliveries
      • -1 = redeliver forever
      Parameters:
      maximumRedeliveries - the value
      Returns:
      the builder
    • useCollisionAvoidance

      public OnExceptionDefinition useCollisionAvoidance()
      Turn on collision avoidance.
      Returns:
      the builder
    • useExponentialBackOff

      public OnExceptionDefinition useExponentialBackOff()
      Turn on exponential back off
      Returns:
      the builder
    • maximumRedeliveryDelay

      public OnExceptionDefinition maximumRedeliveryDelay(long maximumRedeliveryDelay)
      Sets the maximum delay between redelivery
      Parameters:
      maximumRedeliveryDelay - the delay in millis
      Returns:
      the builder
    • maximumRedeliveryDelay

      public OnExceptionDefinition maximumRedeliveryDelay(String maximumRedeliveryDelay)
      Sets the maximum delay between redelivery (supports property placeholders)
      Parameters:
      maximumRedeliveryDelay - the delay in millis
      Returns:
      the builder
    • redeliveryPolicyRef

      public OnExceptionDefinition redeliveryPolicyRef(String redeliveryPolicyRef)
      Sets a reference to a redelivery policy to lookup in the Registry to be used.
      Parameters:
      redeliveryPolicyRef - reference to use for lookup
      Returns:
      the builder
    • delayPattern

      public OnExceptionDefinition delayPattern(String delayPattern)
      Sets the delay pattern with delay intervals.
      Parameters:
      delayPattern - the delay pattern
      Returns:
      the builder
    • useOriginalMessage

      public OnExceptionDefinition useOriginalMessage()
      Will use the original input Message (original body and headers) when an Exchange is moved to the dead letter queue.

      Notice: this only applies when all redeliveries attempt have failed and the Exchange is doomed for failure.
      Instead of using the current inprogress Exchange IN message we use the original IN message instead. This allows you to store the original input in the dead letter queue instead of the inprogress snapshot of the IN message. For instance if you route transform the IN body during routing and then failed. With the original exchange store in the dead letter queue it might be easier to manually re submit the Exchange again as the IN message is the same as when Camel received it. So you should be able to send the Exchange to the same input.

      The difference between useOriginalMessage and useOriginalBody is that the former includes both the original body and headers, where as the latter only includes the original body. You can use the latter to enrich the message with custom headers and include the original message body. The former wont let you do this, as its using the original message body and headers as they are. You cannot enable both useOriginalMessage and useOriginalBody.

      The original input message is defensively copied, and the copied message body is converted to StreamCache if possible (stream caching is enabled, can be disabled globally or on the original route), to ensure the body can be read when the original message is being used later. If the body is converted to StreamCache then the message body on the current Exchange is replaced with the StreamCache body. If the body is not converted to StreamCache then the body will not be able to re-read when accessed later.

      Important: The original input means the input message that are bounded by the current UnitOfWork. An unit of work typically spans one route, or multiple routes if they are connected using internal endpoints such as direct or seda. When messages is passed via external endpoints such as JMS or HTTP then the consumer will create a new unit of work, with the message it received as input as the original input. Also some EIP patterns such as splitter, multicast, will create a new unit of work boundary for the messages in their sub-route (eg the split message); however these EIPs have an option named shareUnitOfWork which allows to combine with the parent unit of work in regard to error handling and therefore use the parent original message.

      By default this feature is off.

      Returns:
      the builder
      See Also:
    • useOriginalBody

      public OnExceptionDefinition useOriginalBody()
      Will use the original input Message body (original body only) when an Exchange is moved to the dead letter queue.

      Notice: this only applies when all redeliveries attempt have failed and the Exchange is doomed for failure.
      Instead of using the current inprogress Exchange IN message we use the original IN message instead. This allows you to store the original input in the dead letter queue instead of the inprogress snapshot of the IN message. For instance if you route transform the IN body during routing and then failed. With the original exchange store in the dead letter queue it might be easier to manually re submit the Exchange again as the IN message is the same as when Camel received it. So you should be able to send the Exchange to the same input.

      The difference between useOriginalMessage and useOriginalBody is that the former includes both the original body and headers, where as the latter only includes the original body. You can use the latter to enrich the message with custom headers and include the original message body. The former wont let you do this, as its using the original message body and headers as they are. You cannot enable both useOriginalMessage and useOriginalBody.

      The original input message is defensively copied, and the copied message body is converted to StreamCache if possible (stream caching is enabled, can be disabled globally or on the original route), to ensure the body can be read when the original message is being used later. If the body is converted to StreamCache then the message body on the current Exchange is replaced with the StreamCache body. If the body is not converted to StreamCache then the body will not be able to re-read when accessed later.

      Important: The original input means the input message that are bounded by the current UnitOfWork. An unit of work typically spans one route, or multiple routes if they are connected using internal endpoints such as direct or seda. When messages is passed via external endpoints such as JMS or HTTP then the consumer will create a new unit of work, with the message it received as input as the original input. Also some EIP patterns such as splitter, multicast, will create a new unit of work boundary for the messages in their sub-route (eg the split message); however these EIPs have an option named shareUnitOfWork which allows to combine with the parent unit of work in regard to error handling and therefore use the parent original message.

      By default this feature is off.

      Returns:
      the builder
      See Also:
    • onRedelivery

      public OnExceptionDefinition onRedelivery(org.apache.camel.Processor processor)
      Sets a processor that should be processed before a redelivery attempt.

      Can be used to change the Exchange before its being redelivered.

    • onRedeliveryRef

      public OnExceptionDefinition onRedeliveryRef(String ref)
      Sets a reference to a processor that should be processed before a redelivery attempt.

      Can be used to change the Exchange before its being redelivered.

      Parameters:
      ref - reference to the processor
    • onExceptionOccurred

      public OnExceptionDefinition onExceptionOccurred(org.apache.camel.Processor processor)
      Sets a processor that should be processed just after an exception occurred. Can be used to perform custom logging about the occurred exception at the exact time it happened.

      Important: Any exception thrown from this processor will be ignored.

    • onExceptionOccurredRef

      public OnExceptionDefinition onExceptionOccurredRef(String ref)
      Sets a reference to a processor that should be processed just after an exception occurred. Can be used to perform custom logging about the occurred exception at the exact time it happened.

      Important: Any exception thrown from this processor will be ignored.

      Parameters:
      ref - reference to the processor
    • getOutputs

      public List<ProcessorDefinition<?>> getOutputs()
      Overrides:
      getOutputs in class OutputDefinition<OnExceptionDefinition>
    • setOutputs

      public void setOutputs(List<ProcessorDefinition<?>> outputs)
      Overrides:
      setOutputs in class OutputDefinition<OnExceptionDefinition>
    • getExceptions

      public List<String> getExceptions()
    • setExceptions

      public void setExceptions(List<String> exceptions)
      A set of exceptions to react upon.
    • getRedeliveryPolicyType

      public RedeliveryPolicyDefinition getRedeliveryPolicyType()
    • setRedeliveryPolicyType

      public void setRedeliveryPolicyType(RedeliveryPolicyDefinition redeliveryPolicyType)
      Used for configuring redelivery options
    • getRedeliveryPolicyRef

      public String getRedeliveryPolicyRef()
    • setRedeliveryPolicyRef

      public void setRedeliveryPolicyRef(String redeliveryPolicyRef)
    • getHandledPolicy

      public org.apache.camel.Predicate getHandledPolicy()
    • setHandled

      public void setHandled(ExpressionSubElementDefinition handled)
    • getContinued

      public ExpressionSubElementDefinition getContinued()
    • setContinued

      public void setContinued(ExpressionSubElementDefinition continued)
    • getHandled

      public ExpressionSubElementDefinition getHandled()
    • setHandledPolicy

      public void setHandledPolicy(org.apache.camel.Predicate handledPolicy)
    • getContinuedPolicy

      public org.apache.camel.Predicate getContinuedPolicy()
    • setContinuedPolicy

      public void setContinuedPolicy(org.apache.camel.Predicate continuedPolicy)
    • getOnWhen

      public WhenDefinition getOnWhen()
    • setOnWhen

      public void setOnWhen(WhenDefinition onWhen)
    • getRetryWhile

      public ExpressionSubElementDefinition getRetryWhile()
    • setRetryWhile

      public void setRetryWhile(ExpressionSubElementDefinition retryWhile)
    • getRetryWhilePolicy

      public org.apache.camel.Predicate getRetryWhilePolicy()
    • setRetryWhilePolicy

      public void setRetryWhilePolicy(org.apache.camel.Predicate retryWhilePolicy)
    • getOnRedelivery

      public org.apache.camel.Processor getOnRedelivery()
    • setOnRedelivery

      public void setOnRedelivery(org.apache.camel.Processor onRedelivery)
    • getOnRedeliveryRef

      public String getOnRedeliveryRef()
    • setOnRedeliveryRef

      public void setOnRedeliveryRef(String onRedeliveryRef)
    • getOnExceptionOccurred

      public org.apache.camel.Processor getOnExceptionOccurred()
    • setOnExceptionOccurred

      public void setOnExceptionOccurred(org.apache.camel.Processor onExceptionOccurred)
    • getOnExceptionOccurredRef

      public String getOnExceptionOccurredRef()
    • setOnExceptionOccurredRef

      public void setOnExceptionOccurredRef(String onExceptionOccurredRef)
    • getUseOriginalMessage

      public String getUseOriginalMessage()
    • setUseOriginalMessage

      public void setUseOriginalMessage(String useOriginalMessage)
    • getUseOriginalBody

      public String getUseOriginalBody()
    • setUseOriginalBody

      public void setUseOriginalBody(String useOriginalBody)
    • getOrCreateRedeliveryPolicy

      protected RedeliveryPolicyDefinition getOrCreateRedeliveryPolicy()