Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,8 +44,8 @@ public interface HandlerExceptionResolver {
|
||||
* @param handler the executed handler, or {@code null} if none chosen at the
|
||||
* time of the exception (for example, if multipart resolution failed)
|
||||
* @param ex the exception that got thrown during handler execution
|
||||
* @return a corresponding {@code ModelAndView} to forward to, or {@code null}
|
||||
* for default processing
|
||||
* @return a corresponding {@code ModelAndView} to forward to,
|
||||
* or {@code null} for default processing in the resolution chain
|
||||
*/
|
||||
ModelAndView resolveException(
|
||||
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.web.servlet.handler;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@@ -125,8 +124,8 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
|
||||
* to the {@link #doResolveException} template method.
|
||||
*/
|
||||
@Override
|
||||
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler, Exception ex) {
|
||||
public ModelAndView resolveException(
|
||||
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
||||
|
||||
if (shouldApplyTo(request, handler)) {
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
@@ -237,9 +236,10 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
|
||||
* @param handler the executed handler, or {@code null} if none chosen at the time
|
||||
* of the exception (for example, if multipart resolution failed)
|
||||
* @param ex the exception that got thrown during handler execution
|
||||
* @return a corresponding {@code ModelAndView} to forward to, or {@code null} for default processing
|
||||
* @return a corresponding {@code ModelAndView} to forward to,
|
||||
* or {@code null} for default processing in the resolution chain
|
||||
*/
|
||||
protected abstract ModelAndView doResolveException(HttpServletRequest request,
|
||||
HttpServletResponse response, Object handler, Exception ex);
|
||||
protected abstract ModelAndView doResolveException(
|
||||
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -170,11 +170,12 @@ public class SimpleMappingExceptionResolver extends AbstractHandlerExceptionReso
|
||||
* @param handler the executed handler, or {@code null} if none chosen at the time
|
||||
* of the exception (for example, if multipart resolution failed)
|
||||
* @param ex the exception that got thrown during handler execution
|
||||
* @return a corresponding ModelAndView to forward to, or {@code null} for default processing
|
||||
* @return a corresponding {@code ModelAndView} to forward to,
|
||||
* or {@code null} for default processing in the resolution chain
|
||||
*/
|
||||
@Override
|
||||
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler, Exception ex) {
|
||||
protected ModelAndView doResolveException(
|
||||
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
||||
|
||||
// Expose ModelAndView for chosen error view.
|
||||
String viewName = determineViewName(ex, request);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -59,16 +59,16 @@ public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionRes
|
||||
|
||||
|
||||
@Override
|
||||
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler, Exception ex) {
|
||||
protected ModelAndView doResolveException(
|
||||
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
||||
|
||||
ResponseStatus responseStatus = AnnotatedElementUtils.findMergedAnnotation(ex.getClass(), ResponseStatus.class);
|
||||
if (responseStatus != null) {
|
||||
ResponseStatus status = AnnotatedElementUtils.findMergedAnnotation(ex.getClass(), ResponseStatus.class);
|
||||
if (status != null) {
|
||||
try {
|
||||
return resolveResponseStatus(responseStatus, request, response, handler, ex);
|
||||
return resolveResponseStatus(status, request, response, handler, ex);
|
||||
}
|
||||
catch (Exception resolveEx) {
|
||||
logger.warn("Handling of @ResponseStatus resulted in Exception", resolveEx);
|
||||
logger.warn("ResponseStatus handling resulted in exception", resolveEx);
|
||||
}
|
||||
}
|
||||
else if (ex.getCause() instanceof Exception) {
|
||||
@@ -79,7 +79,7 @@ public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionRes
|
||||
}
|
||||
|
||||
/**
|
||||
* Template method that handles {@link ResponseStatus @ResponseStatus} annotation.
|
||||
* Template method that handles the {@link ResponseStatus @ResponseStatus} annotation.
|
||||
* <p>The default implementation sends a response error using
|
||||
* {@link HttpServletResponse#sendError(int)} or
|
||||
* {@link HttpServletResponse#sendError(int, String)} if the annotation has a
|
||||
@@ -88,11 +88,9 @@ public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionRes
|
||||
* @param request current HTTP request
|
||||
* @param response current HTTP response
|
||||
* @param handler the executed handler, or {@code null} if none chosen at the
|
||||
* time of the exception (for example, if multipart resolution failed)
|
||||
* @param ex the exception that got thrown during handler execution or the
|
||||
* exception that has the ResponseStatus annotation if found on the cause.
|
||||
* @return a corresponding ModelAndView to forward to, or {@code null}
|
||||
* for default processing
|
||||
* time of the exception, e.g. if multipart resolution failed
|
||||
* @param ex the exception
|
||||
* @return an empty ModelAndView, i.e. exception resolved
|
||||
*/
|
||||
protected ModelAndView resolveResponseStatus(ResponseStatus responseStatus, HttpServletRequest request,
|
||||
HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -52,9 +52,9 @@ import org.springframework.web.servlet.NoHandlerFoundException;
|
||||
import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver;
|
||||
|
||||
/**
|
||||
* Default implementation of the {@link org.springframework.web.servlet.HandlerExceptionResolver
|
||||
* HandlerExceptionResolver} interface that resolves standard Spring exceptions and translates
|
||||
* them to corresponding HTTP status codes.
|
||||
* The default implementation of the {@link org.springframework.web.servlet.HandlerExceptionResolver}
|
||||
* interface, resolving standard Spring MVC exceptions and translating them to corresponding
|
||||
* HTTP status codes.
|
||||
*
|
||||
* <p>This exception resolver is enabled by default in the common Spring
|
||||
* {@link org.springframework.web.servlet.DispatcherServlet}.
|
||||
@@ -102,63 +102,69 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler, Exception ex) {
|
||||
protected ModelAndView doResolveException(
|
||||
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
||||
|
||||
try {
|
||||
if (ex instanceof org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException) {
|
||||
return handleNoSuchRequestHandlingMethod((org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException) ex,
|
||||
return handleNoSuchRequestHandlingMethod(
|
||||
(org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException) ex,
|
||||
request, response, handler);
|
||||
}
|
||||
else if (ex instanceof HttpRequestMethodNotSupportedException) {
|
||||
return handleHttpRequestMethodNotSupported((HttpRequestMethodNotSupportedException) ex, request,
|
||||
response, handler);
|
||||
return handleHttpRequestMethodNotSupported(
|
||||
(HttpRequestMethodNotSupportedException) ex, request, response, handler);
|
||||
}
|
||||
else if (ex instanceof HttpMediaTypeNotSupportedException) {
|
||||
return handleHttpMediaTypeNotSupported((HttpMediaTypeNotSupportedException) ex, request, response,
|
||||
handler);
|
||||
return handleHttpMediaTypeNotSupported(
|
||||
(HttpMediaTypeNotSupportedException) ex, request, response, handler);
|
||||
}
|
||||
else if (ex instanceof HttpMediaTypeNotAcceptableException) {
|
||||
return handleHttpMediaTypeNotAcceptable((HttpMediaTypeNotAcceptableException) ex, request, response,
|
||||
handler);
|
||||
return handleHttpMediaTypeNotAcceptable(
|
||||
(HttpMediaTypeNotAcceptableException) ex, request, response, handler);
|
||||
}
|
||||
else if (ex instanceof MissingPathVariableException) {
|
||||
return handleMissingPathVariable((MissingPathVariableException) ex, request,
|
||||
response, handler);
|
||||
return handleMissingPathVariable(
|
||||
(MissingPathVariableException) ex, request, response, handler);
|
||||
}
|
||||
else if (ex instanceof MissingServletRequestParameterException) {
|
||||
return handleMissingServletRequestParameter((MissingServletRequestParameterException) ex, request,
|
||||
response, handler);
|
||||
return handleMissingServletRequestParameter(
|
||||
(MissingServletRequestParameterException) ex, request, response, handler);
|
||||
}
|
||||
else if (ex instanceof ServletRequestBindingException) {
|
||||
return handleServletRequestBindingException((ServletRequestBindingException) ex, request, response,
|
||||
handler);
|
||||
return handleServletRequestBindingException(
|
||||
(ServletRequestBindingException) ex, request, response, handler);
|
||||
}
|
||||
else if (ex instanceof ConversionNotSupportedException) {
|
||||
return handleConversionNotSupported((ConversionNotSupportedException) ex, request, response, handler);
|
||||
return handleConversionNotSupported(
|
||||
(ConversionNotSupportedException) ex, request, response, handler);
|
||||
}
|
||||
else if (ex instanceof TypeMismatchException) {
|
||||
return handleTypeMismatch((TypeMismatchException) ex, request, response, handler);
|
||||
return handleTypeMismatch(
|
||||
(TypeMismatchException) ex, request, response, handler);
|
||||
}
|
||||
else if (ex instanceof HttpMessageNotReadableException) {
|
||||
return handleHttpMessageNotReadable((HttpMessageNotReadableException) ex, request, response, handler);
|
||||
return handleHttpMessageNotReadable(
|
||||
(HttpMessageNotReadableException) ex, request, response, handler);
|
||||
}
|
||||
else if (ex instanceof HttpMessageNotWritableException) {
|
||||
return handleHttpMessageNotWritable((HttpMessageNotWritableException) ex, request, response, handler);
|
||||
return handleHttpMessageNotWritable(
|
||||
(HttpMessageNotWritableException) ex, request, response, handler);
|
||||
}
|
||||
else if (ex instanceof MethodArgumentNotValidException) {
|
||||
return handleMethodArgumentNotValidException((MethodArgumentNotValidException) ex, request, response,
|
||||
handler);
|
||||
return handleMethodArgumentNotValidException(
|
||||
(MethodArgumentNotValidException) ex, request, response, handler);
|
||||
}
|
||||
else if (ex instanceof MissingServletRequestPartException) {
|
||||
return handleMissingServletRequestPartException((MissingServletRequestPartException) ex, request,
|
||||
response, handler);
|
||||
return handleMissingServletRequestPartException(
|
||||
(MissingServletRequestPartException) ex, request, response, handler);
|
||||
}
|
||||
else if (ex instanceof BindException) {
|
||||
return handleBindException((BindException) ex, request, response, handler);
|
||||
}
|
||||
else if (ex instanceof NoHandlerFoundException) {
|
||||
return handleNoHandlerFoundException((NoHandlerFoundException) ex, request, response, handler);
|
||||
return handleNoHandlerFoundException(
|
||||
(NoHandlerFoundException) ex, request, response, handler);
|
||||
}
|
||||
else if (ex instanceof AsyncRequestTimeoutException) {
|
||||
return handleAsyncRequestTimeoutException(
|
||||
@@ -167,7 +173,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
|
||||
}
|
||||
catch (Exception handlerException) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Handling of [" + ex.getClass().getName() + "] resulted in Exception", handlerException);
|
||||
logger.warn("Handling of [" + ex.getClass().getName() + "] resulted in exception", handlerException);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -507,7 +513,6 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
|
||||
return new ModelAndView();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Invoked to send a server error. Sets the status to 500 and also sets the
|
||||
* request attribute "javax.servlet.error.exception" to the Exception.
|
||||
@@ -515,7 +520,6 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
|
||||
protected void sendServerError(Exception ex, HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException {
|
||||
|
||||
|
||||
request.setAttribute("javax.servlet.error.exception", ex);
|
||||
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user