From a9a1f783c5f968dde56f38fc69744c89179c06b2 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 13 Apr 2017 15:59:15 +0200 Subject: [PATCH] Polishing --- gradle/publish-maven.gradle | 4 +-- .../cache/config/CacheNamespaceHandler.java | 11 +++++--- .../context/annotation/Configuration.java | 2 +- .../AbstractApplicationEventMulticaster.java | 6 ++--- .../event/ApplicationEventMulticaster.java | 3 ++- .../event/EventListenerMethodProcessor.java | 4 +-- .../format/annotation/DateTimeFormat.java | 10 +++---- .../format/annotation/NumberFormat.java | 6 ++--- .../org/springframework/asm/package-info.java | 6 ++--- .../springframework/cglib/package-info.java | 6 ++--- .../support/CollectionToObjectConverter.java | 4 +-- ...hMatchingResourcePatternResolverTests.java | 4 +-- .../jdbc/datasource/init/ScriptUtils.java | 27 +++++++++---------- .../converter/FormHttpMessageConverter.java | 11 +++----- .../GenericHttpMessageConverter.java | 12 ++++----- .../http/converter/HttpMessageConverter.java | 10 +++---- .../http/converter/json/GsonFactoryBean.java | 3 +-- .../Jaxb2CollectionHttpMessageConverter.java | 8 +++--- .../web/filter/ForwardedHeaderFilter.java | 20 +++++--------- ...pingJackson2HttpMessageConverterTests.java | 9 +++---- .../web/servlet/ModelAndView.java | 25 ++++++++++++----- ...DeferredResultReturnValueHandlerTests.java | 11 ++++---- 22 files changed, 100 insertions(+), 102 deletions(-) diff --git a/gradle/publish-maven.gradle b/gradle/publish-maven.gradle index 1145e112a66..eff54387f69 100644 --- a/gradle/publish-maven.gradle +++ b/gradle/publish-maven.gradle @@ -29,8 +29,8 @@ def customizePom(pom, gradleProject) { } licenses { license { - name "The Apache Software License, Version 2.0" - url "http://www.apache.org/licenses/LICENSE-2.0.txt" + name "Apache License, Version 2.0" + url "http://www.apache.org/licenses/LICENSE-2.0" distribution "repo" } } diff --git a/spring-context/src/main/java/org/springframework/cache/config/CacheNamespaceHandler.java b/spring-context/src/main/java/org/springframework/cache/config/CacheNamespaceHandler.java index 59dcc256dfb..68bcbcbdca1 100644 --- a/spring-context/src/main/java/org/springframework/cache/config/CacheNamespaceHandler.java +++ b/spring-context/src/main/java/org/springframework/cache/config/CacheNamespaceHandler.java @@ -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. @@ -39,10 +39,11 @@ public class CacheNamespaceHandler extends NamespaceHandlerSupport { static final String DEFAULT_CACHE_MANAGER_BEAN_NAME = "cacheManager"; + static String extractCacheManager(Element element) { - return (element.hasAttribute(CacheNamespaceHandler.CACHE_MANAGER_ATTRIBUTE) ? element - .getAttribute(CacheNamespaceHandler.CACHE_MANAGER_ATTRIBUTE) - : CacheNamespaceHandler.DEFAULT_CACHE_MANAGER_BEAN_NAME); + return (element.hasAttribute(CacheNamespaceHandler.CACHE_MANAGER_ATTRIBUTE) ? + element.getAttribute(CacheNamespaceHandler.CACHE_MANAGER_ATTRIBUTE) : + CacheNamespaceHandler.DEFAULT_CACHE_MANAGER_BEAN_NAME); } static BeanDefinition parseKeyGenerator(Element element, BeanDefinition def) { @@ -53,9 +54,11 @@ public class CacheNamespaceHandler extends NamespaceHandlerSupport { return def; } + @Override public void init() { registerBeanDefinitionParser("annotation-driven", new AnnotationDrivenCacheBeanDefinitionParser()); registerBeanDefinitionParser("advice", new CacheAdviceParser()); } + } diff --git a/spring-context/src/main/java/org/springframework/context/annotation/Configuration.java b/spring-context/src/main/java/org/springframework/context/annotation/Configuration.java index 5e96e5fa1ab..04627fb749b 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/Configuration.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/Configuration.java @@ -390,7 +390,7 @@ public @interface Configuration { /** * Explicitly specify the name of the Spring bean definition associated - * with this Configuration class. If left unspecified (the common case), + * with this Configuration class. If left unspecified (the common case), * a bean name will be automatically generated. *

The custom name applies only if the Configuration class is picked up via * component scanning or supplied directly to a {@link AnnotationConfigApplicationContext}. diff --git a/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java b/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java index b7dd9186a18..fa93701c383 100644 --- a/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java +++ b/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java @@ -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. @@ -256,8 +256,8 @@ public abstract class AbstractApplicationEventMulticaster * for the given event type */ protected boolean supportsEvent(Class listenerType, ResolvableType eventType) { - if (GenericApplicationListener.class.isAssignableFrom(listenerType) - || SmartApplicationListener.class.isAssignableFrom(listenerType)) { + if (GenericApplicationListener.class.isAssignableFrom(listenerType) || + SmartApplicationListener.class.isAssignableFrom(listenerType)) { return true; } ResolvableType declaredEventType = GenericApplicationListenerAdapter.resolveDeclaredEventType(listenerType); diff --git a/spring-context/src/main/java/org/springframework/context/event/ApplicationEventMulticaster.java b/spring-context/src/main/java/org/springframework/context/event/ApplicationEventMulticaster.java index 98053230400..e00601d2437 100644 --- a/spring-context/src/main/java/org/springframework/context/event/ApplicationEventMulticaster.java +++ b/spring-context/src/main/java/org/springframework/context/event/ApplicationEventMulticaster.java @@ -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. @@ -79,6 +79,7 @@ public interface ApplicationEventMulticaster { * based on the {@code event} instance. * @param event the event to multicast * @param eventType the type of event (can be null) + * @since 4.2 */ void multicastEvent(ApplicationEvent event, ResolvableType eventType); diff --git a/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java b/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java index 7a95f172e3d..278021f50c5 100644 --- a/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java @@ -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. @@ -145,7 +145,7 @@ public class EventListenerMethodProcessor implements SmartInitializingSingleton, if (CollectionUtils.isEmpty(annotatedMethods)) { this.nonAnnotatedClasses.add(targetType); if (logger.isTraceEnabled()) { - logger.trace("No @EventListener annotations found on bean class: " + targetType); + logger.trace("No @EventListener annotations found on bean class: " + targetType.getName()); } } else { diff --git a/spring-context/src/main/java/org/springframework/format/annotation/DateTimeFormat.java b/spring-context/src/main/java/org/springframework/format/annotation/DateTimeFormat.java index e52d5d4f8bb..393c3ce2dcf 100644 --- a/spring-context/src/main/java/org/springframework/format/annotation/DateTimeFormat.java +++ b/spring-context/src/main/java/org/springframework/format/annotation/DateTimeFormat.java @@ -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. @@ -23,10 +23,10 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * Declares that a field should be formatted as a date time. + * Declares that a field or method parameter should be formatted as a date or time. * *

Supports formatting by style pattern, ISO date time pattern, or custom format pattern string. - * Can be applied to {@code java.util.Date}, {@code java.util.Calendar}, {@code java.long.Long}, + * Can be applied to {@code java.util.Date}, {@code java.util.Calendar}, {@code java.lang.Long}, * Joda-Time value types; and as of Spring 4 and JDK 8, to JSR-310 java.time types too. * *

For style-based formatting, set the {@link #style} attribute to be the style pattern code. @@ -35,7 +35,7 @@ import java.lang.annotation.Target; * A date or time may be omitted by specifying the style character '-'. * *

For ISO-based formatting, set the {@link #iso} attribute to be the desired {@link ISO} format, - * such as {@link ISO#DATE}. For custom formatting, set the {@link #pattern()} attribute to be the + * such as {@link ISO#DATE}. For custom formatting, set the {@link #pattern} attribute to be the * DateTime pattern, such as {@code yyyy/MM/dd hh:mm:ss a}. * *

Each attribute is mutually exclusive, so only set one attribute per annotation instance @@ -64,7 +64,7 @@ public @interface DateTimeFormat { /** * The ISO pattern to use to format the field. - * The possible ISO patterns are defined in the {@link ISO} enum. + *

The possible ISO patterns are defined in the {@link ISO} enum. *

Defaults to {@link ISO#NONE}, indicating this attribute should be ignored. * Set this attribute when you wish to format your field in accordance with an ISO format. */ diff --git a/spring-context/src/main/java/org/springframework/format/annotation/NumberFormat.java b/spring-context/src/main/java/org/springframework/format/annotation/NumberFormat.java index d56c46cae95..3424143ec59 100644 --- a/spring-context/src/main/java/org/springframework/format/annotation/NumberFormat.java +++ b/spring-context/src/main/java/org/springframework/format/annotation/NumberFormat.java @@ -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. @@ -23,7 +23,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * Declares that a field should be formatted as a number. + * Declares that a field or method parameter should be formatted as a number. * *

Supports formatting by style or custom pattern string. * Can be applied to any JDK {@code java.lang.Number} type. @@ -37,7 +37,7 @@ import java.lang.annotation.Target; * When the {@link #pattern} attribute is specified, it takes precedence over * the {@link #style} attribute. When no annotation attributes are specified, * the default format applied is style-based for either number of currency, - * depending on the annotated field type. + * depending on the annotated field or method parameter type. * * @author Keith Donald * @author Juergen Hoeller diff --git a/spring-core/src/main/java/org/springframework/asm/package-info.java b/spring-core/src/main/java/org/springframework/asm/package-info.java index 98c9a0d8ca8..dc7bf516933 100644 --- a/spring-core/src/main/java/org/springframework/asm/package-info.java +++ b/spring-core/src/main/java/org/springframework/asm/package-info.java @@ -1,6 +1,6 @@ /** * Spring's repackaging of - * org.objectweb.asm 5.0 + * ASM * (for internal use only). * *

This repackaging technique avoids any potential conflicts with @@ -8,8 +8,6 @@ * libraries and frameworks. * *

As this repackaging happens at the class file level, sources - * and javadocs are not available here. See the original ObjectWeb - * ASM 5.0 javadocs - * for details when working with these classes. + * and javadocs are not available here. */ package org.springframework.asm; diff --git a/spring-core/src/main/java/org/springframework/cglib/package-info.java b/spring-core/src/main/java/org/springframework/cglib/package-info.java index 78ef762beed..85d1758e539 100644 --- a/spring-core/src/main/java/org/springframework/cglib/package-info.java +++ b/spring-core/src/main/java/org/springframework/cglib/package-info.java @@ -1,6 +1,6 @@ /** * Spring's repackaging of - * net.sf.cglib 3.2 + * CGLIB * (for internal use only). * *

This repackaging technique avoids any potential conflicts with @@ -8,8 +8,6 @@ * libraries and frameworks. * *

As this repackaging happens at the class file level, sources - * and javadocs are not available here. See the original - * CGLIB 3.2 javadocs - * for details when working with these classes. + * and javadocs are not available here. */ package org.springframework.cglib; diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToObjectConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToObjectConverter.java index bcc51e2f951..052105e6ef1 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToObjectConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToObjectConverter.java @@ -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. @@ -57,7 +57,7 @@ final class CollectionToObjectConverter implements ConditionalGenericConverter { return source; } Collection sourceCollection = (Collection) source; - if (sourceCollection.size() == 0) { + if (sourceCollection.isEmpty()) { return null; } Object firstElement = sourceCollection.iterator().next(); diff --git a/spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java b/spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java index b53cefa1d81..1b3489a40bd 100644 --- a/spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java @@ -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. @@ -154,7 +154,7 @@ public class PathMatchingResourcePatternResolverTests { private void assertFilenameIn(Resource resource, String... filenames) { String filename = resource.getFilename(); assertTrue(resource + " does not have a filename that matches any of the specified names", - Arrays.stream(filenames).anyMatch(filename::endsWith)); + Arrays.stream(filenames).anyMatch(filename::endsWith)); } } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java index 77d302eefff..10076a01c60 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java @@ -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. @@ -168,11 +168,11 @@ public abstract class ScriptUtils { String blockCommentStartDelimiter, String blockCommentEndDelimiter, List statements) throws ScriptException { - Assert.hasText(script, "script must not be null or empty"); - Assert.notNull(separator, "separator must not be null"); - Assert.hasText(commentPrefix, "commentPrefix must not be null or empty"); - Assert.hasText(blockCommentStartDelimiter, "blockCommentStartDelimiter must not be null or empty"); - Assert.hasText(blockCommentEndDelimiter, "blockCommentEndDelimiter must not be null or empty"); + Assert.hasText(script, "'script' must not be null or empty"); + Assert.notNull(separator, "'separator' must not be null"); + Assert.hasText(commentPrefix, "'commentPrefix' must not be null or empty"); + Assert.hasText(blockCommentStartDelimiter, "'blockCommentStartDelimiter' must not be null or empty"); + Assert.hasText(blockCommentEndDelimiter, "'blockCommentEndDelimiter' must not be null or empty"); StringBuilder sb = new StringBuilder(); boolean inSingleQuote = false; @@ -199,7 +199,7 @@ public abstract class ScriptUtils { } if (!inSingleQuote && !inDoubleQuote) { if (script.startsWith(separator, i)) { - // we've reached the end of the current statement + // We've reached the end of the current statement if (sb.length() > 0) { statements.add(sb.toString()); sb = new StringBuilder(); @@ -208,32 +208,31 @@ public abstract class ScriptUtils { continue; } else if (script.startsWith(commentPrefix, i)) { - // skip over any content from the start of the comment to the EOL + // Skip over any content from the start of the comment to the EOL int indexOfNextNewline = script.indexOf("\n", i); if (indexOfNextNewline > i) { i = indexOfNextNewline; continue; } else { - // if there's no EOL, we must be at the end - // of the script, so stop here. + // If there's no EOL, we must be at the end of the script, so stop here. break; } } else if (script.startsWith(blockCommentStartDelimiter, i)) { - // skip over any block comments + // Skip over any block comments int indexOfCommentEnd = script.indexOf(blockCommentEndDelimiter, i); if (indexOfCommentEnd > i) { i = indexOfCommentEnd + blockCommentEndDelimiter.length() - 1; continue; } else { - throw new ScriptParseException(String.format("Missing block comment end delimiter [%s].", - blockCommentEndDelimiter), resource); + throw new ScriptParseException( + "Missing block comment end delimiter: " + blockCommentEndDelimiter, resource); } } else if (c == ' ' || c == '\n' || c == '\t') { - // avoid multiple adjacent whitespace characters + // Avoid multiple adjacent whitespace characters if (sb.length() > 0 && sb.charAt(sb.length() - 1) != ' ') { c = ' '; } diff --git a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java index 643a8713f0e..e7776f0751b 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java @@ -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. @@ -395,12 +395,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter getHttpEntity(Object part) { - if (part instanceof HttpEntity) { - return (HttpEntity) part; - } - else { - return new HttpEntity(part); - } + return (part instanceof HttpEntity ? (HttpEntity) part : new HttpEntity(part)); } /** @@ -415,7 +410,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter extends HttpMessageConverter /** * Indicates whether the given class can be written by this converter. - * This method should perform the same checks than + *

This method should perform the same checks than * {@link HttpMessageConverter#canWrite(Class, MediaType)} with additional ones * related to the generic type. - * @param type the (potentially generic) type to test for writability, can be - * {@code null} if not specified. + * @param type the (potentially generic) type to test for writability + * (can be {@code null} if not specified) * @param clazz the source object class to test for writability - * @param mediaType the media type to write, can be {@code null} if not specified. - * Typically the value of an {@code Accept} header. + * @param mediaType the media type to write (can be {@code null} if not specified); + * typically the value of an {@code Accept} header. * @return {@code true} if writable; {@code false} otherwise * @since 4.2 */ diff --git a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConverter.java index 661c559f414..4fc985333d5 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 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,8 +35,8 @@ public interface HttpMessageConverter { /** * Indicates whether the given class can be read by this converter. * @param clazz the class to test for readability - * @param mediaType the media type to read, can be {@code null} if not specified. - * Typically the value of a {@code Content-Type} header. + * @param mediaType the media type to read (can be {@code null} if not specified); + * typically the value of a {@code Content-Type} header. * @return {@code true} if readable; {@code false} otherwise */ boolean canRead(Class clazz, MediaType mediaType); @@ -44,8 +44,8 @@ public interface HttpMessageConverter { /** * Indicates whether the given class can be written by this converter. * @param clazz the class to test for writability - * @param mediaType the media type to write, can be {@code null} if not specified. - * Typically the value of an {@code Accept} header. + * @param mediaType the media type to write (can be {@code null} if not specified); + * typically the value of an {@code Accept} header. * @return {@code true} if writable; {@code false} otherwise */ boolean canWrite(Class clazz, MediaType mediaType); diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/GsonFactoryBean.java b/spring-web/src/main/java/org/springframework/http/converter/json/GsonFactoryBean.java index 549db72f474..414515cdc1c 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/GsonFactoryBean.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/GsonFactoryBean.java @@ -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. @@ -24,7 +24,6 @@ import com.google.gson.GsonBuilder; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; - /** * A {@link FactoryBean} for creating a Google Gson 2.x {@link Gson} instance. * diff --git a/spring-web/src/main/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverter.java index 91bc8f27154..81f2455a4c1 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverter.java @@ -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. @@ -187,10 +187,9 @@ public class Jaxb2CollectionHttpMessageConverter try { return (T) collectionClass.newInstance(); } - catch (Exception ex) { + catch (Throwable ex) { throw new IllegalArgumentException( - "Could not instantiate collection class [" + - collectionClass.getName() + "]: " + ex.getMessage()); + "Could not instantiate collection class: " + collectionClass.getName(), ex); } } else if (List.class == collectionClass) { @@ -230,6 +229,7 @@ public class Jaxb2CollectionHttpMessageConverter @Override public void write(T t, Type type, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { + throw new UnsupportedOperationException(); } diff --git a/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java b/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java index 9d388830dc9..15d93c7605c 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java @@ -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. @@ -71,6 +71,7 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { private final UrlPathHelper pathHelper; + public ForwardedHeaderFilter() { this.pathHelper = new UrlPathHelper(); this.pathHelper.setUrlDecode(false); @@ -143,8 +144,7 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { String prefix = getForwardedPrefix(request); this.contextPath = (prefix != null ? prefix : request.getContextPath()); this.requestUri = this.contextPath + pathHelper.getPathWithinApplication(request); - this.requestUrl = this.scheme + "://" + this.host + - (port == -1 ? "" : ":" + port) + this.requestUri; + this.requestUrl = this.scheme + "://" + this.host + (port == -1 ? "" : ":" + port) + this.requestUri; this.headers = initHeaders(request); } @@ -235,13 +235,13 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { } } + private static class ForwardedHeaderResponseWrapper extends HttpServletResponseWrapper { private static final String FOLDER_SEPARATOR = "/"; private final HttpServletRequest request; - public ForwardedHeaderResponseWrapper(HttpServletResponse response, HttpServletRequest request) { super(response); this.request = request; @@ -249,7 +249,6 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { @Override public void sendRedirect(String location) throws IOException { - UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(location); // Absolute location @@ -259,20 +258,15 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { } // Network-path reference - if(location.startsWith("//")) { + if (location.startsWith("//")) { String scheme = this.request.getScheme(); super.sendRedirect(builder.scheme(scheme).toUriString()); return; } // Relative to Servlet container root or to current request - String path; - if (location.startsWith(FOLDER_SEPARATOR)) { - path = location; - } - else { - path = StringUtils.applyRelativePath(this.request.getRequestURI(), location); - } + String path = (location.startsWith(FOLDER_SEPARATOR) ? location : + StringUtils.applyRelativePath(this.request.getRequestURI(), location)); String result = UriComponentsBuilder .fromHttpRequest(new ServletServerHttpRequest(this.request)) diff --git a/spring-web/src/test/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverterTests.java index de4ebe2fd8a..675cc0b8449 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverterTests.java @@ -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. @@ -99,7 +99,7 @@ public class MappingJackson2HttpMessageConverterTests { assertEquals("Foo", result.get("string")); assertEquals(42, result.get("number")); assertEquals(42D, (Double) result.get("fraction"), 0D); - List array = new ArrayList(); + List array = new ArrayList<>(); array.add("Foo"); array.add("Bar"); assertEquals(array, result.get("array")); @@ -162,7 +162,6 @@ public class MappingJackson2HttpMessageConverterTests { @SuppressWarnings("unchecked") public void readGenerics() throws IOException { MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter() { - @Override protected JavaType getJavaType(Type type, Class contextClass) { if (type instanceof Class && List.class.isAssignableFrom((Class)type)) { @@ -451,9 +450,9 @@ public class MappingJackson2HttpMessageConverterTests { } - private interface MyJacksonView1 {}; + private interface MyJacksonView1 {} - private interface MyJacksonView2 {}; + private interface MyJacksonView2 {} @SuppressWarnings("unused") diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/ModelAndView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/ModelAndView.java index 5323c1a8f40..237526d0c43 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/ModelAndView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/ModelAndView.java @@ -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. @@ -89,7 +89,7 @@ public class ModelAndView { } /** - * Creates new ModelAndView given a view name and a model. + * Create a new ModelAndView given a view name and a model. * @param viewName name of the View to render, to be resolved * by the DispatcherServlet's ViewResolver * @param model Map of model names (Strings) to model objects @@ -104,7 +104,7 @@ public class ModelAndView { } /** - * Creates new ModelAndView given a View object and a model. + * Create a new ModelAndView given a View object and a model. * Note: the supplied model data is copied into the internal * storage of this class. You should not consider to modify the supplied * Map after supplying it to this class @@ -121,14 +121,27 @@ public class ModelAndView { } /** - * Creates new ModelAndView given a view name, model, and status. + * Create a new ModelAndView given a view name and HTTP status. + * @param viewName name of the View to render, to be resolved + * by the DispatcherServlet's ViewResolver + * @param status an HTTP status code to use for the response + * (to be set just prior to View rendering) + * @since 4.3.8 + */ + public ModelAndView(String viewName, HttpStatus status) { + this.view = viewName; + this.status = status; + } + + /** + * Create a new ModelAndView given a view name, model, and HTTP status. * @param viewName name of the View to render, to be resolved * by the DispatcherServlet's ViewResolver * @param model Map of model names (Strings) to model objects * (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; - * The response status is set just prior to View rendering. + * @param status an HTTP status code to use for the response + * (to be set just prior to View rendering) * @since 4.3 */ public ModelAndView(String viewName, Map model, HttpStatus status) { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java index 9e902ac6214..a9cf29a5248 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java @@ -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. @@ -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 java.lang.reflect.Method; @@ -34,13 +35,11 @@ import org.springframework.web.context.request.async.StandardServletAsyncWebRequ import org.springframework.web.context.request.async.WebAsyncUtils; import org.springframework.web.method.support.ModelAndViewContainer; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * Unit tests for {@link DeferredResultMethodReturnValueHandler}. + * * @author Rossen Stoyanchev */ public class DeferredResultReturnValueHandlerTests { @@ -53,7 +52,7 @@ public class DeferredResultReturnValueHandlerTests { @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.handler = new DeferredResultMethodReturnValueHandler(); this.request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse();