diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/UnsatisfiedDependencyException.java b/spring-beans/src/main/java/org/springframework/beans/factory/UnsatisfiedDependencyException.java index f539e701807..9ec35a7e631 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/UnsatisfiedDependencyException.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/UnsatisfiedDependencyException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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,7 +56,7 @@ public class UnsatisfiedDependencyException extends BeanCreationException { public UnsatisfiedDependencyException( String resourceDescription, String beanName, String propertyName, BeansException ex) { - this(resourceDescription, beanName, propertyName, (ex != null ? ": " + ex.getMessage() : "")); + this(resourceDescription, beanName, propertyName, (ex != null ? ex.getMessage() : "")); initCause(ex); } @@ -88,7 +88,7 @@ public class UnsatisfiedDependencyException extends BeanCreationException { public UnsatisfiedDependencyException( String resourceDescription, String beanName, int ctorArgIndex, Class ctorArgType, BeansException ex) { - this(resourceDescription, beanName, ctorArgIndex, ctorArgType, (ex != null ? ": " + ex.getMessage() : "")); + this(resourceDescription, beanName, ctorArgIndex, ctorArgType, (ex != null ? ex.getMessage() : "")); initCause(ex); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java index fd38f364ccd..88642eb493e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.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. @@ -196,6 +196,7 @@ public class DependencyDescriptor implements Serializable { * Optionally set the concrete class that contains this dependency. * This may differ from the class that declares the parameter/field in that * it may be a subclass thereof, potentially substituting type variables. + * @since 4.0 */ public void setContainingClass(Class containingClass) { this.containingClass = containingClass; @@ -206,6 +207,7 @@ public class DependencyDescriptor implements Serializable { /** * Build a ResolvableType object for the wrapped parameter/field. + * @since 4.0 */ public ResolvableType getResolvableType() { return (this.field != null ? ResolvableType.forField(this.field, this.nestingLevel, this.containingClass) : @@ -217,6 +219,7 @@ public class DependencyDescriptor implements Serializable { *

This is {@code false} by default but may be overridden to return {@code true} in order * to suggest to a {@link org.springframework.beans.factory.support.AutowireCandidateResolver} * that a fallback match is acceptable as well. + * @since 4.0 */ public boolean fallbackMatchAllowed() { return false; @@ -224,6 +227,7 @@ public class DependencyDescriptor implements Serializable { /** * Return a variant of this descriptor that is intended for a fallback match. + * @since 4.0 * @see #fallbackMatchAllowed() */ public DependencyDescriptor forFallbackMatch() { diff --git a/spring-context/src/test/java/org/springframework/jmx/export/annotation/EnableMBeanExportConfigurationTests.java b/spring-context/src/test/java/org/springframework/jmx/export/annotation/EnableMBeanExportConfigurationTests.java index 6ad47d7eb90..caad3982993 100644 --- a/spring-context/src/test/java/org/springframework/jmx/export/annotation/EnableMBeanExportConfigurationTests.java +++ b/spring-context/src/test/java/org/springframework/jmx/export/annotation/EnableMBeanExportConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 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. @@ -73,7 +73,8 @@ public class EnableMBeanExportConfigurationTests { ObjectName oname = ObjectNameManager.getInstance("bean:name=testBean4"); assertNotNull(server.getObjectInstance(oname)); assertEquals("TEST", server.getAttribute(oname, "Name")); - } finally { + } + finally { ctx.close(); } } @@ -142,7 +143,8 @@ public class EnableMBeanExportConfigurationTests { assertNotNull(server.getObjectInstance(oname)); String name = (String) server.getAttribute(oname, "Name"); assertNull(name); - } finally { + } + finally { ctx.close(); } } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/EnumToStringConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/EnumToStringConverter.java index bfd1762d969..02a5f19f29c 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/EnumToStringConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/EnumToStringConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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,8 +23,9 @@ import org.springframework.core.convert.converter.Converter; import org.springframework.util.ClassUtils; /** - * Calls {@link Enum#name()} to convert a source Enum to a String. This converter will - * not match enums with interfaces that can be converterd. + * Calls {@link Enum#name()} to convert a source Enum to a String. + * This converter will not match enums with interfaces that can be converted. + * * @author Keith Donald * @author Phillip Webb * @since 3.0 @@ -33,14 +34,16 @@ final class EnumToStringConverter implements Converter, String>, Conditi private final ConversionService conversionService; + public EnumToStringConverter(ConversionService conversionService) { this.conversionService = conversionService; } + @Override public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { for (Class interfaceType : ClassUtils.getAllInterfacesForClass(sourceType.getType())) { - if (conversionService.canConvert(TypeDescriptor.valueOf(interfaceType), targetType)) { + if (this.conversionService.canConvert(TypeDescriptor.valueOf(interfaceType), targetType)) { return false; } } diff --git a/spring-core/src/main/java/org/springframework/core/env/PropertySourcesPropertyResolver.java b/spring-core/src/main/java/org/springframework/core/env/PropertySourcesPropertyResolver.java index 9e33628448d..edf0b72965b 100644 --- a/spring-core/src/main/java/org/springframework/core/env/PropertySourcesPropertyResolver.java +++ b/spring-core/src/main/java/org/springframework/core/env/PropertySourcesPropertyResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 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. @@ -80,8 +80,8 @@ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver { if (debugEnabled) { logger.debug(String.format("Searching for key '%s' in [%s]", key, propertySource.getName())); } - Object value; - if ((value = propertySource.getProperty(key)) != null) { + Object value = propertySource.getProperty(key); + if (value != null) { Class valueType = value.getClass(); if (resolveNestedPlaceholders && value instanceof String) { value = resolveNestedPlaceholders((String) value); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/DestinationVariableMethodArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/DestinationVariableMethodArgumentResolver.java index 9ebd81363ae..76e6a8e1bfa 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/DestinationVariableMethodArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/DestinationVariableMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 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. @@ -42,6 +42,7 @@ public class DestinationVariableMethodArgumentResolver extends AbstractNamedValu super(cs, null); } + @Override public boolean supportsParameter(MethodParameter parameter) { return parameter.hasParameterAnnotation(DestinationVariable.class); @@ -58,10 +59,9 @@ public class DestinationVariableMethodArgumentResolver extends AbstractNamedValu throws Exception { @SuppressWarnings("unchecked") - Map vars = (Map) message.getHeaders().get( - DESTINATION_TEMPLATE_VARIABLES_HEADER); - - return (vars != null) ? vars.get(name) : null; + Map vars = + (Map) message.getHeaders().get(DESTINATION_TEMPLATE_VARIABLES_HEADER); + return (vars != null ? vars.get(name) : null); } @Override @@ -77,4 +77,5 @@ public class DestinationVariableMethodArgumentResolver extends AbstractNamedValu super(annotation.value(), true, ValueConstants.DEFAULT_NONE); } } -} \ No newline at end of file + +} diff --git a/spring-web/src/main/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverter.java index c0c1daa2738..797732eff05 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 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. @@ -55,7 +55,7 @@ public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConve /** * Construct a new {@code MarshallingHttpMessageConverter} with no {@link Marshaller} or * {@link Unmarshaller} set. The Marshaller and Unmarshaller must be set after construction - * by invoking {@link #setMarshaller(Marshaller)} and {@link #setUnmarshaller(Unmarshaller)} . + * by invoking {@link #setMarshaller(Marshaller)} and {@link #setUnmarshaller(Unmarshaller)}. */ public MarshallingHttpMessageConverter() { } @@ -104,14 +104,15 @@ public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConve this.unmarshaller = unmarshaller; } + @Override public boolean canRead(Class clazz, MediaType mediaType) { - return canRead(mediaType) && (this.unmarshaller != null) && this.unmarshaller.supports(clazz); + return (canRead(mediaType) && this.unmarshaller != null && this.unmarshaller.supports(clazz)); } @Override public boolean canWrite(Class clazz, MediaType mediaType) { - return canWrite(mediaType) && (this.marshaller != null) && this.marshaller.supports(clazz); + return (canWrite(mediaType) && this.marshaller != null && this.marshaller.supports(clazz)); } @Override diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestPart.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestPart.java index b8bd5c28fa0..8f27d5c86fa 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestPart.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestPart.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. @@ -55,7 +55,6 @@ import org.springframework.web.multipart.MultipartResolver; * @author Arjen Poutsma * @author Sam Brannen * @since 3.1 - * * @see RequestParam * @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter */ diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java index e2671f3b081..aba8999a187 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.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. @@ -262,7 +262,8 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod } RequestParam requestParam = parameter.getParameterAnnotation(RequestParam.class); - String name = (requestParam == null || StringUtils.isEmpty(requestParam.name()) ? parameter.getParameterName() : requestParam.name()); + String name = (requestParam == null || StringUtils.isEmpty(requestParam.name()) ? + parameter.getParameterName() : requestParam.name()); if (value == null) { builder.queryParam(name); diff --git a/spring-web/src/main/java/org/springframework/web/multipart/support/MissingServletRequestPartException.java b/spring-web/src/main/java/org/springframework/web/multipart/support/MissingServletRequestPartException.java index 422517bd63d..905525b0392 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/support/MissingServletRequestPartException.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/support/MissingServletRequestPartException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 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. @@ -24,27 +24,28 @@ import org.springframework.web.multipart.MultipartResolver; * Raised when the part of a "multipart/form-data" request identified by its * name cannot be found. * - *

This may be because the request is not a multipart/form-data - * - * either because the part is not present in the request, or - * because the web application is not configured correctly for processing - * multipart requests -- e.g. no {@link MultipartResolver}. + *

This may be because the request is not a multipart/form-data request, + * because the part is not present in the request, or because the web + * application is not configured correctly for processing multipart requests, + * e.g. no {@link MultipartResolver}. * * @author Rossen Stoyanchev * @since 3.1 */ +@SuppressWarnings("serial") public class MissingServletRequestPartException extends ServletException { - private static final long serialVersionUID = -1255077391966870705L; - private final String partName; + public MissingServletRequestPartException(String partName) { - super("Required request part '" + partName + "' is not present."); + super("Required request part '" + partName + "' is not present"); this.partName = partName; } + public String getRequestPartName() { return this.partName; } + } diff --git a/spring-web/src/main/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequest.java b/spring-web/src/main/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequest.java index b26637e632f..78eab9180e5 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequest.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,7 +33,6 @@ import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.multipart.MultipartResolver; import org.springframework.web.util.WebUtils; - /** * {@link ServerHttpRequest} implementation that accesses one part of a multipart * request. If using {@link MultipartResolver} configuration the part is accessed @@ -54,8 +53,8 @@ public class RequestPartServletServerHttpRequest extends ServletServerHttpReques /** - * Create a new instance. - * @param request the current request + * Create a new {@code RequestPartServletServerHttpRequest} instance. + * @param request the current servlet request * @param partName the name of the part to adapt to the {@link ServerHttpRequest} contract * @throws MissingServletRequestPartException if the request part cannot be found * @throws IllegalArgumentException if MultipartHttpServletRequest cannot be initialized diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolverTests.java index 4617715a8ca..00b61b5f2b3 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolverTests.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. @@ -87,10 +87,10 @@ public class RequestParamMethodArgumentResolverTests { private MockHttpServletRequest request; + @Before public void setUp() throws Exception { resolver = new RequestParamMethodArgumentResolver(null, true); - ParameterNameDiscoverer paramNameDiscoverer = new LocalVariableTableParameterNameDiscoverer(); Method method = getClass().getMethod("params", String.class, String[].class, @@ -126,6 +126,7 @@ public class RequestParamMethodArgumentResolverTests { webRequest = new ServletWebRequest(request, new MockHttpServletResponse()); } + @Test public void supportsParameter() { resolver = new RequestParamMethodArgumentResolver(null, true); @@ -154,18 +155,16 @@ public class RequestParamMethodArgumentResolverTests { request.addParameter("name", expected); Object result = resolver.resolveArgument(paramNamedDefaultValueString, null, webRequest, null); - assertTrue(result instanceof String); assertEquals("Invalid result", expected, result); } @Test public void resolveStringArray() throws Exception { - String[] expected = new String[]{"foo", "bar"}; + String[] expected = new String[] {"foo", "bar"}; request.addParameter("name", expected); Object result = resolver.resolveArgument(paramNamedStringArray, null, webRequest, null); - assertTrue(result instanceof String[]); assertArrayEquals("Invalid result", expected, (String[]) result); } @@ -178,7 +177,6 @@ public class RequestParamMethodArgumentResolverTests { webRequest = new ServletWebRequest(request); Object result = resolver.resolveArgument(paramMultipartFile, null, webRequest, null); - assertTrue(result instanceof MultipartFile); assertEquals("Invalid result", expected, result); } @@ -193,7 +191,6 @@ public class RequestParamMethodArgumentResolverTests { webRequest = new ServletWebRequest(request); Object result = resolver.resolveArgument(paramMultipartFileList, null, webRequest, null); - assertTrue(result instanceof List); assertEquals(Arrays.asList(expected1, expected2), result); } @@ -208,9 +205,9 @@ public class RequestParamMethodArgumentResolverTests { webRequest = new ServletWebRequest(request); Object result = resolver.resolveArgument(paramMultipartFileArray, null, webRequest, null); - assertTrue(result instanceof MultipartFile[]); MultipartFile[] parts = (MultipartFile[]) result; + assertEquals(2, parts.length); assertEquals(parts[0], expected1); assertEquals(parts[1], expected2); } @@ -242,7 +239,6 @@ public class RequestParamMethodArgumentResolverTests { webRequest = new ServletWebRequest(request); Object result = resolver.resolveArgument(paramPartList, null, webRequest, null); - assertTrue(result instanceof List); assertEquals(Arrays.asList(expected1, expected2), result); } @@ -259,9 +255,9 @@ public class RequestParamMethodArgumentResolverTests { webRequest = new ServletWebRequest(request); Object result = resolver.resolveArgument(paramPartArray, null, webRequest, null); - assertTrue(result instanceof Part[]); Part[] parts = (Part[]) result; + assertEquals(2, parts.length); assertEquals(parts[0], expected1); assertEquals(parts[1], expected2); } @@ -274,7 +270,6 @@ public class RequestParamMethodArgumentResolverTests { webRequest = new ServletWebRequest(request); Object result = resolver.resolveArgument(paramMultipartFileNotAnnot, null, webRequest, null); - assertTrue(result instanceof MultipartFile); assertEquals("Invalid result", expected, result); } @@ -289,7 +284,6 @@ public class RequestParamMethodArgumentResolverTests { webRequest = new ServletWebRequest(request); Object result = resolver.resolveArgument(paramMultipartFileListNotAnnot, null, webRequest, null); - assertTrue(result instanceof List); assertEquals(Arrays.asList(expected1, expected2), result); } @@ -300,9 +294,7 @@ public class RequestParamMethodArgumentResolverTests { fail("Expected exception: request is not a multipart request"); } - // SPR-9079 - - @Test + @Test // SPR-9079 public void isMultipartRequestHttpPut() throws Exception { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); MultipartFile expected = new MockMultipartFile("multipartFileList", "Hello World".getBytes()); @@ -311,7 +303,6 @@ public class RequestParamMethodArgumentResolverTests { webRequest = new ServletWebRequest(request); Object actual = resolver.resolveArgument(paramMultipartFileListNotAnnot, null, webRequest, null); - assertTrue(actual instanceof List); assertEquals(expected, ((List) actual).get(0)); } @@ -334,7 +325,6 @@ public class RequestParamMethodArgumentResolverTests { webRequest = new ServletWebRequest(request); Object result = resolver.resolveArgument(paramPartNotAnnot, null, webRequest, null); - assertTrue(result instanceof Part); assertEquals("Invalid result", expected, result); } @@ -342,7 +332,6 @@ public class RequestParamMethodArgumentResolverTests { @Test public void resolveDefaultValue() throws Exception { Object result = resolver.resolveArgument(paramNamedDefaultValueString, null, webRequest, null); - assertTrue(result instanceof String); assertEquals("Invalid result", "bar", result); } @@ -353,11 +342,8 @@ public class RequestParamMethodArgumentResolverTests { fail("Expected exception"); } - // SPR-10578 - - @Test + @Test // SPR-10578 public void missingRequestParamEmptyValueConvertedToNull() throws Exception { - WebDataBinder binder = new WebRequestDataBinder(null); binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); @@ -367,13 +353,11 @@ public class RequestParamMethodArgumentResolverTests { this.request.addParameter("stringNotAnnot", ""); Object arg = resolver.resolveArgument(paramStringNotAnnot, null, webRequest, binderFactory); - assertNull(arg); } @Test public void missingRequestParamEmptyValueNotRequired() throws Exception { - WebDataBinder binder = new WebRequestDataBinder(null); binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); @@ -383,7 +367,6 @@ public class RequestParamMethodArgumentResolverTests { this.request.addParameter("name", ""); Object arg = resolver.resolveArgument(paramNotRequired, null, webRequest, binderFactory); - assertNull(arg); } @@ -396,17 +379,13 @@ public class RequestParamMethodArgumentResolverTests { assertEquals("plainValue", result); } - // SPR-8561 - - @Test + @Test // SPR-8561 public void resolveSimpleTypeParamToNull() throws Exception { Object result = resolver.resolveArgument(paramStringNotAnnot, null, webRequest, null); assertNull(result); } - // SPR-10180 - - @Test + @Test // SPR-10180 public void resolveEmptyValueToDefault() throws Exception { this.request.addParameter("name", ""); Object result = resolver.resolveArgument(paramNamedDefaultValueString, null, webRequest, null); @@ -429,13 +408,12 @@ public class RequestParamMethodArgumentResolverTests { @Test @SuppressWarnings("rawtypes") - public void resolveOptional() throws Exception { + public void resolveOptionalParamValue() throws Exception { ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer(); initializer.setConversionService(new DefaultConversionService()); WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer); Object result = resolver.resolveArgument(paramOptional, null, webRequest, binderFactory); - assertEquals(Optional.class, result.getClass()); assertEquals(Optional.empty(), result); this.request.addParameter("name", "123"); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java index 99386e074ae..d84d1601f9d 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.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. @@ -152,6 +152,28 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap return this.mappingRegistry; } + /** + * Register the given mapping. + *

This method may be invoked at runtime after initialization has completed. + * @param mapping the mapping for the handler method + * @param handler the handler + * @param method the method + */ + public void registerMapping(T mapping, Object handler, Method method) { + this.mappingRegistry.register(mapping, handler, method); + } + + /** + * Un-register the given mapping. + *

This method may be invoked at runtime after initialization has completed. + * @param mapping the mapping to unregister + */ + public void unregisterMapping(T mapping) { + this.mappingRegistry.unregister(mapping); + } + + + // Handler method detection /** * Detects handler methods at initialization. @@ -195,13 +217,6 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap handlerMethodsInitialized(getHandlerMethods()); } - /** - * Whether the given type is a handler with handler methods. - * @param beanType the type of the bean being checked - * @return "true" if this a handler type, "false" otherwise. - */ - protected abstract boolean isHandler(Class beanType); - /** * Look for handler methods in a handler. * @param handler the bean name of a handler or a handler instance @@ -227,16 +242,6 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap } } - /** - * Provide the mapping for a handler method. A method for which no - * mapping can be provided is not a handler method. - * @param method the method to provide a mapping for - * @param handlerType the handler type, possibly a sub-type of the method's - * declaring class - * @return the mapping, or {@code null} if the method is not mapped - */ - protected abstract T getMappingForMethod(Method method, Class handlerType); - /** * Register a handler method and its unique mapping. Invoked at startup for * each detected handler method. @@ -269,11 +274,6 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap return handlerMethod; } - /** - * Extract and return the URL paths contained in a mapping. - */ - protected abstract Set getMappingPathPatterns(T mapping); - /** * Extract and return the CORS configuration for the mapping. */ @@ -288,25 +288,8 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap protected void handlerMethodsInitialized(Map handlerMethods) { } - /** - * Register the given mapping. - *

This method may be invoked at runtime after initialization has completed. - * @param mapping the mapping for the handler method - * @param handler the handler - * @param method the method - */ - public void registerMapping(T mapping, Object handler, Method method) { - this.mappingRegistry.register(mapping, handler, method); - } - /** - * Un-register the given mapping. - *

This method may be invoked at runtime after initialization has completed. - * @param mapping the mapping to unregister - */ - public void unregisterMapping(T mapping) { - this.mappingRegistry.unregister(mapping); - } + // Handler method lookup /** * Look up a handler method for the given request. @@ -392,23 +375,6 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap } } - /** - * Check if a mapping matches the current request and return a (potentially - * new) mapping with conditions relevant to the current request. - * @param mapping the mapping to get a match for - * @param request the current HTTP servlet request - * @return the match, or {@code null} if the mapping doesn't match - */ - protected abstract T getMatchingMapping(T mapping, HttpServletRequest request); - - /** - * Return a comparator for sorting matching mappings. - * The returned comparator should sort 'better' matches higher. - * @param request the current request - * @return the comparator (never {@code null}) - */ - protected abstract Comparator getMappingComparator(HttpServletRequest request); - /** * Invoked when a matching mapping is found. * @param mapping the matching mapping @@ -449,6 +415,48 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap } + // Abstract template methods + + /** + * Whether the given type is a handler with handler methods. + * @param beanType the type of the bean being checked + * @return "true" if this a handler type, "false" otherwise. + */ + protected abstract boolean isHandler(Class beanType); + + /** + * Provide the mapping for a handler method. A method for which no + * mapping can be provided is not a handler method. + * @param method the method to provide a mapping for + * @param handlerType the handler type, possibly a sub-type of the method's + * declaring class + * @return the mapping, or {@code null} if the method is not mapped + */ + protected abstract T getMappingForMethod(Method method, Class handlerType); + + /** + * Extract and return the URL paths contained in a mapping. + */ + protected abstract Set getMappingPathPatterns(T mapping); + + /** + * Check if a mapping matches the current request and return a (potentially + * new) mapping with conditions relevant to the current request. + * @param mapping the mapping to get a match for + * @param request the current HTTP servlet request + * @return the match, or {@code null} if the mapping doesn't match + */ + protected abstract T getMatchingMapping(T mapping, HttpServletRequest request); + + /** + * Return a comparator for sorting matching mappings. + * The returned comparator should sort 'better' matches higher. + * @param request the current request + * @return the comparator (never {@code null}) + */ + protected abstract Comparator getMappingComparator(HttpServletRequest request); + + /** * A registry that maintains all mappings to handler methods, exposing methods * to perform lookups and providing concurrent access. @@ -516,7 +524,6 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap this.readWriteLock.readLock().unlock(); } - public void register(T mapping, Object handler, Method method) { this.readWriteLock.writeLock().lock(); try { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMethodArgumentResolver.java index 31f44a6e64a..6e9711767b5 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMethodArgumentResolver.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. @@ -48,6 +48,7 @@ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueMeth super(null); } + @Override public boolean supportsParameter(MethodParameter parameter) { if (!parameter.hasParameterAnnotation(MatrixVariable.class)) { @@ -67,13 +68,10 @@ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueMeth } @Override + @SuppressWarnings("unchecked") protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception { - - @SuppressWarnings("unchecked") - Map> pathParameters = - (Map>) request.getAttribute( - HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST); - + Map> pathParameters = (Map>) + request.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST); if (CollectionUtils.isEmpty(pathParameters)) { return null; } @@ -95,7 +93,7 @@ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueMeth String paramType = parameter.getParameterType().getName(); throw new ServletRequestBindingException( "Found more than one match for URI path parameter '" + name + - "' for parameter type [" + paramType + "]. Use pathVar attribute to disambiguate."); + "' for parameter type [" + paramType + "]. Use 'pathVar' attribute to disambiguate."); } paramValues.addAll(params.get(name)); found = true; @@ -127,4 +125,5 @@ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueMeth super(annotation.name(), annotation.required(), annotation.defaultValue()); } } -} \ No newline at end of file + +} diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolver.java index ec3c7e24318..0475e03b6db 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolver.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,7 +33,6 @@ import org.springframework.web.bind.annotation.ValueConstants; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver; -import org.springframework.web.method.annotation.RequestParamMapMethodArgumentResolver; import org.springframework.web.method.support.ModelAndViewContainer; import org.springframework.web.method.support.UriComponentsContributor; import org.springframework.web.servlet.HandlerMapping; @@ -43,22 +42,18 @@ import org.springframework.web.util.UriComponentsBuilder; /** * Resolves method arguments annotated with an @{@link PathVariable}. * - *

An @{@link PathVariable} is a named value that gets resolved from a URI - * template variable. It is always required and does not have a default value - * to fall back on. See the base class + *

An @{@link PathVariable} is a named value that gets resolved from a URI template variable. + * It is always required and does not have a default value to fall back on. See the base class * {@link org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver} * for more information on how named values are processed. * - *

If the method parameter type is {@link Map}, the name specified in the - * annotation is used to resolve the URI variable String value. The value is - * then converted to a {@link Map} via type conversion assuming a suitable - * {@link Converter} or {@link PropertyEditor} has been registered. - * Or if the annotation does not specify name the - * {@link RequestParamMapMethodArgumentResolver} is used instead to provide - * access to all URI variables in a map. + *

If the method parameter type is {@link Map}, the name specified in the annotation is used + * to resolve the URI variable String value. The value is then converted to a {@link Map} via + * type conversion, assuming a suitable {@link Converter} or {@link PropertyEditor} has been + * registered. * - *

A {@link WebDataBinder} is invoked to apply type conversion to resolved - * path variable values that don't yet match the method parameter type. + *

A {@link WebDataBinder} is invoked to apply type conversion to resolved path variable + * values that don't yet match the method parameter type. * * @author Rossen Stoyanchev * @author Arjen Poutsma @@ -95,10 +90,9 @@ public class PathVariableMethodArgumentResolver extends AbstractNamedValueMethod @Override @SuppressWarnings("unchecked") protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception { - Map uriTemplateVars = - (Map) request.getAttribute( - HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST); - return (uriTemplateVars != null) ? uriTemplateVars.get(name) : null; + Map uriTemplateVars = (Map) request.getAttribute( + HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST); + return (uriTemplateVars != null ? uriTemplateVars.get(name) : null); } @Override diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java index 1e35c830d6c..7ccc938ced1 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java @@ -28,7 +28,6 @@ import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; - import javax.servlet.http.HttpServletRequest; import org.springframework.core.io.AbstractResource; @@ -238,6 +237,7 @@ public class VersionResourceResolver extends AbstractResourceResolver { return null; } + private class FileNameVersionedResource extends AbstractResource implements VersionedResource { private final Resource original; @@ -313,7 +313,6 @@ public class VersionResourceResolver extends AbstractResourceResolver { public String getVersion() { return this.version; } - } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionedResource.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionedResource.java index 8960a54ef6f..c780df8c891 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionedResource.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionedResource.java @@ -19,8 +19,8 @@ package org.springframework.web.servlet.resource; import org.springframework.core.io.Resource; /** - * Interface for a resource descriptor that describes its version - * with a version string that can be derived from its content and/or metadata. + * Interface for a resource descriptor that describes its version with a + * version string that can be derived from its content and/or metadata. * * @author Brian Clozel * @since 4.2.5 @@ -29,4 +29,5 @@ import org.springframework.core.io.Resource; public interface VersionedResource extends Resource { String getVersion(); + } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java index f7c35c2aee2..21bf3834bf1 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 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. @@ -47,7 +47,9 @@ import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMeth import static org.junit.Assert.*; -/** @author Arjen Poutsma */ +/** + * @author Arjen Poutsma + */ public class DefaultHandlerExceptionResolverTests { private DefaultHandlerExceptionResolver exceptionResolver; @@ -174,7 +176,9 @@ public class DefaultHandlerExceptionResolverTests { assertNotNull("No ModelAndView returned", mav); assertTrue("No Empty ModelAndView returned", mav.isEmpty()); assertEquals("Invalid status code", 400, response.getStatus()); - assertEquals("Required request part 'name' is not present.", response.getErrorMessage()); + assertTrue(response.getErrorMessage().contains("request part")); + assertTrue(response.getErrorMessage().contains("name")); + assertTrue(response.getErrorMessage().contains("not present")); } @Test @@ -211,6 +215,7 @@ public class DefaultHandlerExceptionResolverTests { assertSame(ex, request.getAttribute("javax.servlet.error.exception")); } + @SuppressWarnings("unused") public void handle(String arg) { }