Browse Source

Polishing

pull/1935/head
Juergen Hoeller 8 years ago
parent
commit
7a97ba54ea
  1. 9
      spring-web/src/main/java/org/springframework/web/method/support/ModelAndViewContainer.java
  2. 47
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java
  3. 9
      spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java
  4. 16
      spring-webmvc/src/main/java/org/springframework/web/servlet/view/xml/MappingJackson2XmlView.java

9
spring-web/src/main/java/org/springframework/web/method/support/ModelAndViewContainer.java

@ -1,5 +1,5 @@ @@ -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.
@ -43,6 +43,7 @@ import org.springframework.web.bind.support.SimpleSessionStatus; @@ -43,6 +43,7 @@ import org.springframework.web.bind.support.SimpleSessionStatus;
* returns the redirect model instead of the default model.
*
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @since 3.1
*/
public class ModelAndViewContainer {
@ -165,9 +166,9 @@ public class ModelAndViewContainer { @@ -165,9 +166,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.
* <p>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;

47
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java

@ -190,7 +190,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes @@ -190,7 +190,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}
* @deprecated as of 4.3, along with {@link org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException}
*/
@Deprecated
@ -213,7 +213,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes @@ -213,7 +213,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, Object handler) throws IOException {
@ -238,7 +238,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes @@ -238,7 +238,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, Object handler) throws IOException {
@ -262,7 +262,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes @@ -262,7 +262,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, Object handler) throws IOException {
@ -281,7 +281,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes @@ -281,7 +281,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,
@ -301,7 +301,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes @@ -301,7 +301,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, Object handler) throws IOException {
@ -319,7 +319,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes @@ -319,7 +319,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, Object handler) throws IOException {
@ -337,7 +337,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes @@ -337,7 +337,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, Object handler) throws IOException {
@ -358,7 +358,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes @@ -358,7 +358,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, Object handler) throws IOException {
@ -381,7 +381,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes @@ -381,7 +381,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, Object handler) throws IOException {
@ -394,17 +394,18 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes @@ -394,17 +394,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.
* <p>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, Object handler) throws IOException {
@ -419,29 +420,29 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes @@ -419,29 +420,29 @@ 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.
* <p>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, Object handler) throws IOException {
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return new ModelAndView();
}
/**
* 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.
* <p>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, Object handler) throws IOException {
@ -454,12 +455,12 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes @@ -454,12 +455,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.
* <p>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, Object handler) throws IOException {
@ -479,7 +480,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes @@ -479,7 +480,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,
@ -498,7 +499,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes @@ -498,7 +499,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,

9
spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java

@ -1,5 +1,5 @@ @@ -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.
@ -128,7 +128,8 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement @@ -128,7 +128,8 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
String tok = st.nextToken();
int eqIdx = tok.indexOf('=');
if (eqIdx == -1) {
throw new IllegalArgumentException("Expected = in attributes CSV string '" + propString + "'");
throw new IllegalArgumentException(
"Expected '=' in attributes CSV string '" + propString + "'");
}
if (eqIdx >= tok.length() - 2) {
throw new IllegalArgumentException(
@ -170,7 +171,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement @@ -170,7 +171,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
* the View instance configuration. "Dynamic" attributes, on the other hand,
* are values passed in as part of the model.
* <p>Can be populated with a "map" or "props" element in XML bean definitions.
* @param attributes Map with name Strings as keys and attribute objects as values
* @param attributes a Map with name Strings as keys and attribute objects as values
*/
public void setAttributesMap(Map<String, ?> attributes) {
if (attributes != null) {
@ -419,7 +420,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement @@ -419,7 +420,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
* Expose the model objects in the given map as request attributes.
* Names will be taken from the model Map.
* This method is suitable for all resources reachable by {@link javax.servlet.RequestDispatcher}.
* @param model Map of model objects to expose
* @param model a Map of model objects to expose
* @param request current HTTP request
*/
protected void exposeModelAsRequestAttributes(Map<String, Object> model, HttpServletRequest request) throws Exception {

16
spring-webmvc/src/main/java/org/springframework/web/servlet/view/xml/MappingJackson2XmlView.java

@ -1,5 +1,5 @@ @@ -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.
@ -40,9 +40,13 @@ import org.springframework.web.servlet.view.json.AbstractJackson2View; @@ -40,9 +40,13 @@ 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 {
/**
* The default content type for the view.
*/
public static final String DEFAULT_CONTENT_TYPE = "application/xml";
@ -67,20 +71,12 @@ public class MappingJackson2XmlView extends AbstractJackson2View { @@ -67,20 +71,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<String, Object> model) {
Object value = null;

Loading…
Cancel
Save