Polishing
This commit is contained in:
@@ -51,7 +51,7 @@ public class ModelAndView {
|
||||
/** Model Map */
|
||||
private ModelMap model;
|
||||
|
||||
/** Optional status for the response */
|
||||
/** Optional HTTP status for the response */
|
||||
private HttpStatus status;
|
||||
|
||||
/** Indicates whether or not this instance has been cleared with a call to {@link #clear()} */
|
||||
@@ -120,7 +120,6 @@ public class ModelAndView {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates new ModelAndView given a view name, model, and status.
|
||||
* @param viewName name of the View to render, to be resolved
|
||||
@@ -129,6 +128,7 @@ public class ModelAndView {
|
||||
* (Objects). Model entries may not be {@code null}, but the
|
||||
* model Map may be {@code null} if there is no model data.
|
||||
* @param status an alternative status code to use for the response.
|
||||
* @since 4.3
|
||||
*/
|
||||
public ModelAndView(String viewName, Map<String, ?> model, HttpStatus status) {
|
||||
this.view = viewName;
|
||||
@@ -239,7 +239,7 @@ public class ModelAndView {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the status to use for the response.
|
||||
* Set the HTTP status to use for the response.
|
||||
* @since 4.3
|
||||
*/
|
||||
public void setStatus(HttpStatus status) {
|
||||
@@ -247,7 +247,8 @@ public class ModelAndView {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configured status for the response.
|
||||
* Return the configured HTTP status for the response, if any.
|
||||
* @since 4.3
|
||||
*/
|
||||
public HttpStatus getStatus() {
|
||||
return this.status;
|
||||
|
||||
@@ -847,7 +847,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
|
||||
* be useful for example to allow default resolvers to be registered and then
|
||||
* insert a custom one through this method.
|
||||
* @param exceptionResolvers the list of configured resolvers to extend.
|
||||
* @since 4.3.1
|
||||
* @since 4.3
|
||||
*/
|
||||
protected void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ public interface WebMvcConfigurer {
|
||||
* be useful for example to allow default resolvers to be registered and then
|
||||
* insert a custom one through this method.
|
||||
* @param exceptionResolvers the list of configured resolvers to extend.
|
||||
* @since 4.3.1
|
||||
* @since 4.3
|
||||
*/
|
||||
void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers);
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.springframework.web.servlet.LocaleResolver;
|
||||
*/
|
||||
public class AcceptHeaderLocaleResolver implements LocaleResolver {
|
||||
|
||||
private final List<Locale> supportedLocales = new ArrayList<Locale>();
|
||||
private final List<Locale> supportedLocales = new ArrayList<Locale>(4);
|
||||
|
||||
private Locale defaultLocale;
|
||||
|
||||
@@ -91,8 +91,9 @@ public class AcceptHeaderLocaleResolver implements LocaleResolver {
|
||||
|
||||
@Override
|
||||
public Locale resolveLocale(HttpServletRequest request) {
|
||||
if (getDefaultLocale() != null && request.getHeader("Accept-Language") == null) {
|
||||
return getDefaultLocale();
|
||||
Locale defaultLocale = getDefaultLocale();
|
||||
if (defaultLocale != null && request.getHeader("Accept-Language") == null) {
|
||||
return defaultLocale;
|
||||
}
|
||||
Locale locale = request.getLocale();
|
||||
if (!isSupportedLocale(locale)) {
|
||||
@@ -102,7 +103,8 @@ public class AcceptHeaderLocaleResolver implements LocaleResolver {
|
||||
}
|
||||
|
||||
private boolean isSupportedLocale(Locale locale) {
|
||||
return (getSupportedLocales().isEmpty() || getSupportedLocales().contains(locale));
|
||||
List<Locale> supportedLocales = getSupportedLocales();
|
||||
return (supportedLocales.isEmpty() || supportedLocales.contains(locale));
|
||||
}
|
||||
|
||||
private Locale findSupportedLocale(HttpServletRequest request, Locale fallback) {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.servlet.mvc.method.annotation;
|
||||
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
@@ -27,7 +28,7 @@ public interface DeferredResultAdapter {
|
||||
|
||||
/**
|
||||
* Create a {@code DeferredResult} for the given return value.
|
||||
* @param returnValue the return value, never {@code null}
|
||||
* @param returnValue the return value (never {@code null})
|
||||
* @return the DeferredResult
|
||||
*/
|
||||
DeferredResult<?> adaptToDeferredResult(Object returnValue);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.servlet.mvc.method.annotation;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
@@ -33,17 +34,15 @@ import org.springframework.web.method.annotation.AbstractNamedValueMethodArgumen
|
||||
*/
|
||||
public class RequestAttributeMethodArgumentResolver extends AbstractNamedValueMethodArgumentResolver {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
return parameter.hasParameterAnnotation(RequestAttribute.class);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
|
||||
RequestAttribute annot = parameter.getParameterAnnotation(RequestAttribute.class);
|
||||
return new NamedValueInfo(annot.name(), annot.required(), ValueConstants.DEFAULT_NONE);
|
||||
RequestAttribute ann = parameter.getParameterAnnotation(RequestAttribute.class);
|
||||
return new NamedValueInfo(ann.name(), ann.required(), ValueConstants.DEFAULT_NONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,23 +13,24 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.servlet.mvc.method.annotation;
|
||||
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
|
||||
|
||||
/**
|
||||
* Contract to adapt streaming async types to {@code ResponseBodyEmitter}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.3
|
||||
*/
|
||||
public interface ResponseBodyEmitterAdapter {
|
||||
|
||||
/**
|
||||
* Obtain a {@code ResponseBodyEmitter} for the given return value. If
|
||||
* the return is the body {@code ResponseEntity} then the given
|
||||
* Obtain a {@code ResponseBodyEmitter} for the given return value.
|
||||
* If the return is the body {@code ResponseEntity} then the given
|
||||
* {@code ServerHttpResponse} contains its status and headers.
|
||||
* @param returnValue the return value, never {@code null}
|
||||
* @param returnValue the return value (never {@code null})
|
||||
* @param response the response
|
||||
* @return the return value adapted to a {@code ResponseBodyEmitter}
|
||||
*/
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.servlet.mvc.method.annotation;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
@@ -33,17 +34,15 @@ import org.springframework.web.method.annotation.AbstractNamedValueMethodArgumen
|
||||
*/
|
||||
public class SessionAttributeMethodArgumentResolver extends AbstractNamedValueMethodArgumentResolver {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
return parameter.hasParameterAnnotation(SessionAttribute.class);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
|
||||
SessionAttribute annot = parameter.getParameterAnnotation(SessionAttribute.class);
|
||||
return new NamedValueInfo(annot.name(), annot.required(), ValueConstants.DEFAULT_NONE);
|
||||
SessionAttribute ann = parameter.getParameterAnnotation(SessionAttribute.class);
|
||||
return new NamedValueInfo(ann.name(), ann.required(), ValueConstants.DEFAULT_NONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -145,27 +145,6 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport {
|
||||
setSupportedMethods(supportedMethods);
|
||||
}
|
||||
|
||||
private void initAllowHeader() {
|
||||
Collection<String> allowedMethods;
|
||||
if (this.supportedMethods == null) {
|
||||
allowedMethods = new ArrayList<String>(HttpMethod.values().length - 1);
|
||||
for (HttpMethod method : HttpMethod.values()) {
|
||||
if (!HttpMethod.TRACE.equals(method)) {
|
||||
allowedMethods.add(method.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (this.supportedMethods.contains(HttpMethod.OPTIONS.name())) {
|
||||
allowedMethods = this.supportedMethods;
|
||||
}
|
||||
else {
|
||||
allowedMethods = new ArrayList<String>(this.supportedMethods);
|
||||
allowedMethods.add(HttpMethod.OPTIONS.name());
|
||||
|
||||
}
|
||||
this.allowHeader = StringUtils.collectionToCommaDelimitedString(allowedMethods);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the HTTP methods that this content generator should support.
|
||||
@@ -189,6 +168,27 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport {
|
||||
return StringUtils.toStringArray(this.supportedMethods);
|
||||
}
|
||||
|
||||
private void initAllowHeader() {
|
||||
Collection<String> allowedMethods;
|
||||
if (this.supportedMethods == null) {
|
||||
allowedMethods = new ArrayList<String>(HttpMethod.values().length - 1);
|
||||
for (HttpMethod method : HttpMethod.values()) {
|
||||
if (!HttpMethod.TRACE.equals(method)) {
|
||||
allowedMethods.add(method.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (this.supportedMethods.contains(HttpMethod.OPTIONS.name())) {
|
||||
allowedMethods = this.supportedMethods;
|
||||
}
|
||||
else {
|
||||
allowedMethods = new ArrayList<String>(this.supportedMethods);
|
||||
allowedMethods.add(HttpMethod.OPTIONS.name());
|
||||
|
||||
}
|
||||
this.allowHeader = StringUtils.collectionToCommaDelimitedString(allowedMethods);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the "Allow" header value to use in response to an HTTP OPTIONS
|
||||
* request based on the configured {@link #setSupportedMethods supported
|
||||
@@ -268,14 +268,15 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport {
|
||||
* @param varyByRequestHeaders one or more request header names
|
||||
* @since 4.3
|
||||
*/
|
||||
public void setVaryByRequestHeaders(String... varyByRequestHeaders) {
|
||||
public final void setVaryByRequestHeaders(String... varyByRequestHeaders) {
|
||||
this.varyByRequestHeaders = varyByRequestHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configured request header names for the "Vary" response header.
|
||||
* @since 4.3
|
||||
*/
|
||||
public String[] getVaryByRequestHeaders() {
|
||||
public final String[] getVaryByRequestHeaders() {
|
||||
return this.varyByRequestHeaders;
|
||||
}
|
||||
|
||||
@@ -593,6 +594,7 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Collection<String> getVaryRequestHeadersToAdd(HttpServletResponse response) {
|
||||
if (!response.containsHeader(HttpHeaders.VARY)) {
|
||||
return Arrays.asList(getVaryByRequestHeaders());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -255,21 +255,22 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure one or more hosts associated with the application. All other
|
||||
* hosts will be considered external hosts. In effect this property
|
||||
* provides a way turn off encoding via
|
||||
* {@link HttpServletResponse#encodeRedirectURL} for URLs that have a host
|
||||
* and that host is not listed as a known host.
|
||||
* Configure one or more hosts associated with the application.
|
||||
* All other hosts will be considered external hosts.
|
||||
* <p>In effect, this property provides a way turn off encoding via
|
||||
* {@link HttpServletResponse#encodeRedirectURL} for URLs that have a
|
||||
* host and that host is not listed as a known host.
|
||||
* <p>If not set (the default) all URLs are encoded through the response.
|
||||
* @param hosts one or more application hosts
|
||||
* @since 4.3
|
||||
*/
|
||||
public void setHosts(String[] hosts) {
|
||||
public void setHosts(String... hosts) {
|
||||
this.hosts = hosts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configured application hosts.
|
||||
* @since 4.3
|
||||
*/
|
||||
public String[] getHosts() {
|
||||
return this.hosts;
|
||||
|
||||
@@ -257,21 +257,22 @@ public class UrlBasedViewResolver extends AbstractCachingViewResolver implements
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure one or more hosts associated with the application. All other
|
||||
* hosts will be considered external hosts. In effect this property
|
||||
* provides a way turn off encoding on redirect via
|
||||
* {@link HttpServletResponse#encodeRedirectURL} for URLs that have a host
|
||||
* and that host is not listed as a known host.
|
||||
* Configure one or more hosts associated with the application.
|
||||
* All other hosts will be considered external hosts.
|
||||
* <p>In effect, this property provides a way turn off encoding on redirect
|
||||
* via {@link HttpServletResponse#encodeRedirectURL} for URLs that have a
|
||||
* host and that host is not listed as a known host.
|
||||
* <p>If not set (the default) all URLs are encoded through the response.
|
||||
* @param redirectHosts one or more application hosts
|
||||
* @since 4.3
|
||||
*/
|
||||
public void setRedirectHosts(String[] redirectHosts) {
|
||||
public void setRedirectHosts(String... redirectHosts) {
|
||||
this.redirectHosts = redirectHosts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configured application hosts for redirect purposes.
|
||||
* @since 4.3
|
||||
*/
|
||||
public String[] getRedirectHosts() {
|
||||
return this.redirectHosts;
|
||||
|
||||
Reference in New Issue
Block a user