Class ResponseStatusExceptionResolver
- java.lang.Object
- org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
- org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver
- All Implemented Interfaces:
Aware,MessageSourceAware,Ordered,HandlerExceptionResolver
public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionResolver implements MessageSourceAware
AHandlerExceptionResolverthat uses the@ResponseStatusannotation to map exceptions to HTTP status codes.This exception resolver is enabled by default in the
DispatcherServletand the MVC Java config and the MVC namespace.As of 4.2 this resolver also looks recursively for
@ResponseStatuspresent on cause exceptions, and as of 4.2.2 this resolver supports attribute overrides for@ResponseStatusin custom composed annotations.- Since:
- 3.0
- Author:
- Arjen Poutsma, Rossen Stoyanchev, Sam Brannen
- See Also:
ResponseStatus
Field Summary
Fields inherited from class org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
logger
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor Summary
Constructors Constructor Description ResponseStatusExceptionResolver()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ModelAndViewdoResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)Actually resolve the given exception that got thrown during handler execution, returning aModelAndViewthat represents a specific error page if appropriate.protected ModelAndViewresolveResponseStatus(ResponseStatus responseStatus, HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)Template method that handles the@ResponseStatusannotation.voidsetMessageSource(MessageSource messageSource)Set the MessageSource that this object runs in.Methods inherited from class org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
buildLogMessage, getOrder, logException, prepareResponse, preventCaching, resolveException, setMappedHandlerClasses, setMappedHandlers, setOrder, setPreventResponseCaching, setWarnLogCategory, shouldApplyTo
Constructor Detail
ResponseStatusExceptionResolver
public ResponseStatusExceptionResolver()
Method Detail
setMessageSource
public void setMessageSource(MessageSource messageSource)
Description copied from interface:MessageSourceAwareSet the MessageSource that this object runs in.Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. Invoked before ApplicationContextAware's setApplicationContext.
- Specified by:
setMessageSourcein interfaceMessageSourceAware- Parameters:
messageSource- message sourceto be used by this object
doResolveException
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
Description copied from class:AbstractHandlerExceptionResolverActually 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 resolved applies ("mappedHandlers" etc), so an implementation may simply proceed with its actual exception handling.
- Specified by:
doResolveExceptionin classAbstractHandlerExceptionResolver- Parameters:
request- current HTTP requestresponse- current HTTP responsehandler- the executed handler, ornullif 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
resolveResponseStatus
protected ModelAndView resolveResponseStatus(ResponseStatus responseStatus, HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception
Template method that handles the@ResponseStatusannotation.The default implementation sends a response error using
HttpServletResponse.sendError(int)orHttpServletResponse.sendError(int, String)if the annotation has a reason and then returns an empty ModelAndView.- Parameters:
responseStatus- the annotationrequest- current HTTP requestresponse- current HTTP responsehandler- the executed handler, ornullif none chosen at the time of the exception, e.g. if multipart resolution failedex- the exception- Returns:
- an empty ModelAndView, i.e. exception resolved
- Throws:
Exception