Class DefaultExceptionPolicyStrategy
- java.lang.Object
-
- org.apache.camel.processor.errorhandler.DefaultExceptionPolicyStrategy
-
- All Implemented Interfaces:
ExceptionPolicyStrategy
public class DefaultExceptionPolicyStrategy extends Object implements ExceptionPolicyStrategy
The default strategy used in Camel to resolve theExceptionPolicyKey
that should handle the thrown exception. Selection strategy:
This strategy applies the following rules:- Will walk the exception hierarchy from bottom upwards till the thrown exception, meaning that the most outer
caused by is selected first, ending with the thrown exception itself. The method
createExceptionIterable(Throwable)
provides the Iterator used for the walking. - The exception type must be configured with an Exception that is an instance of the thrown exception, this is
tested using the
filter(ExceptionPolicyKey, Class, Throwable)
method. By default the filter uses instanceof test. - If the exception type has exactly the thrown exception then its selected as its an exact match
- Otherwise the type that has an exception that is the closest super of the thrown exception is selected (recurring up the exception hierarchy)
If theExceptionPolicyKey
has a when defined with an expression the type is also matches against the current exchange using thematchesWhen(ExceptionPolicyKey, org.apache.camel.Exchange)
method. This can be used to for more fine grained matching, so you can e.g. define multiple sets of exception types with the same exception class(es) but have a predicate attached to select which to select at runtime.
-
-
Field Summary
Fields Modifier and Type Field Description static DefaultExceptionPolicyStrategy
INSTANCE
-
Constructor Summary
Constructors Constructor Description DefaultExceptionPolicyStrategy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Iterable<Throwable>
createExceptionIterable(Throwable exception)
Strategy method creating the iterator to walk the exception in the order Camel should use for find theExceptionPolicyKey
should be used.protected boolean
filter(ExceptionPolicyKey type, Class<?> exceptionClass, Throwable exception)
Strategy to filter the given type exception class with the thrown exceptionExceptionPolicyKey
getExceptionPolicy(Set<ExceptionPolicyKey> exceptionPolicies, org.apache.camel.Exchange exchange, Throwable exception)
Resolves theExceptionPolicyKey
that should handle the thrown exception.protected boolean
matchesWhen(ExceptionPolicyKey definition, org.apache.camel.Exchange exchange)
Strategy method for matching the exception type with the current exchange.
-
-
-
Field Detail
-
INSTANCE
public static final DefaultExceptionPolicyStrategy INSTANCE
-
-
Method Detail
-
getExceptionPolicy
public ExceptionPolicyKey getExceptionPolicy(Set<ExceptionPolicyKey> exceptionPolicies, org.apache.camel.Exchange exchange, Throwable exception)
Description copied from interface:ExceptionPolicyStrategy
Resolves theExceptionPolicyKey
that should handle the thrown exception.- Specified by:
getExceptionPolicy
in interfaceExceptionPolicyStrategy
- Parameters:
exceptionPolicies
- the configured exception policies to resolve fromexchange
- the exchangeexception
- the exception that was thrown- Returns:
- the resolved exception type to handle this exception, null if none found.
-
filter
protected boolean filter(ExceptionPolicyKey type, Class<?> exceptionClass, Throwable exception)
Strategy to filter the given type exception class with the thrown exception- Parameters:
type
- the exception typeexceptionClass
- the current exception class for testingexception
- the thrown exception- Returns:
- true if the to current exception class is a candidate, false to skip it.
-
matchesWhen
protected boolean matchesWhen(ExceptionPolicyKey definition, org.apache.camel.Exchange exchange)
Strategy method for matching the exception type with the current exchange. This default implementation will match as:- Always true if no when predicate on the exception type
- Otherwise the when predicate is matches against the current exchange
- Parameters:
definition
- the exception definitionexchange
- the currentExchange
- Returns:
- true if matched, false otherwise.
-
createExceptionIterable
protected Iterable<Throwable> createExceptionIterable(Throwable exception)
Strategy method creating the iterator to walk the exception in the order Camel should use for find theExceptionPolicyKey
should be used. The default iterator will walk from the bottom upwards (the last caused by going upwards to the exception)- Parameters:
exception
- the exception- Returns:
- the list to iterate
-
-