diff --git a/spring-beans-groovy/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java b/spring-beans-groovy/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java index 534f80cd949..84ddde998f4 100644 --- a/spring-beans-groovy/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java +++ b/spring-beans-groovy/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.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. @@ -213,7 +213,7 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp Binding binding = new Binding() { @Override public void setVariable(String name, Object value) { - if (currentBeanDefinition !=null) { + if (currentBeanDefinition != null) { applyPropertyToBeanDefinition(name, value); } else { @@ -410,7 +410,7 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp } dp.apply(); } - deferredProperties.clear(); + this.deferredProperties.clear(); } /** diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ClassPathBeanDefinitionScanner.java b/spring-context/src/main/java/org/springframework/context/annotation/ClassPathBeanDefinitionScanner.java index e766e248802..0a1b0555df7 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ClassPathBeanDefinitionScanner.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ClassPathBeanDefinitionScanner.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,8 +103,7 @@ public class ClassPathBeanDefinitionScanner extends ClassPathScanningCandidateCo * {@link org.springframework.stereotype.Component @Component}, * {@link org.springframework.stereotype.Repository @Repository}, * {@link org.springframework.stereotype.Service @Service}, and - * {@link org.springframework.stereotype.Controller @Controller} stereotype - * annotations. + * {@link org.springframework.stereotype.Controller @Controller} stereotype annotations * @see #setResourceLoader * @see #setEnvironment */ @@ -124,13 +123,12 @@ public class ClassPathBeanDefinitionScanner extends ClassPathScanningCandidateCo * @param registry the {@code BeanFactory} to load bean definitions into, in the form * of a {@code BeanDefinitionRegistry} * @param useDefaultFilters whether to include the default filters for the - * @param environment the Spring {@link Environment} to use when evaluating bean - * definition profile metadata. * {@link org.springframework.stereotype.Component @Component}, * {@link org.springframework.stereotype.Repository @Repository}, * {@link org.springframework.stereotype.Service @Service}, and - * {@link org.springframework.stereotype.Controller @Controller} stereotype - * annotations. + * {@link org.springframework.stereotype.Controller @Controller} stereotype annotations + * @param environment the Spring {@link Environment} to use when evaluating bean + * definition profile metadata * @since 3.1 * @see #setResourceLoader */ diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java b/spring-context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java index 71ebcf03959..86a904810ca 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java @@ -115,6 +115,7 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC if (useDefaultFilters) { registerDefaultFilters(); } + Assert.notNull(environment, "Environment must not be null"); this.environment = environment; } @@ -161,10 +162,11 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC /** * Set the Environment to use when resolving placeholders and evaluating * {@link Conditional @Conditional}-annotated component classes. - *

The default is a {@link StandardEnvironment} + *

The default is a {@link StandardEnvironment}. * @param environment the Environment to use */ public void setEnvironment(Environment environment) { + Assert.notNull(environment, "Environment must not be null"); this.environment = environment; this.conditionEvaluator = null; } diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java index 9d25fe5dfde..6cd5ccf929d 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.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. @@ -78,10 +78,10 @@ public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport private int keepAliveSeconds = 60; - private boolean allowCoreThreadTimeOut = false; - private int queueCapacity = Integer.MAX_VALUE; + private boolean allowCoreThreadTimeOut = false; + private ThreadPoolExecutor threadPoolExecutor; @@ -154,17 +154,6 @@ public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport } } - /** - * Specify whether to allow core threads to time out. This enables dynamic - * growing and shrinking even in combination with a non-zero queue (since - * the max pool size will only grow once the queue is full). - *

Default is "false". - * @see java.util.concurrent.ThreadPoolExecutor#allowCoreThreadTimeOut(boolean) - */ - public void setAllowCoreThreadTimeOut(boolean allowCoreThreadTimeOut) { - this.allowCoreThreadTimeOut = allowCoreThreadTimeOut; - } - /** * Set the capacity for the ThreadPoolExecutor's BlockingQueue. * Default is {@code Integer.MAX_VALUE}. @@ -177,6 +166,17 @@ public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport this.queueCapacity = queueCapacity; } + /** + * Specify whether to allow core threads to time out. This enables dynamic + * growing and shrinking even in combination with a non-zero queue (since + * the max pool size will only grow once the queue is full). + *

Default is "false". + * @see java.util.concurrent.ThreadPoolExecutor#allowCoreThreadTimeOut(boolean) + */ + public void setAllowCoreThreadTimeOut(boolean allowCoreThreadTimeOut) { + this.allowCoreThreadTimeOut = allowCoreThreadTimeOut; + } + @Override protected ExecutorService initializeExecutor( diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/TaskExecutorRegistration.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/TaskExecutorRegistration.java index 35955cd6666..463bf4ed225 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/TaskExecutorRegistration.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/TaskExecutorRegistration.java @@ -18,7 +18,6 @@ package org.springframework.messaging.simp.config; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; - /** * A registration class for customizing the properties of {@link ThreadPoolTaskExecutor}. * @@ -38,13 +37,11 @@ public class TaskExecutorRegistration { /** * Set the core pool size of the ThreadPoolExecutor. - * - *

NOTE: the core pool size is effectively the max pool size + *

NOTE: The core pool size is effectively the max pool size * when an unbounded {@link #queueCapacity(int) queueCapacity} is configured * (the default). This is essentially the "Unbounded queues" strategy as explained * in {@link java.util.concurrent.ThreadPoolExecutor ThreadPoolExecutor}. When * this strategy is used, the {@link #maxPoolSize(int) maxPoolSize} is ignored. - * *

By default this is set to twice the value of * {@link Runtime#availableProcessors()}. In an an application where tasks do not * block frequently, the number should be closer to or equal to the number of @@ -57,13 +54,11 @@ public class TaskExecutorRegistration { /** * Set the max pool size of the ThreadPoolExecutor. - * - *

NOTE: when an unbounded + *

NOTE: When an unbounded * {@link #queueCapacity(int) queueCapacity} is configured (the default), the * max pool size is effectively ignored. See the "Unbounded queues" strategy * in {@link java.util.concurrent.ThreadPoolExecutor ThreadPoolExecutor} for * more details. - * *

By default this is set to {@code Integer.MAX_VALUE}. */ public TaskExecutorRegistration maxPoolSize(int maxPoolSize) { @@ -73,14 +68,11 @@ public class TaskExecutorRegistration { /** * Set the queue capacity for the ThreadPoolExecutor. - * - *

NOTE: when an unbounded - * {@link #queueCapacity(int) queueCapacity} is configured (the default) the - * core pool size is effectively the max pool size. This is essentially the - * "Unbounded queues" strategy as explained in + *

NOTE: when an unbounded {@code queueCapacity} is configured + * (the default), the core pool size is effectively the max pool size. This is + * essentially the "Unbounded queues" strategy as explained in * {@link java.util.concurrent.ThreadPoolExecutor ThreadPoolExecutor}. When * this strategy is used, the {@link #maxPoolSize(int) maxPoolSize} is ignored. - * *

By default this is set to {@code Integer.MAX_VALUE}. */ public TaskExecutorRegistration queueCapacity(int queueCapacity) { @@ -92,8 +84,7 @@ public class TaskExecutorRegistration { * Set the time limit for which threads may remain idle before being terminated. * If there are more than the core number of threads currently in the pool, * after waiting this amount of time without processing a task, excess threads - * will be terminated. This overrides any value set in the constructor. - * + * will be terminated. This overrides any value set in the constructor. *

By default this is set to 60. */ public TaskExecutorRegistration keepAliveSeconds(int keepAliveSeconds) { diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractWebArgumentResolverAdapter.java b/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractWebArgumentResolverAdapter.java index 3a8740026d2..78a3b50806f 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractWebArgumentResolverAdapter.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractWebArgumentResolverAdapter.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. @@ -18,6 +18,7 @@ package org.springframework.web.method.annotation; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.core.MethodParameter; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -47,10 +48,11 @@ import org.springframework.web.method.support.ModelAndViewContainer; */ public abstract class AbstractWebArgumentResolverAdapter implements HandlerMethodArgumentResolver { - private final Log logger = LogFactory.getLog(this.getClass()); + private final Log logger = LogFactory.getLog(getClass()); private final WebArgumentResolver adaptee; + /** * Create a new instance. */ @@ -59,6 +61,7 @@ public abstract class AbstractWebArgumentResolverAdapter implements HandlerMetho this.adaptee = adaptee; } + /** * Actually resolve the value and check the resolved value is not * {@link WebArgumentResolver#UNRESOLVED} absorbing _any_ exceptions. @@ -82,21 +85,14 @@ public abstract class AbstractWebArgumentResolverAdapter implements HandlerMetho } } - /** - * Required for access to NativeWebRequest in {@link #supportsParameter}. - */ - protected abstract NativeWebRequest getWebRequest(); - /** * Delegate to the {@link WebArgumentResolver} instance. * @exception IllegalStateException if the resolved value is not assignable * to the method parameter. */ @Override - public Object resolveArgument( - MethodParameter parameter, ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, WebDataBinderFactory binderFactory) - throws Exception { + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { Class paramType = parameter.getParameterType(); Object result = this.adaptee.resolveArgument(parameter, webRequest); @@ -108,4 +104,11 @@ public abstract class AbstractWebArgumentResolverAdapter implements HandlerMetho } return result; } + + + /** + * Required for access to NativeWebRequest in {@link #supportsParameter}. + */ + protected abstract NativeWebRequest getWebRequest(); + } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/ErrorsMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/ErrorsMethodArgumentResolver.java index bb2b31f6b16..6d9b11cc7ec 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/ErrorsMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/ErrorsMethodArgumentResolver.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. @@ -47,10 +47,8 @@ public class ErrorsMethodArgumentResolver implements HandlerMethodArgumentResolv } @Override - public Object resolveArgument( - MethodParameter parameter, ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, WebDataBinderFactory binderFactory) - throws Exception { + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { ModelMap model = mavContainer.getModel(); if (model.size() > 0) { diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java b/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java index ed8a0c025e5..07effd2c62f 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.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. @@ -44,10 +44,8 @@ public class MapMethodProcessor implements HandlerMethodArgumentResolver, Handle } @Override - public Object resolveArgument( - MethodParameter parameter, ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, WebDataBinderFactory binderFactory) - throws Exception { + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { return mavContainer.getModel(); } @@ -59,10 +57,8 @@ public class MapMethodProcessor implements HandlerMethodArgumentResolver, Handle @Override @SuppressWarnings({ "unchecked", "rawtypes" }) - public void handleReturnValue( - Object returnValue, MethodParameter returnType, - ModelAndViewContainer mavContainer, NativeWebRequest webRequest) - throws Exception { + public void handleReturnValue(Object returnValue, MethodParameter returnType, + ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { if (returnValue == null) { return; @@ -76,4 +72,5 @@ public class MapMethodProcessor implements HandlerMethodArgumentResolver, Handle returnType.getParameterType().getName() + " in method: " + returnType.getMethod()); } } + } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.java b/spring-web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.java index c1bc4138516..fb09148c2a8 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.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. @@ -43,10 +43,8 @@ public class ModelMethodProcessor implements HandlerMethodArgumentResolver, Hand } @Override - public Object resolveArgument( - MethodParameter parameter, ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, WebDataBinderFactory binderFactory) - throws Exception { + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { return mavContainer.getModel(); } @@ -57,10 +55,8 @@ public class ModelMethodProcessor implements HandlerMethodArgumentResolver, Hand } @Override - public void handleReturnValue( - Object returnValue, MethodParameter returnType, - ModelAndViewContainer mavContainer, NativeWebRequest webRequest) - throws Exception { + public void handleReturnValue(Object returnValue, MethodParameter returnType, + ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { if (returnValue == null) { return; @@ -74,4 +70,5 @@ public class ModelMethodProcessor implements HandlerMethodArgumentResolver, Hand returnType.getParameterType().getName() + " in method: " + returnType.getMethod()); } } + } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMapMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMapMethodArgumentResolver.java index 4d0e4d63954..1b8b46fd7c9 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMapMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMapMethodArgumentResolver.java @@ -47,18 +47,15 @@ public class RequestHeaderMapMethodArgumentResolver implements HandlerMethodArgu @Override public boolean supportsParameter(MethodParameter parameter) { - return parameter.hasParameterAnnotation(RequestHeader.class) && - Map.class.isAssignableFrom(parameter.getParameterType()); + return (parameter.hasParameterAnnotation(RequestHeader.class) && + Map.class.isAssignableFrom(parameter.getParameterType())); } @Override - public Object resolveArgument( - MethodParameter parameter, ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, WebDataBinderFactory binderFactory) - throws Exception { + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { Class paramType = parameter.getParameterType(); - if (MultiValueMap.class.isAssignableFrom(paramType)) { MultiValueMap result; if (HttpHeaders.class.isAssignableFrom(paramType)) { diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMapMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMapMethodArgumentResolver.java index 8708e5a5a03..3038be27015 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMapMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMapMethodArgumentResolver.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. @@ -30,13 +30,15 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.ModelAndViewContainer; /** - * Resolves {@link Map} method arguments annotated with an @{@link RequestParam} where the annotation does not - * specify a request parameter name. See {@link RequestParamMethodArgumentResolver} for resolving {@link Map} + * Resolves {@link Map} method arguments annotated with an @{@link RequestParam} + * where the annotation does not specify a request parameter name. + * See {@link RequestParamMethodArgumentResolver} for resolving {@link Map} * method arguments with a request parameter name. * - *

The created {@link Map} contains all request parameter name/value pairs. If the method parameter type - * is {@link MultiValueMap} instead, the created map contains all request parameters and all there values for - * cases where request parameters have multiple values. + *

The created {@link Map} contains all request parameter name/value pairs. + * If the method parameter type is {@link MultiValueMap} instead, the created + * map contains all request parameters and all there values for cases where + * request parameters have multiple values. * * @author Arjen Poutsma * @author Rossen Stoyanchev @@ -47,20 +49,18 @@ public class RequestParamMapMethodArgumentResolver implements HandlerMethodArgum @Override public boolean supportsParameter(MethodParameter parameter) { - RequestParam requestParamAnnot = parameter.getParameterAnnotation(RequestParam.class); - if (requestParamAnnot != null) { + RequestParam ann = parameter.getParameterAnnotation(RequestParam.class); + if (ann != null) { if (Map.class.isAssignableFrom(parameter.getParameterType())) { - return !StringUtils.hasText(requestParamAnnot.value()); + return !StringUtils.hasText(ann.value()); } } return false; } @Override - public Object resolveArgument( - MethodParameter parameter, ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, WebDataBinderFactory binderFactory) - throws Exception { + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { Class paramType = parameter.getParameterType(); diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/SessionStatusMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/SessionStatusMethodArgumentResolver.java index c9ae58b6478..1e4dedf7707 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/SessionStatusMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/SessionStatusMethodArgumentResolver.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. @@ -38,10 +38,8 @@ public class SessionStatusMethodArgumentResolver implements HandlerMethodArgumen } @Override - public Object resolveArgument( - MethodParameter parameter, ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, WebDataBinderFactory binderFactory) - throws Exception { + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { return mavContainer.getSessionStatus(); } diff --git a/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolver.java index 57823245fee..c5cd168156e 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolver.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. @@ -27,6 +27,7 @@ import org.springframework.web.context.request.NativeWebRequest; * * @author Arjen Poutsma * @since 3.1 + * @see HandlerMethodReturnValueHandler */ public interface HandlerMethodArgumentResolver { @@ -46,13 +47,12 @@ public interface HandlerMethodArgumentResolver { * a {@link WebDataBinder} instance when needed for data binding and * type conversion purposes. * @param parameter the method parameter to resolve. This parameter must - * have previously been passed to - * {@link #supportsParameter(org.springframework.core.MethodParameter)} - * and it must have returned {@code true} + * have previously been passed to {@link #supportsParameter} which must + * have returned {@code true}. * @param mavContainer the ModelAndViewContainer for the current request * @param webRequest the current request * @param binderFactory a factory for creating {@link WebDataBinder} instances - * @return the resolved argument value, or {@code null}. + * @return the resolved argument value, or {@code null} * @throws Exception in case of errors with the preparation of argument values */ Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, diff --git a/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolverComposite.java b/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolverComposite.java index 6fa290d05d9..9d7ba31a2e9 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolverComposite.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolverComposite.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. @@ -66,13 +66,11 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu /** * Iterate over registered {@link HandlerMethodArgumentResolver}s and invoke the one that supports it. - * @exception IllegalStateException if no suitable {@link HandlerMethodArgumentResolver} is found. + * @throws IllegalStateException if no suitable {@link HandlerMethodArgumentResolver} is found. */ @Override - public Object resolveArgument( - MethodParameter parameter, ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, WebDataBinderFactory binderFactory) - throws Exception { + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { HandlerMethodArgumentResolver resolver = getArgumentResolver(parameter); Assert.notNull(resolver, "Unknown parameter type [" + parameter.getParameterType().getName() + "]"); @@ -103,18 +101,17 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu /** * Add the given {@link HandlerMethodArgumentResolver}. */ - public HandlerMethodArgumentResolverComposite addResolver(HandlerMethodArgumentResolver argumentResolver) { - this.argumentResolvers.add(argumentResolver); + public HandlerMethodArgumentResolverComposite addResolver(HandlerMethodArgumentResolver resolver) { + this.argumentResolvers.add(resolver); return this; } /** * Add the given {@link HandlerMethodArgumentResolver}s. */ - public HandlerMethodArgumentResolverComposite addResolvers( - List argumentResolvers) { - if (argumentResolvers != null) { - for (HandlerMethodArgumentResolver resolver : argumentResolvers) { + public HandlerMethodArgumentResolverComposite addResolvers(List resolvers) { + if (resolvers != null) { + for (HandlerMethodArgumentResolver resolver : resolvers) { this.argumentResolvers.add(resolver); } } diff --git a/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandler.java b/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandler.java index 55ee1e30a8c..0e9b03b0a7c 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandler.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandler.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. @@ -25,6 +25,7 @@ import org.springframework.web.context.request.NativeWebRequest; * * @author Arjen Poutsma * @since 3.1 + * @see HandlerMethodArgumentResolver */ public interface HandlerMethodReturnValueHandler { @@ -44,9 +45,8 @@ public interface HandlerMethodReturnValueHandler { * to indicate the response has been handled directly. * @param returnValue the value returned from the handler method * @param returnType the type of the return value. This type must have - * previously been passed to - * {@link #supportsReturnType(org.springframework.core.MethodParameter)} - * and it must have returned {@code true} + * previously been passed to {@link #supportsReturnType} which must + * have returned {@code true}. * @param mavContainer the ModelAndViewContainer for the current request * @param webRequest the current request * @throws Exception if the return value handling results in an error diff --git a/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerComposite.java b/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerComposite.java index 991c5ef73ea..5f57fcda2bc 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerComposite.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerComposite.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. @@ -22,6 +22,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.core.MethodParameter; import org.springframework.util.Assert; import org.springframework.web.context.request.NativeWebRequest; @@ -40,6 +41,7 @@ public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodRe private final List returnValueHandlers = new ArrayList(); + /** * Return a read-only list with the registered handlers, or an empty list. */ @@ -58,13 +60,11 @@ public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodRe /** * Iterate over registered {@link HandlerMethodReturnValueHandler}s and invoke the one that supports it. - * @exception IllegalStateException if no suitable {@link HandlerMethodReturnValueHandler} is found. + * @throws IllegalStateException if no suitable {@link HandlerMethodReturnValueHandler} is found. */ @Override - public void handleReturnValue( - Object returnValue, MethodParameter returnType, - ModelAndViewContainer mavContainer, NativeWebRequest webRequest) - throws Exception { + public void handleReturnValue(Object returnValue, MethodParameter returnType, + ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { HandlerMethodReturnValueHandler handler = getReturnValueHandler(returnType); Assert.notNull(handler, "Unknown return value type [" + returnType.getParameterType().getName() + "]"); @@ -90,18 +90,17 @@ public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodRe /** * Add the given {@link HandlerMethodReturnValueHandler}. */ - public HandlerMethodReturnValueHandlerComposite addHandler(HandlerMethodReturnValueHandler returnValuehandler) { - returnValueHandlers.add(returnValuehandler); + public HandlerMethodReturnValueHandlerComposite addHandler(HandlerMethodReturnValueHandler handler) { + returnValueHandlers.add(handler); return this; } /** * Add the given {@link HandlerMethodReturnValueHandler}s. */ - public HandlerMethodReturnValueHandlerComposite addHandlers( - List returnValueHandlers) { - if (returnValueHandlers != null) { - for (HandlerMethodReturnValueHandler handler : returnValueHandlers) { + public HandlerMethodReturnValueHandlerComposite addHandlers(List handlers) { + if (handlers != null) { + for (HandlerMethodReturnValueHandler handler : handlers) { this.returnValueHandlers.add(handler); } } diff --git a/spring-web/src/main/java/org/springframework/web/method/support/ModelAndViewContainer.java b/spring-web/src/main/java/org/springframework/web/method/support/ModelAndViewContainer.java index 721ccf0bf6d..2e5f8147ed4 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/ModelAndViewContainer.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/ModelAndViewContainer.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. @@ -58,11 +58,6 @@ public class ModelAndViewContainer { private final SessionStatus sessionStatus = new SimpleSessionStatus(); - /** - * Create a new instance. - */ - public ModelAndViewContainer() { - } /** * Set a view name to be resolved by the DispatcherServlet via a ViewResolver. @@ -145,7 +140,7 @@ public class ModelAndViewContainer { * Whether to use the default model or the redirect model. */ private boolean useDefaultModel() { - return !this.redirectModelScenario || ((this.redirectModel == null) && !this.ignoreDefaultModelOnRedirect); + return (!this.redirectModelScenario || (this.redirectModel == null && !this.ignoreDefaultModelOnRedirect)); } /** @@ -183,7 +178,7 @@ public class ModelAndViewContainer { * signal that session processing is complete. */ public SessionStatus getSessionStatus() { - return sessionStatus; + return this.sessionStatus; } /** @@ -243,6 +238,7 @@ public class ModelAndViewContainer { return getModel().containsAttribute(name); } + /** * Return diagnostic information. */ diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AsyncTaskMethodReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AsyncTaskMethodReturnValueHandler.java index 1c4f3e3933c..88c7c04c0dd 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AsyncTaskMethodReturnValueHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AsyncTaskMethodReturnValueHandler.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. @@ -39,16 +39,15 @@ public class AsyncTaskMethodReturnValueHandler implements HandlerMethodReturnVal this.beanFactory = beanFactory; } + @Override public boolean supportsReturnType(MethodParameter returnType) { - Class paramType = returnType.getParameterType(); - return WebAsyncTask.class.isAssignableFrom(paramType); + return WebAsyncTask.class.isAssignableFrom(returnType.getParameterType()); } @Override - public void handleReturnValue(Object returnValue, - MethodParameter returnType, ModelAndViewContainer mavContainer, - NativeWebRequest webRequest) throws Exception { + public void handleReturnValue(Object returnValue, MethodParameter returnType, + ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { if (returnValue == null) { mavContainer.setRequestHandled(true); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/CallableMethodReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/CallableMethodReturnValueHandler.java index 7da354795ce..a38c05bdab9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/CallableMethodReturnValueHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/CallableMethodReturnValueHandler.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. @@ -34,14 +34,12 @@ public class CallableMethodReturnValueHandler implements HandlerMethodReturnValu @Override public boolean supportsReturnType(MethodParameter returnType) { - Class paramType = returnType.getParameterType(); - return Callable.class.isAssignableFrom(paramType); + return Callable.class.isAssignableFrom(returnType.getParameterType()); } @Override - public void handleReturnValue(Object returnValue, - MethodParameter returnType, ModelAndViewContainer mavContainer, - NativeWebRequest webRequest) throws Exception { + public void handleReturnValue(Object returnValue, MethodParameter returnType, + ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { if (returnValue == null) { mavContainer.setRequestHandled(true); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultMethodReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultMethodReturnValueHandler.java index 5f10dfa8912..3b66aec9355 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultMethodReturnValueHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultMethodReturnValueHandler.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. @@ -18,8 +18,8 @@ package org.springframework.web.servlet.mvc.method.annotation; import org.springframework.core.MethodParameter; import org.springframework.web.context.request.NativeWebRequest; -import org.springframework.web.context.request.async.WebAsyncUtils; import org.springframework.web.context.request.async.DeferredResult; +import org.springframework.web.context.request.async.WebAsyncUtils; import org.springframework.web.method.support.HandlerMethodReturnValueHandler; import org.springframework.web.method.support.ModelAndViewContainer; @@ -33,14 +33,12 @@ public class DeferredResultMethodReturnValueHandler implements HandlerMethodRetu @Override public boolean supportsReturnType(MethodParameter returnType) { - Class paramType = returnType.getParameterType(); - return DeferredResult.class.isAssignableFrom(paramType); + return DeferredResult.class.isAssignableFrom(returnType.getParameterType()); } @Override - public void handleReturnValue(Object returnValue, - MethodParameter returnType, ModelAndViewContainer mavContainer, - NativeWebRequest webRequest) throws Exception { + public void handleReturnValue(Object returnValue, MethodParameter returnType, + ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { if (returnValue == null) { mavContainer.setRequestHandled(true); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java index cecae308fd5..c85f1b0bc77 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.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. @@ -48,10 +48,8 @@ public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturn } @Override - public void handleReturnValue( - Object returnValue, MethodParameter returnType, - ModelAndViewContainer mavContainer, NativeWebRequest webRequest) - throws Exception { + public void handleReturnValue(Object returnValue, MethodParameter returnType, + ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { if (returnValue == null) { mavContainer.setRequestHandled(true); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandler.java index ee04263dc34..7347fd61bc1 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandler.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. @@ -57,6 +57,7 @@ public class ModelAndViewResolverMethodReturnValueHandler implements HandlerMeth private final ModelAttributeMethodProcessor modelAttributeProcessor = new ModelAttributeMethodProcessor(true); + /** * Create a new instance. */ @@ -64,6 +65,7 @@ public class ModelAndViewResolverMethodReturnValueHandler implements HandlerMeth this.mavResolvers = mavResolvers; } + /** * Always returns {@code true}. See class-level note. */ @@ -73,17 +75,15 @@ public class ModelAndViewResolverMethodReturnValueHandler implements HandlerMeth } @Override - public void handleReturnValue( - Object returnValue, MethodParameter returnType, - ModelAndViewContainer mavContainer, NativeWebRequest request) - throws Exception { + public void handleReturnValue(Object returnValue, MethodParameter returnType, + ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { if (this.mavResolvers != null) { for (ModelAndViewResolver mavResolver : this.mavResolvers) { Class handlerType = returnType.getContainingClass(); Method method = returnType.getMethod(); ExtendedModelMap model = (ExtendedModelMap) mavContainer.getModel(); - ModelAndView mav = mavResolver.resolveModelAndView(method, handlerType, returnValue, model, request); + ModelAndView mav = mavResolver.resolveModelAndView(method, handlerType, returnValue, model, webRequest); if (mav != ModelAndViewResolver.UNRESOLVED) { mavContainer.addAllAttributes(mav.getModel()); mavContainer.setViewName(mav.getViewName()); @@ -97,7 +97,7 @@ public class ModelAndViewResolverMethodReturnValueHandler implements HandlerMeth // No suitable ModelAndViewResolver... if (this.modelAttributeProcessor.supportsReturnType(returnType)) { - this.modelAttributeProcessor.handleReturnValue(returnValue, returnType, mavContainer, request); + this.modelAttributeProcessor.handleReturnValue(returnValue, returnType, mavContainer, webRequest); } else { throw new UnsupportedOperationException("Unexpected return type: " + diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolver.java index 2726da4378e..2fc6f46e5ff 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolver.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. @@ -44,9 +44,9 @@ public class PathVariableMapMethodArgumentResolver implements HandlerMethodArgum @Override public boolean supportsParameter(MethodParameter parameter) { - PathVariable annot = parameter.getParameterAnnotation(PathVariable.class); - return ((annot != null) && (Map.class.isAssignableFrom(parameter.getParameterType())) - && (!StringUtils.hasText(annot.value()))); + PathVariable ann = parameter.getParameterAnnotation(PathVariable.class); + return (ann != null && (Map.class.isAssignableFrom(parameter.getParameterType())) + && !StringUtils.hasText(ann.value())); } /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RedirectAttributesMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RedirectAttributesMethodArgumentResolver.java index 9cf3a73189f..a4126f5e397 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RedirectAttributesMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RedirectAttributesMethodArgumentResolver.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. @@ -32,10 +32,12 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; /** * Resolves method arguments of type {@link RedirectAttributes}. * - *

This resolver must be listed ahead of {@link org.springframework.web.method.annotation.ModelMethodProcessor} and - * {@link org.springframework.web.method.annotation.MapMethodProcessor}, which support {@link Map} and {@link Model} - * arguments both of which are "super" types of {@code RedirectAttributes} - * and would also attempt to resolve a {@code RedirectAttributes} argument. + *

This resolver must be listed ahead of + * {@link org.springframework.web.method.annotation.ModelMethodProcessor} and + * {@link org.springframework.web.method.annotation.MapMethodProcessor}, + * which support {@link Map} and {@link Model} arguments both of which are + * "super" types of {@code RedirectAttributes} and would also attempt to + * resolve a {@code RedirectAttributes} argument. * * @author Rossen Stoyanchev * @since 3.1 @@ -48,10 +50,8 @@ public class RedirectAttributesMethodArgumentResolver implements HandlerMethodAr } @Override - public Object resolveArgument( - MethodParameter parameter, ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, WebDataBinderFactory binderFactory) - throws Exception { + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { DataBinder dataBinder = binderFactory.createBinder(webRequest, null, null); ModelMap redirectAttributes = new RedirectAttributesModelMap(dataBinder); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.java index bc226326e9e..ca1316c03a6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.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. @@ -73,6 +73,7 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter super(messageConverters, contentNegotiationManager); } + @Override public boolean supportsParameter(MethodParameter parameter) { return parameter.hasParameterAnnotation(RequestBody.class); @@ -80,12 +81,11 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter @Override public boolean supportsReturnType(MethodParameter returnType) { - return ((AnnotationUtils.findAnnotation(returnType.getContainingClass(), ResponseBody.class) != null) || - (returnType.getMethodAnnotation(ResponseBody.class) != null)); + return (AnnotationUtils.findAnnotation(returnType.getContainingClass(), ResponseBody.class) != null || + returnType.getMethodAnnotation(ResponseBody.class) != null); } /** - * {@inheritDoc} * @throws MethodArgumentNotValidException if validation fails * @throws HttpMessageNotReadableException if {@link RequestBody#required()} * is {@code true} and there is no body content or if there is no suitable @@ -96,25 +96,20 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { Object argument = readWithMessageConverters(webRequest, parameter, parameter.getGenericParameterType()); - String name = Conventions.getVariableNameForParameter(parameter); WebDataBinder binder = binderFactory.createBinder(webRequest, argument, name); - if (argument != null) { validate(binder, parameter); } - mavContainer.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, binder.getBindingResult()); - return argument; } - private void validate(WebDataBinder binder, MethodParameter parameter) throws Exception, MethodArgumentNotValidException { - + private void validate(WebDataBinder binder, MethodParameter parameter) throws Exception { Annotation[] annotations = parameter.getParameterAnnotations(); - for (Annotation annot : annotations) { - if (annot.annotationType().getSimpleName().startsWith("Valid")) { - Object hints = AnnotationUtils.getValue(annot); + for (Annotation ann : annotations) { + if (ann.annotationType().getSimpleName().startsWith("Valid")) { + Object hints = AnnotationUtils.getValue(ann); binder.validate(hints instanceof Object[] ? (Object[]) hints : new Object[] {hints}); BindingResult bindingResult = binder.getBindingResult(); if (bindingResult.hasErrors()) { @@ -148,8 +143,8 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter final HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class); HttpInputMessage inputMessage = new ServletServerHttpRequest(servletRequest); - RequestBody annot = methodParam.getParameterAnnotation(RequestBody.class); - if (!annot.required()) { + RequestBody ann = methodParam.getParameterAnnotation(RequestBody.class); + if (!ann.required()) { InputStream inputStream = inputMessage.getBody(); if (inputStream == null) { return null; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessor.java index 3cfd087e334..e17eec5cbfe 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessor.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. @@ -18,7 +18,6 @@ package org.springframework.web.servlet.mvc.method.annotation; import java.util.Collections; import java.util.Map; - import javax.servlet.ServletRequest; import org.springframework.core.MethodParameter; @@ -36,7 +35,7 @@ import org.springframework.web.method.annotation.ModelAttributeMethodProcessor; import org.springframework.web.servlet.HandlerMapping; /** - * A Servlet-specific {@link org.springframework.web.method.annotation.ModelAttributeMethodProcessor} that applies data + * A Servlet-specific {@link ModelAttributeMethodProcessor} that applies data * binding through a WebDataBinder of type {@link ServletRequestDataBinder}. * *

Also adds a fall-back strategy to instantiate the model attribute from a @@ -57,6 +56,7 @@ public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodPr super(annotationNotRequired); } + /** * Instantiate the model attribute from a URI template variable or from a * request parameter if the name matches to the model attribute name and @@ -65,10 +65,8 @@ public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodPr * @see #createAttributeFromRequestValue(String, String, MethodParameter, WebDataBinderFactory, NativeWebRequest) */ @Override - protected final Object createAttribute(String attributeName, - MethodParameter parameter, - WebDataBinderFactory binderFactory, - NativeWebRequest request) throws Exception { + protected final Object createAttribute(String attributeName, MethodParameter parameter, + WebDataBinderFactory binderFactory, NativeWebRequest request) throws Exception { String value = getRequestValueForAttribute(attributeName, request); if (value != null) { @@ -106,9 +104,9 @@ public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodPr @SuppressWarnings("unchecked") protected final Map getUriTemplateVariables(NativeWebRequest request) { Map variables = - (Map) request.getAttribute( - HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST); - return (variables != null) ? variables : Collections.emptyMap(); + (Map) request.getAttribute( + HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST); + return (variables != null ? variables : Collections.emptyMap()); } /** @@ -124,11 +122,10 @@ public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodPr * @return the created model attribute, or {@code null} * @throws Exception */ - protected Object createAttributeFromRequestValue(String sourceValue, - String attributeName, - MethodParameter parameter, - WebDataBinderFactory binderFactory, - NativeWebRequest request) throws Exception { + protected Object createAttributeFromRequestValue(String sourceValue, String attributeName, + MethodParameter parameter, WebDataBinderFactory binderFactory, NativeWebRequest request) + throws Exception { + DataBinder binder = binderFactory.createBinder(request, null, attributeName); ConversionService conversionService = binder.getConversionService(); if (conversionService != null) { @@ -142,8 +139,8 @@ public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodPr } /** - * {@inheritDoc} - *

Downcast {@link WebDataBinder} to {@link ServletRequestDataBinder} before binding. + * This implementation downcasts {@link WebDataBinder} to + * {@link ServletRequestDataBinder} before binding. * @see ServletRequestDataBinderFactory */ @Override diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java index fefc115c2e1..b52e5033503 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java @@ -16,7 +16,6 @@ package org.springframework.web.servlet.mvc.method.annotation; -import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.security.Principal; @@ -64,7 +63,7 @@ public class ServletRequestMethodArgumentResolver implements HandlerMethodArgume @Override public boolean supportsParameter(MethodParameter parameter) { Class paramType = parameter.getParameterType(); - return WebRequest.class.isAssignableFrom(paramType) || + return (WebRequest.class.isAssignableFrom(paramType) || ServletRequest.class.isAssignableFrom(paramType) || MultipartRequest.class.isAssignableFrom(paramType) || HttpSession.class.isAssignableFrom(paramType) || @@ -74,14 +73,12 @@ public class ServletRequestMethodArgumentResolver implements HandlerMethodArgume "java.time.ZoneId".equals(paramType.getName()) || InputStream.class.isAssignableFrom(paramType) || Reader.class.isAssignableFrom(paramType) || - HttpMethod.class.equals(paramType); + HttpMethod.class.equals(paramType)); } @Override - public Object resolveArgument( - MethodParameter parameter, ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, WebDataBinderFactory binderFactory) - throws IOException { + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { Class paramType = parameter.getParameterType(); if (WebRequest.class.isAssignableFrom(paramType)) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletResponseMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletResponseMethodArgumentResolver.java index 11e97e8660b..2818dc529b1 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletResponseMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletResponseMethodArgumentResolver.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. @@ -16,11 +16,9 @@ package org.springframework.web.servlet.mvc.method.annotation; -import java.io.IOException; import java.io.OutputStream; import java.io.Writer; import java.lang.reflect.Method; - import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletResponse; @@ -47,9 +45,9 @@ public class ServletResponseMethodArgumentResolver implements HandlerMethodArgum @Override public boolean supportsParameter(MethodParameter parameter) { Class paramType = parameter.getParameterType(); - return ServletResponse.class.isAssignableFrom(paramType) - || OutputStream.class.isAssignableFrom(paramType) - || Writer.class.isAssignableFrom(paramType); + return (ServletResponse.class.isAssignableFrom(paramType) || + OutputStream.class.isAssignableFrom(paramType) || + Writer.class.isAssignableFrom(paramType)); } /** @@ -59,10 +57,8 @@ public class ServletResponseMethodArgumentResolver implements HandlerMethodArgum * {@code null}, the request is considered directly handled. */ @Override - public Object resolveArgument( - MethodParameter parameter, ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, WebDataBinderFactory binderFactory) - throws IOException { + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { if (mavContainer != null) { mavContainer.setRequestHandled(true); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolver.java index a1800c28580..74e632f2a9b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolver.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. @@ -43,10 +43,8 @@ public class UriComponentsBuilderMethodArgumentResolver implements HandlerMethod } @Override - public Object resolveArgument( - MethodParameter parameter, ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, WebDataBinderFactory binderFactory) - throws Exception { + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); return ServletUriComponentsBuilder.fromServletMapping(request); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandler.java index e68d91273ea..d9d8abd23b9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandler.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. @@ -46,10 +46,8 @@ public class ViewMethodReturnValueHandler implements HandlerMethodReturnValueHan } @Override - public void handleReturnValue( - Object returnValue, MethodParameter returnType, - ModelAndViewContainer mavContainer, NativeWebRequest webRequest) - throws Exception { + public void handleReturnValue(Object returnValue, MethodParameter returnType, + ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { if (returnValue == null) { return; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandler.java index d4ffdb80597..21c35c9c59a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandler.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. @@ -47,10 +47,8 @@ public class ViewNameMethodReturnValueHandler implements HandlerMethodReturnValu } @Override - public void handleReturnValue( - Object returnValue, MethodParameter returnType, - ModelAndViewContainer mavContainer, NativeWebRequest webRequest) - throws Exception { + public void handleReturnValue(Object returnValue, MethodParameter returnType, + ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { if (returnValue == null) { return; diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java index 87731d3f898..1716b32d890 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.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. @@ -1568,7 +1568,6 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl @Test public void restController() throws Exception { - initServletWithControllers(ThisWillActuallyRun.class); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); @@ -3039,7 +3038,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl } -// Test cases deleted from the original SevletAnnotationControllerTests: +// Test cases deleted from the original ServletAnnotationControllerTests: // @Ignore("Controller interface => no method-level @RequestMapping annotation") // public void standardHandleMethod() throws Exception {