Backport selected refinements from the nullability efforts
Issue: SPR-15656
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -68,7 +68,9 @@ abstract class MvcNamespaceUtils {
|
||||
* under that well-known name, unless already registered.
|
||||
* @return a RuntimeBeanReference to this {@link UrlPathHelper} instance
|
||||
*/
|
||||
public static RuntimeBeanReference registerUrlPathHelper(RuntimeBeanReference urlPathHelperRef, ParserContext parserContext, Object source) {
|
||||
public static RuntimeBeanReference registerUrlPathHelper(
|
||||
RuntimeBeanReference urlPathHelperRef, ParserContext parserContext, Object source) {
|
||||
|
||||
if (urlPathHelperRef != null) {
|
||||
if (parserContext.getRegistry().isAlias(URL_PATH_HELPER_BEAN_NAME)) {
|
||||
parserContext.getRegistry().removeAlias(URL_PATH_HELPER_BEAN_NAME);
|
||||
@@ -91,7 +93,9 @@ abstract class MvcNamespaceUtils {
|
||||
* under that well-known name, unless already registered.
|
||||
* @return a RuntimeBeanReference to this {@link PathMatcher} instance
|
||||
*/
|
||||
public static RuntimeBeanReference registerPathMatcher(RuntimeBeanReference pathMatcherRef, ParserContext parserContext, Object source) {
|
||||
public static RuntimeBeanReference registerPathMatcher(
|
||||
RuntimeBeanReference pathMatcherRef, ParserContext parserContext, Object source) {
|
||||
|
||||
if (pathMatcherRef != null) {
|
||||
if (parserContext.getRegistry().isAlias(PATH_MATCHER_BEAN_NAME)) {
|
||||
parserContext.getRegistry().removeAlias(PATH_MATCHER_BEAN_NAME);
|
||||
@@ -160,7 +164,9 @@ abstract class MvcNamespaceUtils {
|
||||
* if a non-null CORS configuration is provided.
|
||||
* @return a RuntimeBeanReference to this {@code Map<String, CorsConfiguration>} instance
|
||||
*/
|
||||
public static RuntimeBeanReference registerCorsConfigurations(Map<String, CorsConfiguration> corsConfigurations, ParserContext parserContext, Object source) {
|
||||
public static RuntimeBeanReference registerCorsConfigurations(
|
||||
Map<String, CorsConfiguration> corsConfigurations, ParserContext parserContext, Object source) {
|
||||
|
||||
if (!parserContext.getRegistry().containsBeanDefinition(CORS_CONFIGURATION_BEAN_NAME)) {
|
||||
RootBeanDefinition corsConfigurationsDef = new RootBeanDefinition(LinkedHashMap.class);
|
||||
corsConfigurationsDef.setSource(source);
|
||||
@@ -181,7 +187,7 @@ abstract class MvcNamespaceUtils {
|
||||
/**
|
||||
* Find the {@code ContentNegotiationManager} bean created by or registered
|
||||
* with the {@code annotation-driven} element.
|
||||
* @return a bean definition, bean reference, or null.
|
||||
* @return a bean definition, bean reference, or {@code null}
|
||||
*/
|
||||
public static Object getContentNegotiationManager(ParserContext context) {
|
||||
String name = AnnotationDrivenBeanDefinitionParser.HANDLER_MAPPING_BEAN_NAME;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -36,9 +36,9 @@ import org.springframework.web.servlet.view.RedirectView;
|
||||
* {@link org.springframework.beans.factory.xml.BeanDefinitionParser} that
|
||||
* parses the following MVC namespace elements:
|
||||
* <ul>
|
||||
* <li>{@code <view-controller>}
|
||||
* <li>{@code <redirect-view-controller>}
|
||||
* <li>{@code <status-controller>}
|
||||
* <li>{@code <view-controller>}
|
||||
* <li>{@code <redirect-view-controller>}
|
||||
* <li>{@code <status-controller>}
|
||||
* </ul>
|
||||
*
|
||||
* <p>All elements result in the registration of a
|
||||
@@ -55,7 +55,7 @@ import org.springframework.web.servlet.view.RedirectView;
|
||||
class ViewControllerBeanDefinitionParser implements BeanDefinitionParser {
|
||||
|
||||
private static final String HANDLER_MAPPING_BEAN_NAME =
|
||||
"org.springframework.web.servlet.config.viewControllerHandlerMapping";
|
||||
"org.springframework.web.servlet.config.viewControllerHandlerMapping";
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -130,19 +130,19 @@ public class ViewResolversBeanDefinitionParser implements BeanDefinitionParser {
|
||||
compositeResolverBeanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
|
||||
names = new String[] {"content-negotiation"};
|
||||
List<Element> contentnNegotiationElements = DomUtils.getChildElementsByTagName(element, names);
|
||||
if (contentnNegotiationElements.isEmpty()) {
|
||||
List<Element> contentNegotiationElements = DomUtils.getChildElementsByTagName(element, names);
|
||||
if (contentNegotiationElements.isEmpty()) {
|
||||
compositeResolverBeanDef.getPropertyValues().add("viewResolvers", resolvers);
|
||||
}
|
||||
else if (contentnNegotiationElements.size() == 1) {
|
||||
BeanDefinition beanDef = createContentNegotiatingViewResolver(contentnNegotiationElements.get(0), context);
|
||||
else if (contentNegotiationElements.size() == 1) {
|
||||
BeanDefinition beanDef = createContentNegotiatingViewResolver(contentNegotiationElements.get(0), context);
|
||||
beanDef.getPropertyValues().add("viewResolvers", resolvers);
|
||||
ManagedList<Object> list = new ManagedList<Object>(1);
|
||||
list.add(beanDef);
|
||||
compositeResolverBeanDef.getPropertyValues().add("order", Ordered.HIGHEST_PRECEDENCE);
|
||||
compositeResolverBeanDef.getPropertyValues().add("viewResolvers", list);
|
||||
}
|
||||
else if (contentnNegotiationElements.size() > 1) {
|
||||
else {
|
||||
throw new IllegalArgumentException("Only one <content-negotiation> element is allowed.");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -51,11 +51,9 @@ public class AsyncSupportConfigurer {
|
||||
* Set the default {@link AsyncTaskExecutor} to use when a controller method
|
||||
* returns a {@link Callable}. Controller methods can override this default on
|
||||
* a per-request basis by returning a {@link WebAsyncTask}.
|
||||
*
|
||||
* <p>By default a {@link SimpleAsyncTaskExecutor} instance is used, and it's
|
||||
* highly recommended to change that default in production since the simple
|
||||
* executor does not re-use threads.
|
||||
*
|
||||
* @param taskExecutor the task executor instance to use by default
|
||||
*/
|
||||
public AsyncSupportConfigurer setTaskExecutor(AsyncTaskExecutor taskExecutor) {
|
||||
@@ -70,7 +68,6 @@ public class AsyncSupportConfigurer {
|
||||
* for further processing of the concurrently produced result.
|
||||
* <p>If this value is not set, the default timeout of the underlying
|
||||
* implementation is used, e.g. 10 seconds on Tomcat with Servlet 3.
|
||||
*
|
||||
* @param timeout the timeout value in milliseconds
|
||||
*/
|
||||
public AsyncSupportConfigurer setDefaultTimeout(long timeout) {
|
||||
@@ -82,7 +79,6 @@ public class AsyncSupportConfigurer {
|
||||
* Configure lifecycle interceptors with callbacks around concurrent request
|
||||
* execution that starts when a controller returns a
|
||||
* {@link java.util.concurrent.Callable}.
|
||||
*
|
||||
* @param interceptors the interceptors to register
|
||||
*/
|
||||
public AsyncSupportConfigurer registerCallableInterceptors(CallableProcessingInterceptor... interceptors) {
|
||||
@@ -94,7 +90,6 @@ public class AsyncSupportConfigurer {
|
||||
/**
|
||||
* Configure lifecycle interceptors with callbacks around concurrent request
|
||||
* execution that starts when a controller returns a {@link DeferredResult}.
|
||||
*
|
||||
* @param interceptors the interceptors to register
|
||||
*/
|
||||
public AsyncSupportConfigurer registerDeferredResultInterceptors(DeferredResultProcessingInterceptor... interceptors) {
|
||||
@@ -103,6 +98,7 @@ public class AsyncSupportConfigurer {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
protected AsyncTaskExecutor getTaskExecutor() {
|
||||
return this.taskExecutor;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -30,40 +30,45 @@ import org.springframework.web.accept.PathExtensionContentNegotiationStrategy;
|
||||
|
||||
/**
|
||||
* Creates a {@code ContentNegotiationManager} and configures it with
|
||||
* one or more {@link ContentNegotiationStrategy} instances. The following shows
|
||||
* the resulting strategy instances, the methods used to configured them, and
|
||||
* whether enabled by default:
|
||||
* one or more {@link ContentNegotiationStrategy} instances.
|
||||
*
|
||||
* <p>As of 5.0 you can set the exact strategies to use via
|
||||
* {@link #strategies(List)}.
|
||||
*
|
||||
* <p>As an alternative you can also rely on the set of defaults described below
|
||||
* which can be turned on or off or customized through the methods of this
|
||||
* builder:
|
||||
*
|
||||
* <table>
|
||||
* <tr>
|
||||
* <th>Configurer Property</th>
|
||||
* <th>Underlying Strategy</th>
|
||||
* <th>Default Setting</th>
|
||||
* <th>Configurer Property</th>
|
||||
* <th>Underlying Strategy</th>
|
||||
* <th>Default Setting</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #favorPathExtension}</td>
|
||||
* <td>{@link PathExtensionContentNegotiationStrategy Path Extension strategy}</td>
|
||||
* <td>On</td>
|
||||
* <td>{@link #favorPathExtension}</td>
|
||||
* <td>{@link PathExtensionContentNegotiationStrategy Path Extension strategy}</td>
|
||||
* <td>On</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #favorParameter}</td>
|
||||
* <td>{@link ParameterContentNegotiationStrategy Parameter strategy}</td>
|
||||
* <td>Off</td>
|
||||
* <td>{@link #favorParameter}</td>
|
||||
* <td>{@link ParameterContentNegotiationStrategy Parameter strategy}</td>
|
||||
* <td>Off</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #ignoreAcceptHeader}</td>
|
||||
* <td>{@link HeaderContentNegotiationStrategy Header strategy}</td>
|
||||
* <td>On</td>
|
||||
* <td>{@link #ignoreAcceptHeader}</td>
|
||||
* <td>{@link HeaderContentNegotiationStrategy Header strategy}</td>
|
||||
* <td>On</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #defaultContentType}</td>
|
||||
* <td>{@link FixedContentNegotiationStrategy Fixed content strategy}</td>
|
||||
* <td>Not set</td>
|
||||
* <td>{@link #defaultContentType}</td>
|
||||
* <td>{@link FixedContentNegotiationStrategy Fixed content strategy}</td>
|
||||
* <td>Not set</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #defaultContentTypeStrategy}</td>
|
||||
* <td>{@link ContentNegotiationStrategy}</td>
|
||||
* <td>Not set</td>
|
||||
* <td>{@link #defaultContentTypeStrategy}</td>
|
||||
* <td>{@link ContentNegotiationStrategy}</td>
|
||||
* <td>Not set</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -28,15 +28,18 @@ import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
|
||||
import org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler;
|
||||
|
||||
/**
|
||||
* Configures a request handler for serving static resources by forwarding the request to the Servlet container's
|
||||
* "default" Servlet. This is intended to be used when the Spring MVC {@link DispatcherServlet} is mapped to "/"
|
||||
* thus overriding the Servlet container's default handling of static resources. Since this handler is configured
|
||||
* at the lowest precedence, effectively it allows all other handler mappings to handle the request, and if none
|
||||
* Configures a request handler for serving static resources by forwarding
|
||||
* the request to the Servlet container's "default" Servlet. This is intended
|
||||
* to be used when the Spring MVC {@link DispatcherServlet} is mapped to "/"
|
||||
* thus overriding the Servlet container's default handling of static resources.
|
||||
*
|
||||
* <p>Since this handler is configured at the lowest precedence, effectively
|
||||
* it allows all other handler mappings to handle the request, and if none
|
||||
* of them do, this handler can forward it to the "default" Servlet.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
*
|
||||
* @see DefaultServletHttpRequestHandler
|
||||
*/
|
||||
public class DefaultServletHandlerConfigurer {
|
||||
@@ -45,19 +48,22 @@ public class DefaultServletHandlerConfigurer {
|
||||
|
||||
private DefaultServletHttpRequestHandler handler;
|
||||
|
||||
|
||||
/**
|
||||
* Create a {@link DefaultServletHandlerConfigurer} instance.
|
||||
* @param servletContext the ServletContext to use to configure the underlying DefaultServletHttpRequestHandler.
|
||||
* @param servletContext the ServletContext to use.
|
||||
*/
|
||||
public DefaultServletHandlerConfigurer(ServletContext servletContext) {
|
||||
Assert.notNull(servletContext, "A ServletContext is required to configure default servlet handling");
|
||||
Assert.notNull(servletContext, "ServletContext is required");
|
||||
this.servletContext = servletContext;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enable forwarding to the "default" Servlet. When this method is used the {@link DefaultServletHttpRequestHandler}
|
||||
* will try to auto-detect the "default" Servlet name. Alternatively, you can specify the name of the default
|
||||
* Servlet via {@link #enable(String)}.
|
||||
* Enable forwarding to the "default" Servlet.
|
||||
* <p>When this method is used the {@link DefaultServletHttpRequestHandler}
|
||||
* will try to autodetect the "default" Servlet name. Alternatively, you can
|
||||
* specify the name of the default Servlet via {@link #enable(String)}.
|
||||
* @see DefaultServletHttpRequestHandler
|
||||
*/
|
||||
public void enable() {
|
||||
@@ -66,27 +72,28 @@ public class DefaultServletHandlerConfigurer {
|
||||
|
||||
/**
|
||||
* Enable forwarding to the "default" Servlet identified by the given name.
|
||||
* This is useful when the default Servlet cannot be auto-detected, for example when it has been manually configured.
|
||||
* <p>This is useful when the default Servlet cannot be autodetected,
|
||||
* for example when it has been manually configured.
|
||||
* @see DefaultServletHttpRequestHandler
|
||||
*/
|
||||
public void enable(String defaultServletName) {
|
||||
handler = new DefaultServletHttpRequestHandler();
|
||||
handler.setDefaultServletName(defaultServletName);
|
||||
handler.setServletContext(servletContext);
|
||||
this.handler = new DefaultServletHttpRequestHandler();
|
||||
this.handler.setDefaultServletName(defaultServletName);
|
||||
this.handler.setServletContext(this.servletContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a handler mapping instance ordered at {@link Integer#MAX_VALUE} containing the
|
||||
* {@link DefaultServletHttpRequestHandler} instance mapped to {@code "/**"}; or {@code null} if
|
||||
* default servlet handling was not been enabled.
|
||||
* {@link DefaultServletHttpRequestHandler} instance mapped to {@code "/**"};
|
||||
* or {@code null} if default servlet handling was not been enabled.
|
||||
*/
|
||||
protected AbstractHandlerMapping getHandlerMapping() {
|
||||
if (handler == null) {
|
||||
if (this.handler == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, HttpRequestHandler> urlMap = new HashMap<String, HttpRequestHandler>();
|
||||
urlMap.put("/**", handler);
|
||||
urlMap.put("/**", this.handler);
|
||||
|
||||
SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
|
||||
handlerMapping.setOrder(Integer.MAX_VALUE);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -28,13 +28,13 @@ import org.springframework.web.servlet.handler.WebRequestHandlerInterceptorAdapt
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Keith Donald
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
public class InterceptorRegistry {
|
||||
|
||||
private final List<InterceptorRegistration> registrations = new ArrayList<InterceptorRegistration>();
|
||||
|
||||
|
||||
/**
|
||||
* Adds the provided {@link HandlerInterceptor}.
|
||||
* @param interceptor the interceptor to add
|
||||
@@ -43,7 +43,7 @@ public class InterceptorRegistry {
|
||||
*/
|
||||
public InterceptorRegistration addInterceptor(HandlerInterceptor interceptor) {
|
||||
InterceptorRegistration registration = new InterceptorRegistration(interceptor);
|
||||
registrations.add(registration);
|
||||
this.registrations.add(registration);
|
||||
return registration;
|
||||
}
|
||||
|
||||
@@ -56,16 +56,16 @@ public class InterceptorRegistry {
|
||||
public InterceptorRegistration addWebRequestInterceptor(WebRequestInterceptor interceptor) {
|
||||
WebRequestHandlerInterceptorAdapter adapted = new WebRequestHandlerInterceptorAdapter(interceptor);
|
||||
InterceptorRegistration registration = new InterceptorRegistration(adapted);
|
||||
registrations.add(registration);
|
||||
this.registrations.add(registration);
|
||||
return registration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all registered interceptors.
|
||||
* Return all registered interceptors.
|
||||
*/
|
||||
protected List<Object> getInterceptors() {
|
||||
List<Object> interceptors = new ArrayList<Object>();
|
||||
for (InterceptorRegistration registration : registrations) {
|
||||
List<Object> interceptors = new ArrayList<Object>(this.registrations.size());
|
||||
for (InterceptorRegistration registration : this.registrations) {
|
||||
interceptors.add(registration.getInterceptor());
|
||||
}
|
||||
return interceptors ;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -98,7 +98,6 @@ public class ViewResolverRegistry {
|
||||
* media types requested by the client (e.g. in the Accept header).
|
||||
* <p>If invoked multiple times the provided default views will be added to
|
||||
* any other default views that may have been configured already.
|
||||
*
|
||||
* @see ContentNegotiatingViewResolver#setDefaultViews
|
||||
*/
|
||||
public void enableContentNegotiation(boolean useNotAcceptableStatus, View... defaultViews) {
|
||||
|
||||
@@ -26,8 +26,6 @@ import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||
import org.springframework.beans.factory.BeanInitializationException;
|
||||
@@ -369,7 +367,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
|
||||
try {
|
||||
this.contentNegotiationManager = configurer.getContentNegotiationManager();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new BeanInitializationException("Could not create ContentNegotiationManager", ex);
|
||||
}
|
||||
}
|
||||
@@ -765,16 +763,16 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
|
||||
}
|
||||
|
||||
if (jackson2XmlPresent) {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.xml().applicationContext(this.applicationContext).build();
|
||||
messageConverters.add(new MappingJackson2XmlHttpMessageConverter(objectMapper));
|
||||
messageConverters.add(new MappingJackson2XmlHttpMessageConverter(
|
||||
Jackson2ObjectMapperBuilder.xml().applicationContext(this.applicationContext).build()));
|
||||
}
|
||||
else if (jaxb2Present) {
|
||||
messageConverters.add(new Jaxb2RootElementHttpMessageConverter());
|
||||
}
|
||||
|
||||
if (jackson2Present) {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().applicationContext(this.applicationContext).build();
|
||||
messageConverters.add(new MappingJackson2HttpMessageConverter(objectMapper));
|
||||
messageConverters.add(new MappingJackson2HttpMessageConverter(
|
||||
Jackson2ObjectMapperBuilder.json().applicationContext(this.applicationContext).build()));
|
||||
}
|
||||
else if (gsonPresent) {
|
||||
messageConverters.add(new GsonHttpMessageConverter());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -78,9 +78,9 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
|
||||
private final List<HandlerInterceptor> adaptedInterceptors = new ArrayList<HandlerInterceptor>();
|
||||
|
||||
private CorsProcessor corsProcessor = new DefaultCorsProcessor();
|
||||
private final UrlBasedCorsConfigurationSource globalCorsConfigSource = new UrlBasedCorsConfigurationSource();
|
||||
|
||||
private final UrlBasedCorsConfigurationSource corsConfigSource = new UrlBasedCorsConfigurationSource();
|
||||
private CorsProcessor corsProcessor = new DefaultCorsProcessor();
|
||||
|
||||
|
||||
/**
|
||||
@@ -123,7 +123,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
*/
|
||||
public void setAlwaysUseFullPath(boolean alwaysUseFullPath) {
|
||||
this.urlPathHelper.setAlwaysUseFullPath(alwaysUseFullPath);
|
||||
this.corsConfigSource.setAlwaysUseFullPath(alwaysUseFullPath);
|
||||
this.globalCorsConfigSource.setAlwaysUseFullPath(alwaysUseFullPath);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,7 +135,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
*/
|
||||
public void setUrlDecode(boolean urlDecode) {
|
||||
this.urlPathHelper.setUrlDecode(urlDecode);
|
||||
this.corsConfigSource.setUrlDecode(urlDecode);
|
||||
this.globalCorsConfigSource.setUrlDecode(urlDecode);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,7 +145,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
*/
|
||||
public void setRemoveSemicolonContent(boolean removeSemicolonContent) {
|
||||
this.urlPathHelper.setRemoveSemicolonContent(removeSemicolonContent);
|
||||
this.corsConfigSource.setRemoveSemicolonContent(removeSemicolonContent);
|
||||
this.globalCorsConfigSource.setRemoveSemicolonContent(removeSemicolonContent);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,7 +157,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
public void setUrlPathHelper(UrlPathHelper urlPathHelper) {
|
||||
Assert.notNull(urlPathHelper, "UrlPathHelper must not be null");
|
||||
this.urlPathHelper = urlPathHelper;
|
||||
this.corsConfigSource.setUrlPathHelper(urlPathHelper);
|
||||
this.globalCorsConfigSource.setUrlPathHelper(urlPathHelper);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,7 +175,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
public void setPathMatcher(PathMatcher pathMatcher) {
|
||||
Assert.notNull(pathMatcher, "PathMatcher must not be null");
|
||||
this.pathMatcher = pathMatcher;
|
||||
this.corsConfigSource.setPathMatcher(pathMatcher);
|
||||
this.globalCorsConfigSource.setPathMatcher(pathMatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,7 +191,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
* <p>Supported interceptor types are HandlerInterceptor, WebRequestInterceptor, and MappedInterceptor.
|
||||
* Mapped interceptors apply only to request URLs that match its path patterns.
|
||||
* Mapped interceptor beans are also detected by type during initialization.
|
||||
* @param interceptors array of handler interceptors, or {@code null} if none
|
||||
* @param interceptors array of handler interceptors
|
||||
* @see #adaptInterceptor
|
||||
* @see org.springframework.web.servlet.HandlerInterceptor
|
||||
* @see org.springframework.web.context.request.WebRequestInterceptor
|
||||
@@ -200,6 +200,23 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
this.interceptors.addAll(Arrays.asList(interceptors));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set "global" CORS configuration based on URL patterns. By default the first
|
||||
* matching URL pattern is combined with the CORS configuration for the
|
||||
* handler, if any.
|
||||
* @since 4.2
|
||||
*/
|
||||
public void setCorsConfigurations(Map<String, CorsConfiguration> corsConfigurations) {
|
||||
this.globalCorsConfigSource.setCorsConfigurations(corsConfigurations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the "global" CORS configuration.
|
||||
*/
|
||||
public Map<String, CorsConfiguration> getCorsConfigurations() {
|
||||
return this.globalCorsConfigSource.getCorsConfigurations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure a custom {@link CorsProcessor} to use to apply the matched
|
||||
* {@link CorsConfiguration} for a request.
|
||||
@@ -218,23 +235,6 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
return this.corsProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set "global" CORS configuration based on URL patterns. By default the first
|
||||
* matching URL pattern is combined with the CORS configuration for the
|
||||
* handler, if any.
|
||||
* @since 4.2
|
||||
*/
|
||||
public void setCorsConfigurations(Map<String, CorsConfiguration> corsConfigurations) {
|
||||
this.corsConfigSource.setCorsConfigurations(corsConfigurations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the CORS configuration.
|
||||
*/
|
||||
public Map<String, CorsConfiguration> getCorsConfigurations() {
|
||||
return this.corsConfigSource.getCorsConfigurations();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the interceptors.
|
||||
@@ -364,7 +364,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
|
||||
HandlerExecutionChain executionChain = getHandlerExecutionChain(handler, request);
|
||||
if (CorsUtils.isCorsRequest(request)) {
|
||||
CorsConfiguration globalConfig = this.corsConfigSource.getCorsConfiguration(request);
|
||||
CorsConfiguration globalConfig = this.globalCorsConfigSource.getCorsConfiguration(request);
|
||||
CorsConfiguration handlerConfig = getCorsConfiguration(handler, request);
|
||||
CorsConfiguration config = (globalConfig != null ? globalConfig.combine(handlerConfig) : handlerConfig);
|
||||
executionChain = getCorsHandlerExecutionChain(request, executionChain, config);
|
||||
@@ -433,15 +433,16 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
* Retrieve the CORS configuration for the given handler.
|
||||
* @param handler the handler to check (never {@code null}).
|
||||
* @param request the current request.
|
||||
* @return the CORS configuration for the handler or {@code null}.
|
||||
* @return the CORS configuration for the handler, or {@code null} if none
|
||||
* @since 4.2
|
||||
*/
|
||||
protected CorsConfiguration getCorsConfiguration(Object handler, HttpServletRequest request) {
|
||||
Object resolvedHandler = handler;
|
||||
if (handler instanceof HandlerExecutionChain) {
|
||||
handler = ((HandlerExecutionChain) handler).getHandler();
|
||||
resolvedHandler = ((HandlerExecutionChain) handler).getHandler();
|
||||
}
|
||||
if (handler instanceof CorsConfigurationSource) {
|
||||
return ((CorsConfigurationSource) handler).getCorsConfiguration(request);
|
||||
if (resolvedHandler instanceof CorsConfigurationSource) {
|
||||
return ((CorsConfigurationSource) resolvedHandler).getCorsConfiguration(request);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -455,7 +456,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||
* HandlerInterceptor that makes CORS-related checks and adds CORS headers.
|
||||
* @param request the current request
|
||||
* @param chain the handler chain
|
||||
* @param config the applicable CORS configuration, possibly {@code null}
|
||||
* @param config the applicable CORS configuration (possibly {@code null})
|
||||
* @since 4.2
|
||||
*/
|
||||
protected HandlerExecutionChain getCorsHandlerExecutionChain(HttpServletRequest request,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -37,14 +37,6 @@ public class HandlerExceptionResolverComposite implements HandlerExceptionResolv
|
||||
|
||||
private int order = Ordered.LOWEST_PRECEDENCE;
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of exception resolvers to delegate to.
|
||||
@@ -57,20 +49,30 @@ public class HandlerExceptionResolverComposite implements HandlerExceptionResolv
|
||||
* Return the list of exception resolvers to delegate to.
|
||||
*/
|
||||
public List<HandlerExceptionResolver> getExceptionResolvers() {
|
||||
return Collections.unmodifiableList(resolvers);
|
||||
return (this.resolvers != null ? Collections.unmodifiableList(this.resolvers) :
|
||||
Collections.<HandlerExceptionResolver>emptyList());
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resolve the exception by iterating over the list of configured exception resolvers.
|
||||
* The first one to return a ModelAndView instance wins. Otherwise {@code null} is returned.
|
||||
*/
|
||||
@Override
|
||||
public ModelAndView resolveException(HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
Object handler,
|
||||
Exception ex) {
|
||||
if (resolvers != null) {
|
||||
for (HandlerExceptionResolver handlerExceptionResolver : resolvers) {
|
||||
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler,Exception ex) {
|
||||
|
||||
if (this.resolvers != null) {
|
||||
for (HandlerExceptionResolver handlerExceptionResolver : this.resolvers) {
|
||||
ModelAndView mav = handlerExceptionResolver.resolveException(request, response, handler, ex);
|
||||
if (mav != null) {
|
||||
return mav;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -35,20 +35,22 @@ abstract class AbstractNameValueExpression<T> implements NameValueExpression<T>
|
||||
|
||||
protected final boolean isNegated;
|
||||
|
||||
|
||||
AbstractNameValueExpression(String expression) {
|
||||
int separator = expression.indexOf('=');
|
||||
if (separator == -1) {
|
||||
this.isNegated = expression.startsWith("!");
|
||||
this.name = isNegated ? expression.substring(1) : expression;
|
||||
this.name = (this.isNegated ? expression.substring(1) : expression);
|
||||
this.value = null;
|
||||
}
|
||||
else {
|
||||
this.isNegated = (separator > 0) && (expression.charAt(separator - 1) == '!');
|
||||
this.name = isNegated ? expression.substring(0, separator - 1) : expression.substring(0, separator);
|
||||
this.name = (this.isNegated ? expression.substring(0, separator - 1) : expression.substring(0, separator));
|
||||
this.value = parseValue(expression.substring(separator + 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
@@ -64,10 +66,6 @@ abstract class AbstractNameValueExpression<T> implements NameValueExpression<T>
|
||||
return this.isNegated;
|
||||
}
|
||||
|
||||
protected abstract boolean isCaseSensitiveName();
|
||||
|
||||
protected abstract T parseValue(String valueExpression);
|
||||
|
||||
public final boolean match(HttpServletRequest request) {
|
||||
boolean isMatch;
|
||||
if (this.value != null) {
|
||||
@@ -76,23 +74,29 @@ abstract class AbstractNameValueExpression<T> implements NameValueExpression<T>
|
||||
else {
|
||||
isMatch = matchName(request);
|
||||
}
|
||||
return isNegated ? !isMatch : isMatch;
|
||||
return (this.isNegated ? !isMatch : isMatch);
|
||||
}
|
||||
|
||||
|
||||
protected abstract boolean isCaseSensitiveName();
|
||||
|
||||
protected abstract T parseValue(String valueExpression);
|
||||
|
||||
protected abstract boolean matchName(HttpServletRequest request);
|
||||
|
||||
protected abstract boolean matchValue(HttpServletRequest request);
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj != null && obj instanceof AbstractNameValueExpression) {
|
||||
if (obj instanceof AbstractNameValueExpression) {
|
||||
AbstractNameValueExpression<?> other = (AbstractNameValueExpression<?>) obj;
|
||||
String thisName = isCaseSensitiveName() ? this.name : this.name.toLowerCase();
|
||||
String otherName = isCaseSensitiveName() ? other.name : other.name.toLowerCase();
|
||||
return ((thisName.equalsIgnoreCase(otherName)) &&
|
||||
String thisName = (isCaseSensitiveName() ? this.name : this.name.toLowerCase());
|
||||
String otherName = (isCaseSensitiveName() ? other.name : other.name.toLowerCase());
|
||||
return (thisName.equalsIgnoreCase(otherName) &&
|
||||
(this.value != null ? this.value.equals(other.value) : other.value == null) &&
|
||||
this.isNegated == other.isNegated);
|
||||
}
|
||||
@@ -101,29 +105,30 @@ abstract class AbstractNameValueExpression<T> implements NameValueExpression<T>
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = isCaseSensitiveName() ? name.hashCode() : name.toLowerCase().hashCode();
|
||||
result = 31 * result + (value != null ? value.hashCode() : 0);
|
||||
result = 31 * result + (isNegated ? 1 : 0);
|
||||
int result = (isCaseSensitiveName() ? this.name.hashCode() : this.name.toLowerCase().hashCode());
|
||||
result = 31 * result + (this.value != null ? this.value.hashCode() : 0);
|
||||
result = 31 * result + (this.isNegated ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if (value != null) {
|
||||
builder.append(name);
|
||||
if (isNegated) {
|
||||
if (this.value != null) {
|
||||
builder.append(this.name);
|
||||
if (this.isNegated) {
|
||||
builder.append('!');
|
||||
}
|
||||
builder.append('=');
|
||||
builder.append(value);
|
||||
builder.append(this.value);
|
||||
}
|
||||
else {
|
||||
if (isNegated) {
|
||||
if (this.isNegated) {
|
||||
builder.append('!');
|
||||
}
|
||||
builder.append(name);
|
||||
builder.append(this.name);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -22,6 +22,7 @@ import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.cors.CorsUtils;
|
||||
|
||||
@@ -158,12 +159,12 @@ public final class HeadersRequestCondition extends AbstractRequestCondition<Head
|
||||
|
||||
@Override
|
||||
protected boolean matchName(HttpServletRequest request) {
|
||||
return request.getHeader(name) != null;
|
||||
return (request.getHeader(this.name) != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean matchValue(HttpServletRequest request) {
|
||||
return value.equals(request.getHeader(name));
|
||||
return ObjectUtils.nullSafeEquals(this.value, request.getHeader(this.name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -24,7 +24,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.1
|
||||
*
|
||||
* @see RequestMapping#params()
|
||||
* @see RequestMapping#headers()
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -22,6 +22,7 @@ import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.util.WebUtils;
|
||||
|
||||
@@ -143,12 +144,12 @@ public final class ParamsRequestCondition extends AbstractRequestCondition<Param
|
||||
|
||||
@Override
|
||||
protected boolean matchName(HttpServletRequest request) {
|
||||
return WebUtils.hasSubmitParameter(request, name);
|
||||
return WebUtils.hasSubmitParameter(request, this.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean matchValue(HttpServletRequest request) {
|
||||
return value.equals(request.getParameter(name));
|
||||
return ObjectUtils.nullSafeEquals(this.value, request.getParameter(this.name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -194,7 +194,7 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
||||
return this.name;
|
||||
}
|
||||
else {
|
||||
return (other.name != null ? other.name : null);
|
||||
return other.name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -616,7 +616,7 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
||||
* from the configured {@code contentNegotiationManager}.
|
||||
*/
|
||||
public List<String> getFileExtensions() {
|
||||
if (useRegisteredSuffixPatternMatch() && getContentNegotiationManager() != null) {
|
||||
if (useRegisteredSuffixPatternMatch() && this.contentNegotiationManager != null) {
|
||||
return this.contentNegotiationManager.getAllFileExtensions();
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -46,14 +46,14 @@ public class HttpHeadersReturnValueHandler implements HandlerMethodReturnValueHa
|
||||
|
||||
mavContainer.setRequestHandled(true);
|
||||
|
||||
Assert.isInstanceOf(HttpHeaders.class, returnValue, "HttpHeaders expected");
|
||||
Assert.state(returnValue instanceof HttpHeaders, "HttpHeaders expected");
|
||||
HttpHeaders headers = (HttpHeaders) returnValue;
|
||||
|
||||
if (!headers.isEmpty()) {
|
||||
HttpServletResponse servletResponse = webRequest.getNativeResponse(HttpServletResponse.class);
|
||||
ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(servletResponse);
|
||||
outputMessage.getHeaders().putAll(headers);
|
||||
outputMessage.getBody(); // flush headers
|
||||
outputMessage.getBody(); // flush headers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -218,7 +218,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
|
||||
* not initialized yet via {@link #afterPropertiesSet()}.
|
||||
*/
|
||||
public List<HandlerMethodArgumentResolver> getArgumentResolvers() {
|
||||
return (this.argumentResolvers != null) ? this.argumentResolvers.getResolvers() : null;
|
||||
return (this.argumentResolvers != null ? this.argumentResolvers.getResolvers() : null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,7 +239,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
|
||||
* {@code null} if not initialized yet via {@link #afterPropertiesSet()}.
|
||||
*/
|
||||
public List<HandlerMethodArgumentResolver> getInitBinderArgumentResolvers() {
|
||||
return (this.initBinderArgumentResolvers != null) ? this.initBinderArgumentResolvers.getResolvers() : null;
|
||||
return (this.initBinderArgumentResolvers != null ? this.initBinderArgumentResolvers.getResolvers() : null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,7 +277,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
|
||||
* initialized yet via {@link #afterPropertiesSet()}.
|
||||
*/
|
||||
public List<HandlerMethodReturnValueHandler> getReturnValueHandlers() {
|
||||
return this.returnValueHandlers.getHandlers();
|
||||
return (this.returnValueHandlers != null ? this.returnValueHandlers.getHandlers() : null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -302,7 +302,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
|
||||
* Return the configured {@link ModelAndViewResolver}s, or {@code null}.
|
||||
*/
|
||||
public List<ModelAndViewResolver> getModelAndViewResolvers() {
|
||||
return modelAndViewResolvers;
|
||||
return this.modelAndViewResolvers;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -31,7 +31,6 @@ import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.method.ControllerAdviceBean;
|
||||
|
||||
|
||||
/**
|
||||
* Invokes {@link RequestBodyAdvice} and {@link ResponseBodyAdvice} where each
|
||||
* instance may be (and is most likely) wrapped with
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -38,7 +38,6 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
*/
|
||||
public class UriComponentsBuilderMethodArgumentResolver implements HandlerMethodArgumentResolver {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
Class<?> type = parameter.getParameterType();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -38,13 +38,6 @@ public class RedirectAttributesModelMap extends ModelMap implements RedirectAttr
|
||||
|
||||
private final ModelMap flashAttributes = new ModelMap();
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
* @param dataBinder used to format attribute values as Strings.
|
||||
*/
|
||||
public RedirectAttributesModelMap(DataBinder dataBinder) {
|
||||
this.dataBinder = dataBinder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor without a DataBinder.
|
||||
@@ -54,6 +47,15 @@ public class RedirectAttributesModelMap extends ModelMap implements RedirectAttr
|
||||
this(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with a DataBinder.
|
||||
* @param dataBinder used to format attribute values as Strings
|
||||
*/
|
||||
public RedirectAttributesModelMap(DataBinder dataBinder) {
|
||||
this.dataBinder = dataBinder;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the attributes candidate for flash storage or an empty Map.
|
||||
*/
|
||||
@@ -76,7 +78,7 @@ public class RedirectAttributesModelMap extends ModelMap implements RedirectAttr
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return (dataBinder != null) ? dataBinder.convertIfNecessary(value, String.class) : value.toString();
|
||||
return (this.dataBinder != null ? this.dataBinder.convertIfNecessary(value, String.class) : value.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -46,7 +46,7 @@ public class GzipResourceResolver extends AbstractResourceResolver {
|
||||
List<? extends Resource> locations, ResourceResolverChain chain) {
|
||||
|
||||
Resource resource = chain.resolveResource(request, requestPath, locations);
|
||||
if ((resource == null) || (request != null && !isGzipAccepted(request))) {
|
||||
if (resource == null || (request != null && !isGzipAccepted(request))) {
|
||||
return resource;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -53,7 +53,7 @@ public abstract class ResourceTransformerSupport implements ResourceTransformer
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the configured {@code ResourceUrlProvider}.
|
||||
* Return the configured {@code ResourceUrlProvider}.
|
||||
*/
|
||||
public ResourceUrlProvider getResourceUrlProvider() {
|
||||
return this.resourceUrlProvider;
|
||||
@@ -69,7 +69,7 @@ public abstract class ResourceTransformerSupport implements ResourceTransformer
|
||||
* @param request the current request
|
||||
* @param resource the resource being transformed
|
||||
* @param transformerChain the transformer chain
|
||||
* @return the resolved URL or null
|
||||
* @return the resolved URL, or {@code} if not resolvable
|
||||
*/
|
||||
protected String resolveUrlPath(String resourcePath, HttpServletRequest request,
|
||||
Resource resource, ResourceTransformerChain transformerChain) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -20,7 +20,6 @@ import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@@ -35,7 +34,6 @@ import org.springframework.web.servlet.FlashMap;
|
||||
import org.springframework.web.servlet.FlashMapManager;
|
||||
import org.springframework.web.util.UrlPathHelper;
|
||||
|
||||
|
||||
/**
|
||||
* A base class for {@link FlashMapManager} implementations.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -79,7 +79,7 @@ public class EscapeBodyTag extends HtmlEscapingAwareTag implements BodyTag {
|
||||
String content = readBodyContent();
|
||||
// HTML and/or JavaScript escape, if demanded
|
||||
content = htmlEscape(content);
|
||||
content = this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(content) : content;
|
||||
content = (this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(content) : content);
|
||||
writeBodyContent(content);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -227,8 +227,7 @@ public class MessageTag extends HtmlEscapingAwareTag implements ArgumentAware {
|
||||
// We have a code or default text that we need to resolve.
|
||||
Object[] argumentsArray = resolveArguments(this.arguments);
|
||||
if (!this.nestedArguments.isEmpty()) {
|
||||
argumentsArray = appendArguments(argumentsArray,
|
||||
this.nestedArguments.toArray());
|
||||
argumentsArray = appendArguments(argumentsArray, this.nestedArguments.toArray());
|
||||
}
|
||||
|
||||
if (this.text != null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -33,37 +33,39 @@ public class Param {
|
||||
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* @return the raw parameter name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the raw name of the parameter
|
||||
* Set the raw name of the parameter.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the raw parameter value
|
||||
* Return the raw parameter name.
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the raw value of the parameter
|
||||
* Set the raw value of the parameter.
|
||||
*/
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the raw parameter value
|
||||
*/
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JSP Tag Param: name '" + name + "', value '" + value + "'";
|
||||
return "JSP Tag Param: name '" + this.name + "', value '" + this.value + "'";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -196,11 +196,11 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware {
|
||||
/**
|
||||
* Build the URL for the tag from the tag attributes and parameters.
|
||||
* @return the URL value as a String
|
||||
* @throws JspException
|
||||
*/
|
||||
private String createUrl() throws JspException {
|
||||
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
|
||||
HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
|
||||
|
||||
StringBuilder url = new StringBuilder();
|
||||
if (this.type == UrlType.CONTEXT_RELATIVE) {
|
||||
// add application context to url
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -57,7 +57,7 @@ public class ButtonTag extends AbstractHtmlElementTag {
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -92,9 +92,7 @@ public abstract class AbstractUrlBasedView extends AbstractView implements Initi
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(super.toString());
|
||||
sb.append("; URL [").append(getUrl()).append("]");
|
||||
return sb.toString();
|
||||
return super.toString() + "; URL [" + getUrl() + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -66,8 +66,6 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
|
||||
private static final int OUTPUT_BYTE_ARRAY_INITIAL_SIZE = 4096;
|
||||
|
||||
|
||||
private String beanName;
|
||||
|
||||
private String contentType = DEFAULT_CONTENT_TYPE;
|
||||
|
||||
private String requestContextAttribute;
|
||||
@@ -80,23 +78,8 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
|
||||
|
||||
private Set<String> exposedContextBeanNames;
|
||||
|
||||
private String beanName;
|
||||
|
||||
/**
|
||||
* Set the view's name. Helpful for traceability.
|
||||
* <p>Framework code must call this when constructing views.
|
||||
*/
|
||||
@Override
|
||||
public void setBeanName(String beanName) {
|
||||
this.beanName = beanName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the view's name. Should never be {@code null},
|
||||
* if the view was correctly configured.
|
||||
*/
|
||||
public String getBeanName() {
|
||||
return this.beanName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content type for this view.
|
||||
@@ -284,6 +267,23 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
|
||||
this.exposedContextBeanNames = new HashSet<String>(Arrays.asList(exposedContextBeanNames));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the view's name. Helpful for traceability.
|
||||
* <p>Framework code must call this when constructing views.
|
||||
*/
|
||||
@Override
|
||||
public void setBeanName(String beanName) {
|
||||
this.beanName = beanName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the view's name. Should never be {@code null},
|
||||
* if the view was correctly configured.
|
||||
*/
|
||||
public String getBeanName() {
|
||||
return this.beanName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepares the view given the specified model, merging it with static
|
||||
|
||||
@@ -87,8 +87,6 @@ import org.springframework.web.servlet.ViewResolver;
|
||||
public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport
|
||||
implements ViewResolver, Ordered, InitializingBean {
|
||||
|
||||
private int order = Ordered.HIGHEST_PRECEDENCE;
|
||||
|
||||
private ContentNegotiationManager contentNegotiationManager;
|
||||
|
||||
private final ContentNegotiationManagerFactoryBean cnmFactoryBean = new ContentNegotiationManagerFactoryBean();
|
||||
@@ -99,15 +97,8 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport
|
||||
|
||||
private List<ViewResolver> viewResolvers;
|
||||
|
||||
private int order = Ordered.HIGHEST_PRECEDENCE;
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link ContentNegotiationManager} to use to determine requested media types.
|
||||
@@ -171,6 +162,15 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport
|
||||
return Collections.unmodifiableList(this.viewResolvers);
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void initServletContext(ServletContext servletContext) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -33,7 +33,7 @@ import freemarker.template.Configuration;
|
||||
public interface FreeMarkerConfig {
|
||||
|
||||
/**
|
||||
* Return the FreeMarker Configuration object for the current
|
||||
* Return the FreeMarker {@link Configuration} object for the current
|
||||
* web application context.
|
||||
* <p>A FreeMarker Configuration object may be used to set FreeMarker
|
||||
* properties and shared objects, and allows to retrieve templates.
|
||||
@@ -42,7 +42,7 @@ public interface FreeMarkerConfig {
|
||||
Configuration getConfiguration();
|
||||
|
||||
/**
|
||||
* Returns the {@link TaglibFactory} used to enable JSP tags to be
|
||||
* Return the {@link TaglibFactory} used to enable JSP tags to be
|
||||
* accessed from FreeMarker templates.
|
||||
*/
|
||||
TaglibFactory getTaglibFactory();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -199,24 +199,25 @@ public class FreeMarkerView extends AbstractTemplateView {
|
||||
*/
|
||||
@Override
|
||||
public boolean checkResource(Locale locale) throws Exception {
|
||||
String url = getUrl();
|
||||
try {
|
||||
// Check that we can get the template, even if we might subsequently get it again.
|
||||
getTemplate(getUrl(), locale);
|
||||
getTemplate(url, locale);
|
||||
return true;
|
||||
}
|
||||
catch (FileNotFoundException ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("No FreeMarker view found for URL: " + getUrl());
|
||||
logger.debug("No FreeMarker view found for URL: " + url);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (ParseException ex) {
|
||||
throw new ApplicationContextException(
|
||||
"Failed to parse FreeMarker template for URL [" + getUrl() + "]", ex);
|
||||
"Failed to parse FreeMarker template for URL [" + url + "]", ex);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new ApplicationContextException(
|
||||
"Could not load FreeMarker template for URL [" + getUrl() + "]", ex);
|
||||
"Could not load FreeMarker template for URL [" + url + "]", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -118,7 +118,7 @@ public class GroovyMarkupConfigurer extends TemplateConfiguration
|
||||
}
|
||||
|
||||
public MarkupTemplateEngine getTemplateEngine() {
|
||||
return templateEngine;
|
||||
return this.templateEngine;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -55,7 +55,7 @@ import org.springframework.web.servlet.view.AbstractUrlBasedView;
|
||||
* {@link ScriptTemplateConfig} bean in the web application context and using
|
||||
* it to obtain the configured properties.
|
||||
*
|
||||
* <p>Nashorn Javascript engine requires Java 8+, and may require setting the
|
||||
* <p>The Nashorn JavaScript engine requires Java 8+ and may require setting the
|
||||
* {@code sharedEngine} property to {@code false} in order to run properly. See
|
||||
* {@link ScriptTemplateConfigurer#setSharedEngine(Boolean)} for more details.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user