From 6027cf22558d6c92cd8de9bfd5fb0bc68dd299dd Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 14 Aug 2018 20:42:40 +0200 Subject: [PATCH] Polishing --- .../method/support/ModelAndViewContainer.java | 6 +-- .../web/servlet/DispatcherServlet.java | 14 +++--- .../DefaultHandlerExceptionResolver.java | 43 ++++++++++--------- .../web/servlet/view/AbstractView.java | 3 +- .../view/xml/MappingJackson2XmlView.java | 11 +---- 5 files changed, 33 insertions(+), 44 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/method/support/ModelAndViewContainer.java b/spring-web/src/main/java/org/springframework/web/method/support/ModelAndViewContainer.java index 5058bd965e6..273c319743b 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/ModelAndViewContainer.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/ModelAndViewContainer.java @@ -172,9 +172,9 @@ public class ModelAndViewContainer { /** * Provide a separate model instance to use in a redirect scenario. - * The provided additional model however is not used unless - * {@link #setRedirectModelScenario(boolean)} gets set to {@code true} to signal - * a redirect scenario. + *

The provided additional model however is not used unless + * {@link #setRedirectModelScenario} gets set to {@code true} + * to signal an actual redirect scenario. */ public void setRedirectModel(ModelMap redirectModel) { this.redirectModel = redirectModel; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java index a9d2a8e2701..1e3945819ba 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java @@ -906,7 +906,6 @@ public class DispatcherServlet extends FrameworkServlet { */ @Override protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception { - logRequest(request); // Keep a snapshot of the request attributes in case of an include, @@ -953,7 +952,6 @@ public class DispatcherServlet extends FrameworkServlet { private void logRequest(HttpServletRequest request) { if (logger.isDebugEnabled()) { - String params; if (isEnableLoggingRequestDetails()) { params = request.getParameterMap().entrySet().stream() @@ -961,16 +959,14 @@ public class DispatcherServlet extends FrameworkServlet { .collect(Collectors.joining(", ")); } else { - params = request.getParameterMap().isEmpty() ? "" : "masked"; + params = (request.getParameterMap().isEmpty() ? "" : "masked"); } String query = StringUtils.isEmpty(request.getQueryString()) ? "" : "?" + request.getQueryString(); - - String dispatchType = !request.getDispatcherType().equals(DispatcherType.REQUEST) ? - "\"" + request.getDispatcherType().name() + "\" dispatch for " : ""; - - String message = dispatchType + request.getMethod() + - " \"" + getRequestUri(request) + query + "\", parameters={" + params + "}"; + String dispatchType = (!request.getDispatcherType().equals(DispatcherType.REQUEST) ? + "\"" + request.getDispatcherType().name() + "\" dispatch for " : ""); + String message = (dispatchType + request.getMethod() + " \"" + getRequestUri(request) + + query + "\", parameters={" + params + "}"); if (logger.isTraceEnabled()) { List values = Collections.list(request.getHeaderNames()); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java index 627681e7a57..4699f98f63e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java @@ -247,7 +247,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * @param handler the executed handler, or {@code null} if none chosen * at the time of the exception (for example, if multipart resolution failed) * @return an empty ModelAndView indicating the exception was handled - * @throws IOException potentially thrown from response.sendError() + * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ protected ModelAndView handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { @@ -272,7 +272,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * @param response current HTTP response * @param handler the executed handler * @return an empty ModelAndView indicating the exception was handled - * @throws IOException potentially thrown from response.sendError() + * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ protected ModelAndView handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { @@ -296,7 +296,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * @param response current HTTP response * @param handler the executed handler * @return an empty ModelAndView indicating the exception was handled - * @throws IOException potentially thrown from response.sendError() + * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ protected ModelAndView handleHttpMediaTypeNotAcceptable(HttpMediaTypeNotAcceptableException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { @@ -315,7 +315,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * @param response current HTTP response * @param handler the executed handler * @return an empty ModelAndView indicating the exception was handled - * @throws IOException potentially thrown from response.sendError() + * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} * @since 4.2 */ protected ModelAndView handleMissingPathVariable(MissingPathVariableException ex, @@ -335,7 +335,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * @param response current HTTP response * @param handler the executed handler * @return an empty ModelAndView indicating the exception was handled - * @throws IOException potentially thrown from response.sendError() + * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ protected ModelAndView handleMissingServletRequestParameter(MissingServletRequestParameterException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { @@ -353,7 +353,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * @param response current HTTP response * @param handler the executed handler * @return an empty ModelAndView indicating the exception was handled - * @throws IOException potentially thrown from response.sendError() + * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ protected ModelAndView handleServletRequestBindingException(ServletRequestBindingException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { @@ -371,7 +371,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * @param response current HTTP response * @param handler the executed handler * @return an empty ModelAndView indicating the exception was handled - * @throws IOException potentially thrown from response.sendError() + * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ protected ModelAndView handleConversionNotSupported(ConversionNotSupportedException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { @@ -392,7 +392,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * @param response current HTTP response * @param handler the executed handler * @return an empty ModelAndView indicating the exception was handled - * @throws IOException potentially thrown from response.sendError() + * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ protected ModelAndView handleTypeMismatch(TypeMismatchException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { @@ -415,7 +415,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * @param response current HTTP response * @param handler the executed handler * @return an empty ModelAndView indicating the exception was handled - * @throws IOException potentially thrown from response.sendError() + * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ protected ModelAndView handleHttpMessageNotReadable(HttpMessageNotReadableException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { @@ -428,17 +428,18 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes } /** - * Handle the case where a {@linkplain org.springframework.http.converter.HttpMessageConverter message converter} + * Handle the case where a + * {@linkplain org.springframework.http.converter.HttpMessageConverter message converter} * cannot write to a HTTP request. *

The default implementation sends an HTTP 500 error, and returns an empty {@code ModelAndView}. - * Alternatively, a fallback view could be chosen, or the HttpMediaTypeNotSupportedException could be - * rethrown as-is. + * Alternatively, a fallback view could be chosen, or the HttpMediaTypeNotSupportedException could + * be rethrown as-is. * @param ex the HttpMessageNotWritableException to be handled * @param request current HTTP request * @param response current HTTP response * @param handler the executed handler * @return an empty ModelAndView indicating the exception was handled - * @throws IOException potentially thrown from response.sendError() + * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ protected ModelAndView handleHttpMessageNotWritable(HttpMessageNotWritableException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { @@ -453,12 +454,12 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes /** * Handle the case where an argument annotated with {@code @Valid} such as * an {@link RequestBody} or {@link RequestPart} argument fails validation. - * An HTTP 400 error is sent back to the client. + *

By default, an HTTP 400 error is sent back to the client. * @param request current HTTP request * @param response current HTTP response * @param handler the executed handler * @return an empty ModelAndView indicating the exception was handled - * @throws IOException potentially thrown from response.sendError() + * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ protected ModelAndView handleMethodArgumentNotValidException(MethodArgumentNotValidException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { @@ -470,12 +471,12 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes /** * Handle the case where an {@linkplain RequestPart @RequestPart}, a {@link MultipartFile}, * or a {@code javax.servlet.http.Part} argument is required but is missing. - * An HTTP 400 error is sent back to the client. + *

By default, an HTTP 400 error is sent back to the client. * @param request current HTTP request * @param response current HTTP response * @param handler the executed handler * @return an empty ModelAndView indicating the exception was handled - * @throws IOException potentially thrown from response.sendError() + * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ protected ModelAndView handleMissingServletRequestPartException(MissingServletRequestPartException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { @@ -488,12 +489,12 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * Handle the case where an {@linkplain ModelAttribute @ModelAttribute} method * argument has binding or validation errors and is not followed by another * method argument of type {@link BindingResult}. - * By default, an HTTP 400 error is sent back to the client. + *

By default, an HTTP 400 error is sent back to the client. * @param request current HTTP request * @param response current HTTP response * @param handler the executed handler * @return an empty ModelAndView indicating the exception was handled - * @throws IOException potentially thrown from response.sendError() + * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ protected ModelAndView handleBindException(BindException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { @@ -513,7 +514,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * @param handler the executed handler, or {@code null} if none chosen * at the time of the exception (for example, if multipart resolution failed) * @return an empty ModelAndView indicating the exception was handled - * @throws IOException potentially thrown from response.sendError() + * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} * @since 4.0 */ protected ModelAndView handleNoHandlerFoundException(NoHandlerFoundException ex, @@ -532,7 +533,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * @param handler the executed handler, or {@code null} if none chosen * at the time of the exception (for example, if multipart resolution failed) * @return an empty ModelAndView indicating the exception was handled - * @throws IOException potentially thrown from response.sendError() + * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} * @since 4.2.8 */ protected ModelAndView handleAsyncRequestTimeoutException(AsyncRequestTimeoutException ex, diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java index 1db8a49c125..8c549b3e9a9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java @@ -497,8 +497,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement } protected String formatViewName() { - return (getBeanName() != null ? - "name '" + getBeanName() + "'" : "[" + getClass().getSimpleName() + "]"); + return (getBeanName() != null ? "name '" + getBeanName() + "'" : "[" + getClass().getSimpleName() + "]"); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xml/MappingJackson2XmlView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xml/MappingJackson2XmlView.java index 147f195747f..74a4f585d5e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xml/MappingJackson2XmlView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/xml/MappingJackson2XmlView.java @@ -42,6 +42,7 @@ import org.springframework.web.servlet.view.json.AbstractJackson2View; * * @author Sebastien Deleuze * @since 4.1 + * @see org.springframework.web.servlet.view.json.MappingJackson2JsonView */ public class MappingJackson2XmlView extends AbstractJackson2View { @@ -73,20 +74,12 @@ public class MappingJackson2XmlView extends AbstractJackson2View { super(xmlMapper, DEFAULT_CONTENT_TYPE); } - /** - * {@inheritDoc} - */ + @Override public void setModelKey(String modelKey) { this.modelKey = modelKey; } - /** - * Filter out undesired attributes from the given model. - * The return value can be either another {@link Map} or a single value object. - * @param model the model, as passed on to {@link #renderMergedOutputModel} - * @return the value to be rendered - */ @Override protected Object filterModel(Map model) { Object value = null;