Class AbstractHandlerExceptionResolver
- All Implemented Interfaces:
- Ordered,- HandlerExceptionResolver
- Direct Known Subclasses:
- AbstractHandlerMethodExceptionResolver,- DefaultHandlerExceptionResolver,- ResponseStatusExceptionResolver,- SimpleMappingExceptionResolver
HandlerExceptionResolver implementations.
 Supports mapped handlers and
 handler classes that the resolver
 should be applied to and implements the Ordered interface.
- Since:
- 3.0
- Author:
- Arjen Poutsma, Juergen Hoeller, Sam Brannen
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected final org.apache.commons.logging.LogLogger available to subclasses.Fields inherited from interface org.springframework.core.OrderedHIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddMappedHandlerClass(Class<?> mappedHandlerClass) Alternative tosetMappedHandlerClasses(Class[]).protected StringbuildLogMessage(Exception ex, HttpServletRequest request) Build a log message for the given exception, occurred during processing the given request.protected abstract @Nullable ModelAndViewdoResolveException(HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex) Actually resolve the given exception that got thrown during handler execution, returning aModelAndViewthat represents a specific error page if appropriate.Return theconfiguredmapped handler classes.intgetOrder()Get the order value of this object.protected booleanWhether there are any handler mappings registered viasetMappedHandlers(Set),setMappedHandlerClasses(Class[]), orsetMappedHandlerPredicate(Predicate).protected voidlogException(Exception ex, HttpServletRequest request) Log the given exception at warn level, provided that warn logging has been activated through the"warnLogCategory"property.protected voidprepareResponse(Exception ex, HttpServletResponse response) Prepare the response for the exceptional case.protected voidpreventCaching(HttpServletResponse response) Prevents the response from being cached, through setting corresponding HTTPCache-Control: no-storeheader.resolveException(HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex) Check whether this resolver is supposed to apply (i.e.voidsetMappedHandlerClasses(Class<?>... mappedHandlerClasses) Specify the set of classes that this exception resolver should apply to.voidsetMappedHandlerPredicate(Predicate<Object> predicate) Use aPredicateto determine which handlers this exception resolver applies to, including when the request was not mapped in which case the handler isnull.voidsetMappedHandlers(Set<?> mappedHandlers) Specify the set of handlers that this exception resolver should apply to.voidsetOrder(int order) voidsetPreventResponseCaching(boolean preventResponseCaching) Specify whether to prevent HTTP response caching for any view resolved by this exception resolver.voidsetWarnLogCategory(String loggerName) Set the log category for warn logging.protected booleanshouldApplyTo(HttpServletRequest request, @Nullable Object handler) Check whether this resolver is supposed to apply to the given handler.
- 
Field Details- 
loggerprotected final org.apache.commons.logging.Log loggerLogger available to subclasses.
 
- 
- 
Constructor Details- 
AbstractHandlerExceptionResolverpublic AbstractHandlerExceptionResolver()
 
- 
- 
Method Details- 
setOrderpublic void setOrder(int order) 
- 
getOrderpublic int getOrder()Description copied from interface:OrderedGet the order value of this object.Higher values are interpreted as lower priority. As a consequence, the object with the lowest value has the highest priority (somewhat analogous to Servlet load-on-startupvalues).Same order values will result in arbitrary sort positions for the affected objects. 
- 
setMappedHandlerPredicateUse aPredicateto determine which handlers this exception resolver applies to, including when the request was not mapped in which case the handler isnull.If no handler predicate, nor handlers, nor handler classes are set, the exception resolver applies to all handlers. - Since:
- 6.1.2
 
- 
setMappedHandlersSpecify the set of handlers that this exception resolver should apply to.If no handler predicate, nor handlers, nor handler classes are set, the exception resolver applies to all handlers. - See Also:
 
- 
setMappedHandlerClassesSpecify the set of classes that this exception resolver should apply to. The resolver will only apply to handlers of the specified types; the specified types may be interfaces or superclasses of handlers as well.If no handler predicate, nor handlers, nor handler classes are set, the exception resolver applies to all handlers. - See Also:
 
- 
addMappedHandlerClassAlternative tosetMappedHandlerClasses(Class[]).- Since:
- 6.1
 
- 
getMappedHandlerClassesReturn theconfiguredmapped handler classes.
- 
setWarnLogCategorySet the log category for warn logging. The name will be passed to the underlying logger implementation through Commons Logging, getting interpreted as a log category according to the logger's configuration. Ifnullor empty String is passed, warn logging is turned off.By default there is no warn logging although subclasses like DefaultHandlerExceptionResolvercan change that default. Specify this setting to activate warn logging into a specific category. Alternatively, override thelogException(java.lang.Exception, jakarta.servlet.http.HttpServletRequest)method for custom logging.- See Also:
- 
- LogFactory.getLog(String)
- Logger.getLogger(String)
 
 
- 
setPreventResponseCachingpublic void setPreventResponseCaching(boolean preventResponseCaching) Specify whether to prevent HTTP response caching for any view resolved by this exception resolver.Default is false. Switch this totruein order to automatically generate HTTP response headers that suppress response caching.
- 
resolveExceptionpublic @Nullable ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex) Check whether this resolver is supposed to apply (i.e. if the supplied handler matches any of the configured handlers or handler classes), and then delegate to thedoResolveException(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse, java.lang.Object, java.lang.Exception)template method.- Specified by:
- resolveExceptionin interface- HandlerExceptionResolver
- Parameters:
- request- current HTTP request
- response- current HTTP response
- handler- the executed handler, or- nullif none chosen at the time of the exception (for example, if multipart resolution failed)
- ex- the exception that got thrown during handler execution
- Returns:
- a corresponding ModelAndViewto forward to, ornullfor default processing in the resolution chain
 
- 
shouldApplyToCheck whether this resolver is supposed to apply to the given handler.The default implementation checks against the configured handlerPredicate handlers and handler classes, if any. - Parameters:
- request- current HTTP request
- handler- the executed handler, or- nullif none chosen at the time of the exception (for example, if multipart resolution failed)
- Returns:
- whether this resolved should proceed with resolving the exception for the given request and handler
- See Also:
 
- 
hasHandlerMappingsprotected boolean hasHandlerMappings()Whether there are any handler mappings registered viasetMappedHandlers(Set),setMappedHandlerClasses(Class[]), orsetMappedHandlerPredicate(Predicate).- Since:
- 5.3
 
- 
logExceptionLog the given exception at warn level, provided that warn logging has been activated through the"warnLogCategory"property.Calls buildLogMessage(java.lang.Exception, jakarta.servlet.http.HttpServletRequest)in order to determine the concrete message to log.- Parameters:
- ex- the exception that got thrown during handler execution
- request- current HTTP request (useful for obtaining metadata)
- See Also:
- 
- setWarnLogCategory(java.lang.String)
- buildLogMessage(java.lang.Exception, jakarta.servlet.http.HttpServletRequest)
- Log.warn(Object, Throwable)
 
 
- 
buildLogMessageBuild a log message for the given exception, occurred during processing the given request.- Parameters:
- ex- the exception that got thrown during handler execution
- request- current HTTP request (useful for obtaining metadata)
- Returns:
- the log message to use
 
- 
prepareResponsePrepare the response for the exceptional case.The default implementation prevents the response from being cached, if the "preventResponseCaching"property has been set to "true".- Parameters:
- ex- the exception that got thrown during handler execution
- response- current HTTP response
- See Also:
 
- 
preventCachingPrevents the response from being cached, through setting corresponding HTTPCache-Control: no-storeheader.- Parameters:
- response- current HTTP response
 
- 
doResolveExceptionprotected abstract @Nullable ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex) Actually resolve the given exception that got thrown during handler execution, returning aModelAndViewthat represents a specific error page if appropriate.May be overridden in subclasses, in order to apply specific exception checks. Note that this template method will be invoked after checking whether this resolver applies ("mappedHandlers" etc), so an implementation may simply proceed with its actual exception handling. - Parameters:
- request- current HTTP request
- response- current HTTP response
- handler- the executed handler, or- nullif none chosen at the time of the exception (for example, if multipart resolution failed)
- ex- the exception that got thrown during handler execution
- Returns:
- a corresponding ModelAndViewto forward to, ornullfor default processing in the resolution chain
 
 
-