From f36070b5607389c630b67fada12efc3073f59f8b Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 2 Jun 2016 17:02:44 +0200 Subject: [PATCH] Polishing (cherry picked from commit 521c41d) --- .../init/CompositeDatabasePopulator.java | 12 +++--- ...ractMappingContentNegotiationStrategy.java | 7 ++-- .../web/accept/ContentNegotiationManager.java | 14 +++---- .../ContentNegotiationManagerFactoryBean.java | 38 +++++++++---------- .../accept/ContentNegotiationStrategy.java | 6 +-- .../FixedContentNegotiationStrategy.java | 5 +-- .../HeaderContentNegotiationStrategy.java | 6 +-- ...MappingMediaTypeFileExtensionResolver.java | 4 +- .../MediaTypeFileExtensionResolver.java | 7 ++-- .../ParameterContentNegotiationStrategy.java | 22 +++++------ ...thExtensionContentNegotiationStrategy.java | 5 +-- ...thExtensionContentNegotiationStrategy.java | 14 +++---- .../support/WebApplicationContextUtils.java | 4 +- .../filter/AbstractRequestLoggingFilter.java | 7 +++- .../PortletApplicationContextUtils.java | 4 +- 15 files changed, 71 insertions(+), 84 deletions(-) diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/CompositeDatabasePopulator.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/CompositeDatabasePopulator.java index 1b74ac0001..b8924624fb 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/CompositeDatabasePopulator.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/CompositeDatabasePopulator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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. @@ -23,7 +23,7 @@ import java.util.Arrays; import java.util.List; /** - * {@link DatabasePopulator} implementation that delegates to a list of other + * Composite {@link DatabasePopulator} that delegates to a list of given * {@code DatabasePopulator} implementations, executing all scripts. * * @author Dave Syer @@ -33,11 +33,11 @@ import java.util.List; */ public class CompositeDatabasePopulator implements DatabasePopulator { - private List populators = new ArrayList(); + private final List populators = new ArrayList(4); /** - * Specify a list of populators to delegate to. + * Specify one or more populators to delegate to. */ public void setPopulators(DatabasePopulator... populators) { this.populators.clear(); @@ -51,9 +51,7 @@ public class CompositeDatabasePopulator implements DatabasePopulator { this.populators.addAll(Arrays.asList(populators)); } - /** - * {@inheritDoc} - */ + @Override public void populate(Connection connection) throws SQLException, ScriptException { for (DatabasePopulator populator : this.populators) { diff --git a/spring-web/src/main/java/org/springframework/web/accept/AbstractMappingContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/AbstractMappingContentNegotiationStrategy.java index 0568b90465..ee83d31f77 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/AbstractMappingContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/AbstractMappingContentNegotiationStrategy.java @@ -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. @@ -43,11 +43,9 @@ import org.springframework.web.context.request.NativeWebRequest; * @author Rossen Stoyanchev * @since 3.2 */ -public abstract class AbstractMappingContentNegotiationStrategy - extends MappingMediaTypeFileExtensionResolver +public abstract class AbstractMappingContentNegotiationStrategy extends MappingMediaTypeFileExtensionResolver implements ContentNegotiationStrategy { - /** * Create an instance with the given map of file extensions and media types. */ @@ -86,6 +84,7 @@ public abstract class AbstractMappingContentNegotiationStrategy return Collections.emptyList(); } + /** * Extract a key from the request to use to look up media types. * @return the lookup key or {@code null}. diff --git a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManager.java b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManager.java index 4450ad1064..3f6efab393 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManager.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManager.java @@ -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. @@ -41,18 +41,14 @@ import org.springframework.web.context.request.NativeWebRequest; * @author Rossen Stoyanchev * @since 3.2 */ -public class ContentNegotiationManager implements ContentNegotiationStrategy, - MediaTypeFileExtensionResolver { +public class ContentNegotiationManager implements ContentNegotiationStrategy, MediaTypeFileExtensionResolver { - private static final List MEDIA_TYPE_ALL = - Collections.singletonList(MediaType.ALL); + private static final List MEDIA_TYPE_ALL = Collections.singletonList(MediaType.ALL); - private final List strategies = - new ArrayList(); + private final List strategies = new ArrayList(); - private final Set resolvers = - new LinkedHashSet(); + private final Set resolvers = new LinkedHashSet(); /** diff --git a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java index b035b079ac..dfcd84990e 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java @@ -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. @@ -40,34 +40,34 @@ import org.springframework.web.context.ServletContextAware; * * * - * - * - * + * + * + * * * - * - * - * + * + * + * * * - * - * - * + * + * + * * * - * - * - * + * + * + * * * - * - * - * + * + * + * * * - * - * - * + * + * + * * *
Property SetterUnderlying StrategyDefault SettingProperty SetterUnderlying StrategyDefault Setting
{@link #setFavorPathExtension}{@link PathExtensionContentNegotiationStrategy Path Extension strategy}On{@link #setFavorPathExtension}{@link PathExtensionContentNegotiationStrategy Path Extension strategy}On
{@link #setFavorParameter favorParameter}{@link ParameterContentNegotiationStrategy Parameter strategy}Off{@link #setFavorParameter favorParameter}{@link ParameterContentNegotiationStrategy Parameter strategy}Off
{@link #setIgnoreAcceptHeader ignoreAcceptHeader}{@link HeaderContentNegotiationStrategy Header strategy}On{@link #setIgnoreAcceptHeader ignoreAcceptHeader}{@link HeaderContentNegotiationStrategy Header strategy}On
{@link #setDefaultContentType defaultContentType}{@link FixedContentNegotiationStrategy Fixed content strategy}Not set{@link #setDefaultContentType defaultContentType}{@link FixedContentNegotiationStrategy Fixed content strategy}Not set
{@link #setDefaultContentTypeStrategy defaultContentTypeStrategy}{@link ContentNegotiationStrategy}Not set{@link #setDefaultContentTypeStrategy defaultContentTypeStrategy}{@link ContentNegotiationStrategy}Not set
* diff --git a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationStrategy.java index 127f90cef4..586485a72a 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationStrategy.java @@ -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. @@ -33,10 +33,8 @@ public interface ContentNegotiationStrategy { /** * Resolve the given request to a list of media types. The returned list is * ordered by specificity first and by quality parameter second. - * * @param webRequest the current request - * @return the requested media types or an empty list, never {@code null} - * + * @return the requested media types or an empty list (never {@code null}) * @throws HttpMediaTypeNotAcceptableException if the requested media * types cannot be parsed */ diff --git a/spring-web/src/main/java/org/springframework/web/accept/FixedContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/FixedContentNegotiationStrategy.java index 547ccef791..50478683b1 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/FixedContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/FixedContentNegotiationStrategy.java @@ -33,8 +33,7 @@ import org.springframework.web.context.request.NativeWebRequest; */ public class FixedContentNegotiationStrategy implements ContentNegotiationStrategy { - private static final Log logger = LogFactory.getLog( - FixedContentNegotiationStrategy.class); + private static final Log logger = LogFactory.getLog(FixedContentNegotiationStrategy.class); private final List contentType; @@ -50,7 +49,7 @@ public class FixedContentNegotiationStrategy implements ContentNegotiationStrate @Override public List resolveMediaTypes(NativeWebRequest request) { if (logger.isDebugEnabled()) { - logger.debug("Requested media types is " + this.contentType + "."); + logger.debug("Requested media types: " + this.contentType); } return this.contentType; } diff --git a/spring-web/src/main/java/org/springframework/web/accept/HeaderContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/HeaderContentNegotiationStrategy.java index bcefd7279e..2642853d9d 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/HeaderContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/HeaderContentNegotiationStrategy.java @@ -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. @@ -34,11 +34,9 @@ import org.springframework.web.context.request.NativeWebRequest; */ public class HeaderContentNegotiationStrategy implements ContentNegotiationStrategy { - /** * {@inheritDoc} - * @throws HttpMediaTypeNotAcceptableException if the 'Accept' header - * cannot be parsed. + * @throws HttpMediaTypeNotAcceptableException if the 'Accept' header cannot be parsed */ @Override public List resolveMediaTypes(NativeWebRequest request) diff --git a/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java b/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java index 6c2c8c7d6b..49c38d6dd3 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java +++ b/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java @@ -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. @@ -35,7 +35,7 @@ import org.springframework.util.MultiValueMap; * lookups between file extensions and MediaTypes in both directions. * *

Initially created with a map of file extensions and media types. - * Subsequently sub-classes can use {@link #addMapping} to add more mappings. + * Subsequently subclasses can use {@link #addMapping} to add more mappings. * * @author Rossen Stoyanchev * @since 3.2 diff --git a/spring-web/src/main/java/org/springframework/web/accept/MediaTypeFileExtensionResolver.java b/spring-web/src/main/java/org/springframework/web/accept/MediaTypeFileExtensionResolver.java index c063e5c50b..49a7fcd986 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/MediaTypeFileExtensionResolver.java +++ b/spring-web/src/main/java/org/springframework/web/accept/MediaTypeFileExtensionResolver.java @@ -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. @@ -31,15 +31,14 @@ public interface MediaTypeFileExtensionResolver { /** * Resolve the given media type to a list of path extensions. - * * @param mediaType the media type to resolve - * @return a list of extensions or an empty list, never {@code null} + * @return a list of extensions or an empty list (never {@code null}) */ List resolveFileExtensions(MediaType mediaType); /** * Return all registered file extensions. - * @return a list of extensions or an empty list, never {@code null} + * @return a list of extensions or an empty list (never {@code null}) */ List getAllFileExtensions(); diff --git a/spring-web/src/main/java/org/springframework/web/accept/ParameterContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/ParameterContentNegotiationStrategy.java index a2520d27fd..f6a9cb4eaa 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ParameterContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ParameterContentNegotiationStrategy.java @@ -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. @@ -27,18 +27,15 @@ import org.springframework.web.HttpMediaTypeNotAcceptableException; import org.springframework.web.context.request.NativeWebRequest; /** - * A {@code ContentNegotiationStrategy} that resolves a query parameter to a - * key to be used to look up a media type. The default parameter name is - * {@code format}. - *s + * A {@code ContentNegotiationStrategy} that resolves a query parameter to a key + * to be used to look up a media type. The default parameter name is {@code format}. + * * @author Rossen Stoyanchev * @since 3.2 */ -public class ParameterContentNegotiationStrategy - extends AbstractMappingContentNegotiationStrategy { +public class ParameterContentNegotiationStrategy extends AbstractMappingContentNegotiationStrategy { - private static final Log logger = LogFactory.getLog( - ParameterContentNegotiationStrategy.class); + private static final Log logger = LogFactory.getLog(ParameterContentNegotiationStrategy.class); private String parameterName = "format"; @@ -56,7 +53,7 @@ public class ParameterContentNegotiationStrategy *

By default this is set to {@code "format"}. */ public void setParameterName(String parameterName) { - Assert.notNull(parameterName, "parameterName is required"); + Assert.notNull(parameterName, "'parameterName' is required"); this.parameterName = parameterName; } @@ -64,6 +61,7 @@ public class ParameterContentNegotiationStrategy return this.parameterName; } + @Override protected String getMediaTypeKey(NativeWebRequest request) { return request.getParameter(getParameterName()); @@ -72,8 +70,8 @@ public class ParameterContentNegotiationStrategy @Override protected void handleMatch(String mediaTypeKey, MediaType mediaType) { if (logger.isDebugEnabled()) { - logger.debug("Requested media type is '" + mediaType + - "' based on '" + getParameterName() + "'='" + mediaTypeKey + "'."); + logger.debug("Requested media type: '" + mediaType + "' based on '" + + getParameterName() + "'='" + mediaTypeKey + "'"); } } diff --git a/spring-web/src/main/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategy.java index 9b19c27154..9f0c26727a 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategy.java @@ -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. @@ -56,8 +56,7 @@ public class PathExtensionContentNegotiationStrategy private static final Log logger = LogFactory.getLog(PathExtensionContentNegotiationStrategy.class); - private static final boolean JAF_PRESENT = ClassUtils.isPresent( - "javax.activation.FileTypeMap", + private static final boolean JAF_PRESENT = ClassUtils.isPresent("javax.activation.FileTypeMap", PathExtensionContentNegotiationStrategy.class.getClassLoader()); private static final UrlPathHelper PATH_HELPER = new UrlPathHelper(); diff --git a/spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java index 203387105c..615568b46d 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java @@ -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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.accept; import java.util.Map; @@ -31,8 +32,7 @@ import org.springframework.web.context.request.NativeWebRequest; * @author Rossen Stoyanchev * @since 3.2 */ -public class ServletPathExtensionContentNegotiationStrategy - extends PathExtensionContentNegotiationStrategy { +public class ServletPathExtensionContentNegotiationStrategy extends PathExtensionContentNegotiationStrategy { private final ServletContext servletContext; @@ -40,12 +40,12 @@ public class ServletPathExtensionContentNegotiationStrategy /** * Create an instance with the given extension-to-MediaType lookup. */ - public ServletPathExtensionContentNegotiationStrategy(ServletContext context, - Map mediaTypes) { + public ServletPathExtensionContentNegotiationStrategy( + ServletContext servletContext, Map mediaTypes) { super(mediaTypes); - Assert.notNull(context, "ServletContext is required!"); - this.servletContext = context; + Assert.notNull(servletContext, "ServletContext is required"); + this.servletContext = servletContext; } /** diff --git a/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java b/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java index ae75fbe4e8..26838d3907 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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. @@ -288,7 +288,7 @@ public abstract class WebApplicationContextUtils { public static void initServletPropertySources( MutablePropertySources propertySources, ServletContext servletContext, ServletConfig servletConfig) { - Assert.notNull(propertySources, "propertySources must not be null"); + Assert.notNull(propertySources, "'propertySources' must not be null"); if (servletContext != null && propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME) && propertySources.get(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME) instanceof StubPropertySource) { propertySources.replace(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME, diff --git a/spring-web/src/main/java/org/springframework/web/filter/AbstractRequestLoggingFilter.java b/spring-web/src/main/java/org/springframework/web/filter/AbstractRequestLoggingFilter.java index 607b8bc076..4062bf6db3 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/AbstractRequestLoggingFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/AbstractRequestLoggingFilter.java @@ -46,7 +46,7 @@ import org.springframework.web.util.WebUtils; * *

Prefixes and suffixes for the before and after messages can be configured using the * {@code beforeMessagePrefix}, {@code afterMessagePrefix}, {@code beforeMessageSuffix} and - * {@code afterMessageSuffix} properties, + * {@code afterMessageSuffix} properties. * * @author Rob Harrop * @author Juergen Hoeller @@ -124,7 +124,6 @@ public abstract class AbstractRequestLoggingFilter extends OncePerRequestFilter *

Should be configured using an {@code } for parameter name * "includePayload" in the filter definition in {@code web.xml}. */ - public void setIncludePayload(boolean includePayload) { this.includePayload = includePayload; } @@ -254,12 +253,14 @@ public abstract class AbstractRequestLoggingFilter extends OncePerRequestFilter StringBuilder msg = new StringBuilder(); msg.append(prefix); msg.append("uri=").append(request.getRequestURI()); + if (isIncludeQueryString()) { String queryString = request.getQueryString(); if (queryString != null) { msg.append('?').append(queryString); } } + if (isIncludeClientInfo()) { String client = request.getRemoteAddr(); if (StringUtils.hasLength(client)) { @@ -274,6 +275,7 @@ public abstract class AbstractRequestLoggingFilter extends OncePerRequestFilter msg.append(";user=").append(user); } } + if (isIncludePayload()) { ContentCachingRequestWrapper wrapper = WebUtils.getNativeRequest(request, ContentCachingRequestWrapper.class); @@ -292,6 +294,7 @@ public abstract class AbstractRequestLoggingFilter extends OncePerRequestFilter } } } + msg.append(suffix); return msg.toString(); } diff --git a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/context/PortletApplicationContextUtils.java b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/context/PortletApplicationContextUtils.java index 4e27a129bf..ce29022a04 100644 --- a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/context/PortletApplicationContextUtils.java +++ b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/context/PortletApplicationContextUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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. @@ -211,7 +211,7 @@ public abstract class PortletApplicationContextUtils { public static void initPortletPropertySources(MutablePropertySources propertySources, ServletContext servletContext, PortletContext portletContext, PortletConfig portletConfig) { - Assert.notNull(propertySources, "propertySources must not be null"); + Assert.notNull(propertySources, "'propertySources' must not be null"); WebApplicationContextUtils.initServletPropertySources(propertySources, servletContext); if (portletContext != null && propertySources.contains(StandardPortletEnvironment.PORTLET_CONTEXT_PROPERTY_SOURCE_NAME)) {