org.springframework.web.servlet.mvc.support
Class DefaultHandlerExceptionResolver

java.lang.Object
  extended by org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
      extended by org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver
All Implemented Interfaces:
Ordered, HandlerExceptionResolver

public class DefaultHandlerExceptionResolver
extends AbstractHandlerExceptionResolver

Default implementation of the HandlerExceptionResolver interface that resolves standard Spring exceptions.

Default implementations typically set the response status to a corresponding HTTP status code.

This exception resolver is enabled by default in the DispatcherServlet.

Since:
3.0
Author:
Arjen Poutsma
See Also:
handleNoSuchRequestHandlingMethod(org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object), handleHttpRequestMethodNotSupported(org.springframework.web.HttpRequestMethodNotSupportedException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object), handleHttpMediaTypeNotSupported(org.springframework.web.HttpMediaTypeNotSupportedException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object), handleMissingServletRequestParameter(org.springframework.web.bind.MissingServletRequestParameterException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object), handleTypeMismatch(org.springframework.beans.TypeMismatchException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object), handleHttpMessageNotReadable(org.springframework.http.converter.HttpMessageNotReadableException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object), handleHttpMessageNotWritable(org.springframework.http.converter.HttpMessageNotWritableException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)

Field Summary
static java.lang.String PAGE_NOT_FOUND_LOG_CATEGORY
          Log category to use when no mapped handler is found for a request.
protected static org.apache.commons.logging.Log pageNotFoundLogger
          Additional logger to use when no mapped handler is found for a request.
 
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
DefaultHandlerExceptionResolver()
          Sets the order to Ordered.LOWEST_PRECEDENCE.
 
Method Summary
protected  ModelAndView doResolveException(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object handler, java.lang.Exception ex)
          Actually resolve the given exception that got thrown during on handler execution, returning a ModelAndView that represents a specific error page if appropriate.
protected  ModelAndView handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object handler)
          Handle the case where no message converters were found for the PUT or POSTed content.
protected  ModelAndView handleHttpMessageNotReadable(HttpMessageNotReadableException ex, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object handler)
          Handle the case where a message converter can not read from a HTTP request.
protected  ModelAndView handleHttpMessageNotWritable(HttpMessageNotWritableException ex, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object handler)
          Handle the case where a message converter can not write to a HTTP request.
protected  ModelAndView handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object handler)
          Handle the case where no request handler method was found for the particular HTTP request method.
protected  ModelAndView handleMissingServletRequestParameter(MissingServletRequestParameterException ex, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object handler)
          Handle the case when a required parameter is missing.
protected  ModelAndView handleNoSuchRequestHandlingMethod(NoSuchRequestHandlingMethodException ex, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object handler)
          Handle the case where no request handler method was found.
protected  ModelAndView handleTypeMismatch(TypeMismatchException ex, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object handler)
          Handle the case when a WebDataBinder conversion error occurs.
 
Methods inherited from class org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
buildLogMessage, getOrder, logException, resolveException, setMappedHandlerClasses, setMappedHandlers, setOrder, setWarnLogCategory, shouldApplyTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PAGE_NOT_FOUND_LOG_CATEGORY

public static final java.lang.String PAGE_NOT_FOUND_LOG_CATEGORY
Log category to use when no mapped handler is found for a request.

See Also:
pageNotFoundLogger, Constant Field Values

pageNotFoundLogger

protected static final org.apache.commons.logging.Log pageNotFoundLogger
Additional logger to use when no mapped handler is found for a request.

See Also:
PAGE_NOT_FOUND_LOG_CATEGORY
Constructor Detail

DefaultHandlerExceptionResolver

public DefaultHandlerExceptionResolver()
Sets the order to Ordered.LOWEST_PRECEDENCE.

Method Detail

doResolveException

protected ModelAndView doResolveException(javax.servlet.http.HttpServletRequest request,
                                          javax.servlet.http.HttpServletResponse response,
                                          java.lang.Object handler,
                                          java.lang.Exception ex)
Description copied from class: AbstractHandlerExceptionResolver
Actually resolve the given exception that got thrown during on handler execution, returning a ModelAndView that 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:
doResolveException in class AbstractHandlerExceptionResolver
Parameters:
request - current HTTP request
response - current HTTP response
handler - the executed handler, or null if 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 ModelAndView to forward to, or null for default processing

handleNoSuchRequestHandlingMethod

protected ModelAndView handleNoSuchRequestHandlingMethod(NoSuchRequestHandlingMethodException ex,
                                                         javax.servlet.http.HttpServletRequest request,
                                                         javax.servlet.http.HttpServletResponse response,
                                                         java.lang.Object handler)
                                                  throws java.lang.Exception
Handle the case where no request handler method was found.

The default implementation logs a warning, sends an HTTP 404 error, and returns an empty ModelAndView. Alternatively, a fallback view could be chosen, or the NoSuchRequestHandlingMethodException could be rethrown as-is.

Parameters:
ex - the NoSuchRequestHandlingMethodException to be handled
request - current HTTP request
response - current HTTP response
handler - the executed handler, or null if none chosen at the time of the exception (for example, if multipart resolution failed)
Returns:
a ModelAndView to render, or null if handled directly
Throws:
java.lang.Exception - an Exception that should be thrown as result of the servlet request

handleHttpRequestMethodNotSupported

protected ModelAndView handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex,
                                                           javax.servlet.http.HttpServletRequest request,
                                                           javax.servlet.http.HttpServletResponse response,
                                                           java.lang.Object handler)
                                                    throws java.lang.Exception
Handle the case where no request handler method was found for the particular HTTP request method.

The default implementation logs a warning, sends an HTTP 405 error, sets the "Allow" header, and returns an empty ModelAndView. Alternatively, a fallback view could be chosen, or the HttpRequestMethodNotSupportedException could be rethrown as-is.

Parameters:
ex - the HttpRequestMethodNotSupportedException to be handled
request - current HTTP request
response - current HTTP response
handler - the executed handler, or null if none chosen at the time of the exception (for example, if multipart resolution failed)
Returns:
a ModelAndView to render, or null if handled directly
Throws:
java.lang.Exception - an Exception that should be thrown as result of the servlet request

handleHttpMediaTypeNotSupported

protected ModelAndView handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex,
                                                       javax.servlet.http.HttpServletRequest request,
                                                       javax.servlet.http.HttpServletResponse response,
                                                       java.lang.Object handler)
                                                throws java.lang.Exception
Handle the case where no message converters were found for the PUT or POSTed content.

The default implementation sends an HTTP 415 error, sets the "Allow" header, and returns an empty ModelAndView. Alternatively, a fallback view could be chosen, or the HttpMediaTypeNotSupportedException could be rethrown as-is.

Parameters:
ex - the HttpMediaTypeNotSupportedException to be handled
request - current HTTP request
response - current HTTP response
handler - the executed handler, or null if none chosen at the time of the exception (for example, if multipart resolution failed)
Returns:
a ModelAndView to render, or null if handled directly
Throws:
java.lang.Exception - an Exception that should be thrown as result of the servlet request

handleMissingServletRequestParameter

protected ModelAndView handleMissingServletRequestParameter(MissingServletRequestParameterException ex,
                                                            javax.servlet.http.HttpServletRequest request,
                                                            javax.servlet.http.HttpServletResponse response,
                                                            java.lang.Object handler)
                                                     throws java.lang.Exception
Handle the case when a required parameter is missing.

The default implementation sends an HTTP 400 error, and returns an empty ModelAndView. Alternatively, a fallback view could be chosen, or the MissingServletRequestParameterException could be rethrown as-is.

Parameters:
ex - the MissingServletRequestParameterException to be handled
request - current HTTP request
response - current HTTP response
handler - the executed handler, or null if none chosen at the time of the exception (for example, if multipart resolution failed)
Returns:
a ModelAndView to render, or null if handled directly
Throws:
java.lang.Exception - an Exception that should be thrown as result of the servlet request

handleTypeMismatch

protected ModelAndView handleTypeMismatch(TypeMismatchException ex,
                                          javax.servlet.http.HttpServletRequest request,
                                          javax.servlet.http.HttpServletResponse response,
                                          java.lang.Object handler)
                                   throws java.lang.Exception
Handle the case when a WebDataBinder conversion error occurs.

The default implementation sends an HTTP 400 error, and returns an empty ModelAndView. Alternatively, a fallback view could be chosen, or the TypeMismatchException could be rethrown as-is.

Parameters:
ex - the TypeMismatchException to be handled
request - current HTTP request
response - current HTTP response
handler - the executed handler, or null if none chosen at the time of the exception (for example, if multipart resolution failed)
Returns:
a ModelAndView to render, or null if handled directly
Throws:
java.lang.Exception - an Exception that should be thrown as result of the servlet request

handleHttpMessageNotReadable

protected ModelAndView handleHttpMessageNotReadable(HttpMessageNotReadableException ex,
                                                    javax.servlet.http.HttpServletRequest request,
                                                    javax.servlet.http.HttpServletResponse response,
                                                    java.lang.Object handler)
                                             throws java.lang.Exception
Handle the case where a message converter can not read from a HTTP request.

The default implementation sends an HTTP 400 error, and returns an empty ModelAndView. Alternatively, a fallback view could be chosen, or the HttpMediaTypeNotSupportedException could be rethrown as-is.

Parameters:
ex - the HttpMessageNotReadableException to be handled
request - current HTTP request
response - current HTTP response
handler - the executed handler, or null if none chosen at the time of the exception (for example, if multipart resolution failed)
Returns:
a ModelAndView to render, or null if handled directly
Throws:
java.lang.Exception - an Exception that should be thrown as result of the servlet request

handleHttpMessageNotWritable

protected ModelAndView handleHttpMessageNotWritable(HttpMessageNotWritableException ex,
                                                    javax.servlet.http.HttpServletRequest request,
                                                    javax.servlet.http.HttpServletResponse response,
                                                    java.lang.Object handler)
                                             throws java.lang.Exception
Handle the case where a message converter can not write to a HTTP request.

The default implementation sends an HTTP 500 error, and returns an empty ModelAndView. Alternatively, a fallback view could be chosen, or the HttpMediaTypeNotSupportedException could be rethrown as-is.

Parameters:
ex - the HttpMessageNotWritableException to be handled
request - current HTTP request
response - current HTTP response
handler - the executed handler, or null if none chosen at the time of the exception (for example, if multipart resolution failed)
Returns:
a ModelAndView to render, or null if handled directly
Throws:
java.lang.Exception - an Exception that should be thrown as result of the servlet request