Class ExceptionMapperFactory
- All Implemented Interfaces:
ExceptionMappers
Exception mappers
implementation that aggregates
exception mappers and server as the main entry point for exception mapper
instance lookup.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Configurator which initializes and registerExceptionMappers
instance intoInjectionManager
andBootstrapBag
.private static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Value
<Set<ExceptionMapperFactory.ExceptionMapperType>> private static final Logger
-
Constructor Summary
ConstructorsConstructorDescriptionExceptionMapperFactory
(InjectionManager injectionManager) Create new exception mapper factory initialized withinjection manager
instance that will be used to look up all providers implementingExceptionMapper
interface. -
Method Summary
Modifier and TypeMethodDescriptioncreateLazyExceptionMappers
(InjectionManager injectionManager) ReturnsLazyValue
of exception mappers that delays their creation to the first use.private int
<T extends Throwable>
javax.ws.rs.ext.ExceptionMapper<T> Get an exception mapping provider for a particular class of exception.private <T extends Throwable>
javax.ws.rs.ext.ExceptionMapper<T> <T extends Throwable>
javax.ws.rs.ext.ExceptionMapper<T> findMapping
(T exceptionInstance) Get an exception mapping provider for a particular exception instance.getExceptionType
(Class<? extends javax.ws.rs.ext.ExceptionMapper> c) private Class
getResolvedType
(Type t, Class c, Class dc) private Class
Get exception type for given exception mapper class.private Class
getTypeFromInterface
(Class<?> clazz, Class<? extends javax.ws.rs.ext.ExceptionMapper> original) Iterate through interface hierarchy ofclazz
and get exception type for given class.private <T extends Throwable>
booleanisPreferredCandidate
(T exceptionInstance, javax.ws.rs.ext.ExceptionMapper<T> candidate, boolean sameDistance) Determines whether the currently considered candidate should be preferred over the previous one.
-
Field Details
-
LOGGER
-
exceptionMapperTypes
-
-
Constructor Details
-
ExceptionMapperFactory
Create new exception mapper factory initialized withinjection manager
instance that will be used to look up all providers implementingExceptionMapper
interface.- Parameters:
injectionManager
- injection manager.
-
-
Method Details
-
findMapping
Description copied from interface:ExceptionMappers
Get an exception mapping provider for a particular exception instance.This method is similar to method
ExceptionMappers.find(Class)
. In addition it takes into an account the result of theExtendedExceptionMapper.isMappable(Throwable)
of any mapper that implements JerseyExtendedExceptionMapper
API. If an extended exception mapper returnsfalse
fromisMappable(Throwable)
, the mapper is disregarded from the search. Exception mapping providers are checked one by one until a first provider returnstrue
from theisMappable(Throwable)
method or until a first provider is found which best supports the exception type and does not implementExtendedExceptionMapper
API (i.e. it is a standard JAX-RSExceptionMapper
). The order in which the providers are checked is determined by the distance of the declared exception mapper type and the actual exception type.Note that if an exception mapping provider does not implement
ExtendedExceptionMapper
it is always considered applicable for a given exception instance.- Specified by:
findMapping
in interfaceExceptionMappers
- Type Parameters:
T
- type of the exception handled by the exception mapping provider.- Parameters:
exceptionInstance
- exception to be handled by the exception mapping provider.- Returns:
- an
ExceptionMapper
for the supplied exception instance type ornull
if none is found.
-
find
Description copied from interface:ExceptionMappers
Get an exception mapping provider for a particular class of exception. Returns the provider whose generic type is the nearest superclass oftype
.- Specified by:
find
in interfaceExceptionMappers
- Type Parameters:
T
- type of the exception handled by the exception mapping provider.- Parameters:
type
- the class of exception.- Returns:
- an
ExceptionMapper
for the supplied type ornull
if none is found.
-
find
-
isPreferredCandidate
private <T extends Throwable> boolean isPreferredCandidate(T exceptionInstance, javax.ws.rs.ext.ExceptionMapper<T> candidate, boolean sameDistance) Determines whether the currently considered candidate should be preferred over the previous one.- Type Parameters:
T
- exception type.- Parameters:
exceptionInstance
- exception to be mapped.candidate
- mapper able to map given exception type.sameDistance
- flag indicating whether this and the previously considered candidate are in the same distance.- Returns:
true
if the given candidate is preferred over the previous one with the same or lower distance,false
otherwise.
-
createLazyExceptionMappers
private LazyValue<Set<ExceptionMapperFactory.ExceptionMapperType>> createLazyExceptionMappers(InjectionManager injectionManager) ReturnsLazyValue
of exception mappers that delays their creation to the first use. The exception mappers won't be created during bootstrap but at the time of the first call.- Parameters:
injectionManager
- injection manager that may not be fully populated at the time of a function call therefore the result is wrapped to lazy value.- Returns:
- lazy value of exception mappers.
-
distance
-
getExceptionType
-
getType
Get exception type for given exception mapper class.- Parameters:
clazz
- class to get exception type for.- Returns:
- exception type for given class.
-
getTypeFromInterface
private Class getTypeFromInterface(Class<?> clazz, Class<? extends javax.ws.rs.ext.ExceptionMapper> original) Iterate through interface hierarchy ofclazz
and get exception type for given class.- Parameters:
clazz
- class to inspect.- Returns:
- exception type for given class or
null
if the class doesn't implementExceptionMapper
.
-
getResolvedType
-