Class ExceptionMapperFactory
- java.lang.Object
-
- org.glassfish.jersey.internal.ExceptionMapperFactory
-
- All Implemented Interfaces:
ExceptionMappers
public class ExceptionMapperFactory extends java.lang.Object implements ExceptionMappers
Exception mappersimplementation that aggregates exception mappers and server as the main entry point for exception mapper instance lookup.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExceptionMapperFactory.ExceptionMappersConfiguratorConfigurator which initializes and registerExceptionMappersinstance intoInjectionManagerandBootstrapBag.private static classExceptionMapperFactory.ExceptionMapperType
-
Field Summary
Fields Modifier and Type Field Description private Value<java.util.Set<ExceptionMapperFactory.ExceptionMapperType>>exceptionMapperTypesprivate static java.util.logging.LoggerLOGGER
-
Constructor Summary
Constructors Constructor Description ExceptionMapperFactory(InjectionManager injectionManager)Create new exception mapper factory initialized withinjection managerinstance that will be used to look up all providers implementingExceptionMapperinterface.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private LazyValue<java.util.Set<ExceptionMapperFactory.ExceptionMapperType>>createLazyExceptionMappers(InjectionManager injectionManager)ReturnsLazyValueof exception mappers that delays their creation to the first use.private intdistance(java.lang.Class<?> c, java.lang.Class<?> emtc)<T extends java.lang.Throwable>
javax.ws.rs.ext.ExceptionMapper<T>find(java.lang.Class<T> type)Get an exception mapping provider for a particular class of exception.private <T extends java.lang.Throwable>
javax.ws.rs.ext.ExceptionMapper<T>find(java.lang.Class<T> type, T exceptionInstance)<T extends java.lang.Throwable>
javax.ws.rs.ext.ExceptionMapper<T>findMapping(T exceptionInstance)Get an exception mapping provider for a particular exception instance.private java.lang.Class<? extends java.lang.Throwable>getExceptionType(java.lang.Class<? extends javax.ws.rs.ext.ExceptionMapper> c)private java.lang.ClassgetResolvedType(java.lang.reflect.Type t, java.lang.Class c, java.lang.Class dc)private java.lang.ClassgetType(java.lang.Class<? extends javax.ws.rs.ext.ExceptionMapper> clazz)Get exception type for given exception mapper class.private java.lang.ClassgetTypeFromInterface(java.lang.Class<?> clazz, java.lang.Class<? extends javax.ws.rs.ext.ExceptionMapper> original)Iterate through interface hierarchy ofclazzand get exception type for given class.private <T extends java.lang.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 Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
exceptionMapperTypes
private final Value<java.util.Set<ExceptionMapperFactory.ExceptionMapperType>> exceptionMapperTypes
-
-
Constructor Detail
-
ExceptionMapperFactory
public ExceptionMapperFactory(InjectionManager injectionManager)
Create new exception mapper factory initialized withinjection managerinstance that will be used to look up all providers implementingExceptionMapperinterface.- Parameters:
injectionManager- injection manager.
-
-
Method Detail
-
findMapping
public <T extends java.lang.Throwable> javax.ws.rs.ext.ExceptionMapper<T> findMapping(T exceptionInstance)
Description copied from interface:ExceptionMappersGet 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 JerseyExtendedExceptionMapperAPI. If an extended exception mapper returnsfalsefromisMappable(Throwable), the mapper is disregarded from the search. Exception mapping providers are checked one by one until a first provider returnstruefrom theisMappable(Throwable)method or until a first provider is found which best supports the exception type and does not implementExtendedExceptionMapperAPI (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
ExtendedExceptionMapperit is always considered applicable for a given exception instance.- Specified by:
findMappingin 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
ExceptionMapperfor the supplied exception instance type ornullif none is found.
-
find
public <T extends java.lang.Throwable> javax.ws.rs.ext.ExceptionMapper<T> find(java.lang.Class<T> type)
Description copied from interface:ExceptionMappersGet an exception mapping provider for a particular class of exception. Returns the provider whose generic type is the nearest superclass oftype.- Specified by:
findin interfaceExceptionMappers- Type Parameters:
T- type of the exception handled by the exception mapping provider.- Parameters:
type- the class of exception.- Returns:
- an
ExceptionMapperfor the supplied type ornullif none is found.
-
find
private <T extends java.lang.Throwable> javax.ws.rs.ext.ExceptionMapper<T> find(java.lang.Class<T> type, T exceptionInstance)
-
isPreferredCandidate
private <T extends java.lang.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:
trueif the given candidate is preferred over the previous one with the same or lower distance,falseotherwise.
-
createLazyExceptionMappers
private LazyValue<java.util.Set<ExceptionMapperFactory.ExceptionMapperType>> createLazyExceptionMappers(InjectionManager injectionManager)
ReturnsLazyValueof 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
private int distance(java.lang.Class<?> c, java.lang.Class<?> emtc)
-
getExceptionType
private java.lang.Class<? extends java.lang.Throwable> getExceptionType(java.lang.Class<? extends javax.ws.rs.ext.ExceptionMapper> c)
-
getType
private java.lang.Class getType(java.lang.Class<? extends javax.ws.rs.ext.ExceptionMapper> clazz)
Get exception type for given exception mapper class.- Parameters:
clazz- class to get exception type for.- Returns:
- exception type for given class.
-
getTypeFromInterface
private java.lang.Class getTypeFromInterface(java.lang.Class<?> clazz, java.lang.Class<? extends javax.ws.rs.ext.ExceptionMapper> original)Iterate through interface hierarchy ofclazzand get exception type for given class.- Parameters:
clazz- class to inspect.- Returns:
- exception type for given class or
nullif the class doesn't implementExceptionMapper.
-
getResolvedType
private java.lang.Class getResolvedType(java.lang.reflect.Type t, java.lang.Class c, java.lang.Class dc)
-
-