diff --git a/spring-context/src/test/java/org/springframework/context/support/SimpleThreadScopeTests.java b/spring-context/src/test/java/org/springframework/context/support/SimpleThreadScopeTests.java index 7451487b49..7b0277b1a5 100644 --- a/spring-context/src/test/java/org/springframework/context/support/SimpleThreadScopeTests.java +++ b/spring-context/src/test/java/org/springframework/context/support/SimpleThreadScopeTests.java @@ -17,6 +17,7 @@ package org.springframework.context.support; import org.junit.Test; + import org.springframework.context.ApplicationContext; import org.springframework.tests.sample.beans.TestBean; @@ -28,8 +29,9 @@ import static org.junit.Assert.*; */ public class SimpleThreadScopeTests { - private ApplicationContext applicationContext = new ClassPathXmlApplicationContext( - "simpleThreadScopeTests.xml", getClass()); + private final ApplicationContext applicationContext = + new ClassPathXmlApplicationContext("simpleThreadScopeTests.xml", getClass()); + @Test public void getFromScope() throws Exception { @@ -45,19 +47,15 @@ public class SimpleThreadScopeTests { public void getMultipleInstances() throws Exception { final TestBean[] beans = new TestBean[2]; Thread thread1 = new Thread(new Runnable() { - @Override public void run() { - beans[0] = applicationContext.getBean("threadScopedObject", - TestBean.class); + beans[0] = applicationContext.getBean("threadScopedObject", TestBean.class); } }); Thread thread2 = new Thread(new Runnable() { - @Override public void run() { - beans[1] = applicationContext.getBean("threadScopedObject", - TestBean.class); + beans[1] = applicationContext.getBean("threadScopedObject", TestBean.class); } }); thread1.start(); @@ -67,7 +65,6 @@ public class SimpleThreadScopeTests { assertNotNull(beans[0]); assertNotNull(beans[1]); - assertNotSame(beans[0], beans[1]); } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java index ca9ae9581f..f9bb8d3bd1 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java @@ -215,7 +215,7 @@ public class GenericConversionService implements ConfigurableConversionService { } - // subclassing hooks + // Protected template methods /** * Template method to convert a null source. @@ -588,6 +588,7 @@ public class GenericConversionService implements ConfigurableConversionService { private void addInterfacesToClassHierarchy(Class type, boolean asArray, List> hierarchy, Set> visited) { + for (Class implementedInterface : type.getInterfaces()) { addToClassHierarchy(hierarchy.size(), implementedInterface, asArray, hierarchy, visited); } @@ -595,6 +596,7 @@ public class GenericConversionService implements ConfigurableConversionService { private void addToClassHierarchy(int index, Class type, boolean asArray, List> hierarchy, Set> visited) { + if (asArray) { type = Array.newInstance(type, 0).getClass(); } diff --git a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java index db838b5e64..5d681d58b9 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java @@ -125,6 +125,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat private static final boolean gsonPresent = ClassUtils.isPresent("com.google.gson.Gson", RestTemplate.class.getClassLoader()); + private final List> messageConverters = new ArrayList>(); private ResponseErrorHandler errorHandler = new DefaultResponseErrorHandler(); diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractCookieValueMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractCookieValueMethodArgumentResolver.java index a5d1b222bc..be22df6889 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractCookieValueMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractCookieValueMethodArgumentResolver.java @@ -48,6 +48,7 @@ public abstract class AbstractCookieValueMethodArgumentResolver extends Abstract super(beanFactory); } + @Override public boolean supportsParameter(MethodParameter parameter) { return parameter.hasParameterAnnotation(CookieValue.class); @@ -60,15 +61,17 @@ public abstract class AbstractCookieValueMethodArgumentResolver extends Abstract } @Override - protected void handleMissingValue(String cookieName, MethodParameter parameter) throws ServletRequestBindingException { - throw new ServletRequestBindingException( - "Missing cookie named '" + cookieName + "' for method parameter type " + parameter.getParameterType().getSimpleName()); + protected void handleMissingValue(String name, MethodParameter parameter) throws ServletRequestBindingException { + throw new ServletRequestBindingException("Missing cookie '" + name + + "' for method parameter of type " + parameter.getParameterType().getSimpleName()); } + private static class CookieValueNamedValueInfo extends NamedValueInfo { private CookieValueNamedValueInfo(CookieValue annotation) { super(annotation.value(), annotation.required(), annotation.defaultValue()); } } + } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/ExpressionValueMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/ExpressionValueMethodArgumentResolver.java index 7cba4d8736..73393f720a 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/ExpressionValueMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/ExpressionValueMethodArgumentResolver.java @@ -48,6 +48,7 @@ public class ExpressionValueMethodArgumentResolver extends AbstractNamedValueMet super(beanFactory); } + @Override public boolean supportsParameter(MethodParameter parameter) { return parameter.hasParameterAnnotation(Value.class); @@ -70,10 +71,12 @@ public class ExpressionValueMethodArgumentResolver extends AbstractNamedValueMet throw new UnsupportedOperationException("@Value is never required: " + parameter.getMethod()); } + private static class ExpressionValueNamedValueInfo extends NamedValueInfo { private ExpressionValueNamedValueInfo(Value annotation) { super("@Value", false, annotation.value()); } } + } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMethodArgumentResolver.java index 48c6c2c80b..5ac1cc535f 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 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. @@ -52,6 +52,7 @@ public class RequestHeaderMethodArgumentResolver extends AbstractNamedValueMetho super(beanFactory); } + @Override public boolean supportsParameter(MethodParameter parameter) { return parameter.hasParameterAnnotation(RequestHeader.class) && @@ -77,14 +78,16 @@ public class RequestHeaderMethodArgumentResolver extends AbstractNamedValueMetho @Override protected void handleMissingValue(String name, MethodParameter parameter) throws ServletRequestBindingException { - throw new ServletRequestBindingException("Missing header '" + name + - "' for method parameter type " + parameter.getParameterType().getSimpleName()); + throw new ServletRequestBindingException("Missing request header '" + name + + "' for method parameter of type " + parameter.getParameterType().getSimpleName()); } + private static class RequestHeaderNamedValueInfo extends NamedValueInfo { private RequestHeaderNamedValueInfo(RequestHeader annotation) { super(annotation.value(), annotation.required(), annotation.defaultValue()); } } + } 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 bb923c21e4..543aa9db6f 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 @@ -152,17 +152,16 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod @Override protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { - RequestParam annotation = parameter.getParameterAnnotation(RequestParam.class); - return (annotation != null) ? new RequestParamNamedValueInfo(annotation) : new RequestParamNamedValueInfo(); + RequestParam ann = parameter.getParameterAnnotation(RequestParam.class); + return (ann != null ? new RequestParamNamedValueInfo(ann) : new RequestParamNamedValueInfo()); } @Override protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest webRequest) throws Exception { - Object arg; - HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class); MultipartHttpServletRequest multipartRequest = - WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class); + WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class); + Object arg; if (MultipartFile.class.equals(parameter.getParameterType())) { assertIsMultipartRequest(servletRequest); @@ -255,29 +254,29 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod } @Override - public void contributeMethodArgument(MethodParameter param, Object value, + public void contributeMethodArgument(MethodParameter parameter, Object value, UriComponentsBuilder builder, Map uriVariables, ConversionService conversionService) { - Class paramType = param.getParameterType(); + Class paramType = parameter.getParameterType(); if (Map.class.isAssignableFrom(paramType) || MultipartFile.class.equals(paramType) || "javax.servlet.http.Part".equals(paramType.getName())) { return; } - RequestParam annot = param.getParameterAnnotation(RequestParam.class); - String name = (annot == null || StringUtils.isEmpty(annot.value()) ? param.getParameterName() : annot.value()); + RequestParam ann = parameter.getParameterAnnotation(RequestParam.class); + String name = (ann == null || StringUtils.isEmpty(ann.value()) ? parameter.getParameterName() : ann.value()); if (value == null) { builder.queryParam(name); } else if (value instanceof Collection) { for (Object element : (Collection) value) { - element = formatUriValue(conversionService, TypeDescriptor.nested(param, 1), element); + element = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), element); builder.queryParam(name, element); } } else { - builder.queryParam(name, formatUriValue(conversionService, new TypeDescriptor(param), value)); + builder.queryParam(name, formatUriValue(conversionService, new TypeDescriptor(parameter), value)); } } 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 c5842b6917..8e563d22c2 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 @@ -116,7 +116,7 @@ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueMeth @Override protected void handleMissingValue(String name, MethodParameter parameter) throws ServletRequestBindingException { throw new ServletRequestBindingException("Missing matrix variable '" + name + - "' for method parameter type " + parameter.getParameterType().getSimpleName()); + "' for method parameter of type " + parameter.getParameterType().getSimpleName()); } 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 8d5da19d8c..3aa5143ca2 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-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -103,7 +103,7 @@ public class PathVariableMethodArgumentResolver extends AbstractNamedValueMethod @Override protected void handleMissingValue(String name, MethodParameter parameter) throws ServletRequestBindingException { throw new ServletRequestBindingException("Missing URI template variable '" + name + - "' for method parameter type " + parameter.getParameterType().getSimpleName()); + "' for method parameter of type " + parameter.getParameterType().getSimpleName()); } @Override @@ -122,16 +122,16 @@ public class PathVariableMethodArgumentResolver extends AbstractNamedValueMethod } @Override - public void contributeMethodArgument(MethodParameter param, Object value, - UriComponentsBuilder builder, Map uriVariables, ConversionService cs) { + public void contributeMethodArgument(MethodParameter parameter, Object value, + UriComponentsBuilder builder, Map uriVariables, ConversionService conversionService) { - if (Map.class.isAssignableFrom(param.getParameterType())) { + if (Map.class.isAssignableFrom(parameter.getParameterType())) { return; } - PathVariable annot = param.getParameterAnnotation(PathVariable.class); - String name = (StringUtils.isEmpty(annot.value()) ? param.getParameterName() : annot.value()); - value = formatUriValue(cs, new TypeDescriptor(param), value); + PathVariable ann = parameter.getParameterAnnotation(PathVariable.class); + String name = (ann == null || StringUtils.isEmpty(ann.value()) ? parameter.getParameterName() : ann.value()); + value = formatUriValue(conversionService, new TypeDescriptor(parameter), value); uriVariables.put(name, value); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolver.java index 48080aa16a..8c51d5d8d2 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 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,8 +27,8 @@ import org.springframework.web.util.UrlPathHelper; import org.springframework.web.util.WebUtils; /** - * An {@link org.springframework.web.method.annotation.AbstractCookieValueMethodArgumentResolver} that resolves cookie - * values from an {@link HttpServletRequest}. + * An {@link org.springframework.web.method.annotation.AbstractCookieValueMethodArgumentResolver} + * that resolves cookie values from an {@link HttpServletRequest}. * * @author Rossen Stoyanchev * @since 3.1 @@ -37,17 +37,19 @@ public class ServletCookieValueMethodArgumentResolver extends AbstractCookieValu private UrlPathHelper urlPathHelper = new UrlPathHelper(); + public ServletCookieValueMethodArgumentResolver(ConfigurableBeanFactory beanFactory) { super(beanFactory); } + public void setUrlPathHelper(UrlPathHelper urlPathHelper) { this.urlPathHelper = urlPathHelper; } + @Override - protected Object resolveName(String cookieName, MethodParameter parameter, NativeWebRequest webRequest) - throws Exception { + protected Object resolveName(String cookieName, MethodParameter parameter, NativeWebRequest webRequest) throws Exception { HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class); Cookie cookieValue = WebUtils.getCookie(servletRequest, cookieName); if (Cookie.class.isAssignableFrom(parameter.getParameterType())) { @@ -60,4 +62,5 @@ public class ServletCookieValueMethodArgumentResolver extends AbstractCookieValu return null; } } + }