diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java index cbf434d4c0..04601a4d47 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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,13 +39,13 @@ import org.springframework.web.method.support.ModelAndViewContainer; /** * Resolves {@link HttpEntity} method argument values and also handles - * both {@link HttpEntity} and {@link ResponseEntity} return values. - * - *
An {@link HttpEntity} return type has a set purpose. Therefore this - * handler should be configured ahead of handlers that support any return + * both {@link HttpEntity} and {@link ResponseEntity} return values. + * + *
An {@link HttpEntity} return type has a set purpose. Therefore this + * handler should be configured ahead of handlers that support any return * value type annotated with {@code @ModelAttribute} or {@code @ResponseBody} * to ensure they don't take over. - * + * * @author Arjen Poutsma * @author Rossen Stoyanchev * @since 3.1 @@ -66,10 +66,9 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro return HttpEntity.class.equals(parameterType) || ResponseEntity.class.equals(parameterType); } - public Object resolveArgument(MethodParameter parameter, - ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, - WebDataBinderFactory binderFactory) + public Object resolveArgument( + MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws IOException, HttpMediaTypeNotSupportedException { HttpInputMessage inputMessage = createInputMessage(webRequest); @@ -100,11 +99,11 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro + "in method " + parameter.getMethod() + "is not parameterized"); } - 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 { + mavContainer.setRequestHandled(true); if (returnValue == null) { @@ -135,4 +134,4 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro } } -} \ No newline at end of file +} diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java index b5494f5061..cca424048e 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java @@ -25,15 +25,15 @@ import org.springframework.web.servlet.SmartView; import org.springframework.web.servlet.View; /** - * Handles return values of type {@link ModelAndView} copying view and model + * Handles return values of type {@link ModelAndView} copying view and model * information to the {@link ModelAndViewContainer}. - * - *
If the return value is {@code null}, the - * {@link ModelAndViewContainer#setRequestHandled(boolean)} flag is set to + * + *
If the return value is {@code null}, the + * {@link ModelAndViewContainer#setRequestHandled(boolean)} flag is set to * {@code false} to indicate the request was handled directly. - * - *
A {@link ModelAndView} return type has a set purpose. Therefore this - * handler should be configured ahead of handlers that support any return + * + *
A {@link ModelAndView} return type has a set purpose. Therefore this + * handler should be configured ahead of handlers that support any return * value type annotated with {@code @ModelAttribute} or {@code @ResponseBody} * to ensure they don't take over. * @@ -41,20 +41,21 @@ import org.springframework.web.servlet.View; * @since 3.1 */ public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturnValueHandler { - + public boolean supportsReturnType(MethodParameter returnType) { return ModelAndView.class.isAssignableFrom(returnType.getParameterType()); } - 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); return; } - + ModelAndView mav = (ModelAndView) returnValue; if (mav.isReference()) { String viewName = mav.getViewName(); @@ -75,4 +76,4 @@ public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturn mavContainer.addAllAttributes(mav.getModel()); } -} \ No newline at end of file +} diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandler.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandler.java index 121ad3ecc0..d1ede55c57 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandler.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -29,25 +29,25 @@ import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver; /** - * This return value handler is intended to be ordered after all others as it + * This return value handler is intended to be ordered after all others as it * attempts to handle _any_ return value type (i.e. returns {@code true} for * all return types). - * + * *
The return value is handled either with a {@link ModelAndViewResolver} - * or otherwise by regarding it as a model attribute if it is a non-simple - * type. If neither of these succeeds (essentially simple type other than + * or otherwise by regarding it as a model attribute if it is a non-simple + * type. If neither of these succeeds (essentially simple type other than * String), {@link UnsupportedOperationException} is raised. - * - *
Note: This class is primarily needed to support + * + *
Note: This class is primarily needed to support * {@link ModelAndViewResolver}, which unfortunately cannot be properly - * adapted to the {@link HandlerMethodReturnValueHandler} contract since the + * adapted to the {@link HandlerMethodReturnValueHandler} contract since the * {@link HandlerMethodReturnValueHandler#supportsReturnType} method * cannot be implemented. Hence {@code ModelAndViewResolver}s are limited - * to always being invoked at the end after all other return value - * handlers have been given a chance. It is recommended to re-implement + * to always being invoked at the end after all other return value + * handlers have been given a chance. It is recommended to re-implement * a {@code ModelAndViewResolver} as {@code HandlerMethodReturnValueHandler}, * which also provides better access to the return type and method information. - * + * * @author Rossen Stoyanchev * @since 3.1 */ @@ -71,10 +71,10 @@ public class ModelAndViewResolverMethodReturnValueHandler implements HandlerMeth return true; } - public void handleReturnValue(Object returnValue, - MethodParameter returnType, - ModelAndViewContainer mavContainer, - NativeWebRequest request) throws Exception { + public void handleReturnValue( + Object returnValue, MethodParameter returnType, + ModelAndViewContainer mavContainer, NativeWebRequest request) + throws Exception { if (this.mavResolvers != null) { for (ModelAndViewResolver mavResolver : this.mavResolvers) { @@ -93,7 +93,7 @@ public class ModelAndViewResolverMethodReturnValueHandler implements HandlerMeth } } - // No suitable ModelAndViewResolver.. + // No suitable ModelAndViewResolver.. if (this.modelAttributeProcessor.supportsReturnType(returnType)) { this.modelAttributeProcessor.handleReturnValue(returnValue, returnType, mavContainer, request); @@ -104,4 +104,4 @@ public class ModelAndViewResolverMethodReturnValueHandler implements HandlerMeth } } -} \ No newline at end of file +} diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RedirectAttributesMethodArgumentResolver.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RedirectAttributesMethodArgumentResolver.java index 272ab04ff9..89d4849c3d 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RedirectAttributesMethodArgumentResolver.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RedirectAttributesMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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,8 +30,8 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes; import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; /** - * Resolves method arguments of type {@link RedirectAttributes}. - * + * 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} @@ -46,10 +46,11 @@ public class RedirectAttributesMethodArgumentResolver implements HandlerMethodAr return RedirectAttributes.class.isAssignableFrom(parameter.getParameterType()); } - 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); mavContainer.setRedirectModel(redirectAttributes); diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java index 348be0654a..3eb3261fb7 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -89,9 +89,9 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod { * @param mavContainer the {@link ModelAndViewContainer} for the current request * @param providedArgs argument values to try to use without the need for view resolution */ - public final void invokeAndHandle(NativeWebRequest request, - ModelAndViewContainer mavContainer, - Object...providedArgs) throws Exception { + public final void invokeAndHandle( + NativeWebRequest request, ModelAndViewContainer mavContainer, + Object... providedArgs) throws Exception { Object returnValue = invokeForRequest(request, mavContainer, providedArgs); @@ -124,7 +124,7 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod { sb.append("[value=" + returnValue + "]"); return getDetailedErrorMessage(sb.toString()); } - + /** * Set the response status according to the {@link ResponseStatus} annotation. */ @@ -157,4 +157,4 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod { private boolean hasResponseStatus() { return responseStatus != null; } -} \ No newline at end of file +} diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java index 6976861adb..a6e9f7f933 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -37,7 +37,7 @@ import org.springframework.web.multipart.MultipartRequest; import org.springframework.web.servlet.support.RequestContextUtils; /** - * Resolves request-related method argument values of the following types: + * Resolves request-related method argument values of the following types: *
The returned instance is initialized via * {@link ServletUriComponentsBuilder#fromServletMapping(HttpServletRequest)}. * @@ -41,11 +41,11 @@ public class UriComponentsBuilderMethodArgumentResolver implements HandlerMethod return UriComponentsBuilder.class.isAssignableFrom(parameter.getParameterType()); } - 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/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandler.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandler.java index 88a1b4d28e..de6a387330 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandler.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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,14 +27,14 @@ import org.springframework.web.servlet.View; /** * Handles return values that are of type {@link View}. * - *
A {@code null} return value is left as-is leaving it to the configured - * {@link RequestToViewNameTranslator} to select a view name by convention. + *
A {@code null} return value is left as-is leaving it to the configured + * {@link RequestToViewNameTranslator} to select a view name by convention. * - *
A {@link View} return type has a set purpose. Therefore this handler - * should be configured ahead of handlers that support any return value type + *
A {@link View} return type has a set purpose. Therefore this handler + * should be configured ahead of handlers that support any return value type * annotated with {@code @ModelAttribute} or {@code @ResponseBody} to ensure * they don't take over. - * + * * @author Rossen Stoyanchev * @since 3.1 */ @@ -44,10 +44,11 @@ public class ViewMethodReturnValueHandler implements HandlerMethodReturnValueHan return View.class.isAssignableFrom(returnType.getParameterType()); } - 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; } @@ -62,7 +63,7 @@ public class ViewMethodReturnValueHandler implements HandlerMethodReturnValueHan } else { // should not happen - throw new UnsupportedOperationException("Unexpected return type: " + + throw new UnsupportedOperationException("Unexpected return type: " + returnType.getParameterType().getName() + " in method: " + returnType.getMethod()); } } diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandler.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandler.java index aa7dc816f0..153486abb5 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandler.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -26,12 +26,12 @@ import org.springframework.web.servlet.RequestToViewNameTranslator; * Handles return values of types {@code void} and {@code String} interpreting * them as view name reference. * - *
A {@code null} return value, either due to a {@code void} return type or - * as the actual return value is left as-is allowing the configured + *
A {@code null} return value, either due to a {@code void} return type or + * as the actual return value is left as-is allowing the configured * {@link RequestToViewNameTranslator} to select a view name by convention. * - *
A String return value can be interpreted in more than one ways depending - * on the presence of annotations like {@code @ModelAttribute} or + *
A String return value can be interpreted in more than one ways depending + * on the presence of annotations like {@code @ModelAttribute} or * {@code @ResponseBody}. Therefore this handler should be configured after * the handlers that support these annotations. * @@ -45,10 +45,11 @@ public class ViewNameMethodReturnValueHandler implements HandlerMethodReturnValu return (void.class.equals(paramType) || String.class.equals(paramType)); } - 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; } @@ -61,7 +62,7 @@ public class ViewNameMethodReturnValueHandler implements HandlerMethodReturnValu } else { // should not happen - throw new UnsupportedOperationException("Unexpected return type: " + + throw new UnsupportedOperationException("Unexpected return type: " + returnType.getParameterType().getName() + " in method: " + returnType.getMethod()); } } @@ -69,7 +70,7 @@ public class ViewNameMethodReturnValueHandler implements HandlerMethodReturnValu /** * Whether the given view name is a redirect view reference. * @param viewName the view name to check, never {@code null} - * @return "true" if the given view name is recognized as a redirect view + * @return "true" if the given view name is recognized as a redirect view * reference; "false" otherwise. */ protected boolean isRedirectViewName(String viewName) { diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandlerTests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandlerTests.java index cfec145354..ee9ccea252 100644 --- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandlerTests.java +++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandlerTests.java @@ -37,7 +37,7 @@ import org.springframework.web.servlet.view.RedirectView; /** * Test fixture with {@link ModelAndViewMethodReturnValueHandler}. - * + * * @author Rossen Stoyanchev */ public class ModelAndViewMethodReturnValueHandlerTests { @@ -57,7 +57,7 @@ public class ModelAndViewMethodReturnValueHandlerTests { this.webRequest = new ServletWebRequest(new MockHttpServletRequest()); this.returnParamModelAndView = getReturnValueParam("modelAndView"); } - + @Test public void supportsReturnType() throws Exception { assertTrue(handler.supportsReturnType(returnParamModelAndView)); @@ -68,7 +68,7 @@ public class ModelAndViewMethodReturnValueHandlerTests { public void handleViewReference() throws Exception { ModelAndView mav = new ModelAndView("viewName", "attrName", "attrValue"); handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest); - + assertEquals("viewName", mavContainer.getView()); assertEquals("attrValue", mavContainer.getModel().get("attrName")); } @@ -77,7 +77,7 @@ public class ModelAndViewMethodReturnValueHandlerTests { public void handleViewInstance() throws Exception { ModelAndView mav = new ModelAndView(new RedirectView(), "attrName", "attrValue"); handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest); - + assertEquals(RedirectView.class, mavContainer.getView().getClass()); assertEquals("attrValue", mavContainer.getModel().get("attrName")); } @@ -85,7 +85,7 @@ public class ModelAndViewMethodReturnValueHandlerTests { @Test public void handleNull() throws Exception { handler.handleReturnValue(null, returnParamModelAndView, mavContainer, webRequest); - + assertTrue(mavContainer.isRequestHandled()); } @@ -93,10 +93,10 @@ public class ModelAndViewMethodReturnValueHandlerTests { public void handleRedirectAttributesWithViewReference() throws Exception { RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap(); mavContainer.setRedirectModel(redirectAttributes); - + ModelAndView mav = new ModelAndView(new RedirectView(), "attrName", "attrValue"); handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest); - + assertEquals(RedirectView.class, mavContainer.getView().getClass()); assertEquals("attrValue", mavContainer.getModel().get("attrName")); assertSame("RedirectAttributes should be used if controller redirects", redirectAttributes, @@ -107,24 +107,24 @@ public class ModelAndViewMethodReturnValueHandlerTests { public void handleRedirectAttributesWithViewInstance() throws Exception { RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap(); mavContainer.setRedirectModel(redirectAttributes); - + ModelAndView mav = new ModelAndView("redirect:viewName", "attrName", "attrValue"); handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest); - + ModelMap model = mavContainer.getModel(); assertEquals("redirect:viewName", mavContainer.getViewName()); assertEquals("attrValue", model.get("attrName")); assertSame("RedirectAttributes should be used if controller redirects", redirectAttributes, model); } - + @Test public void handleRedirectAttributesWithoutRedirect() throws Exception { RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap(); mavContainer.setRedirectModel(redirectAttributes); - + ModelAndView mav = new ModelAndView(); handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest); - + ModelMap model = mavContainer.getModel(); assertEquals(null, mavContainer.getView()); assertTrue(mavContainer.getModel().isEmpty()); @@ -136,7 +136,7 @@ public class ModelAndViewMethodReturnValueHandlerTests { Method method = getClass().getDeclaredMethod(methodName); return new MethodParameter(method, -1); } - + ModelAndView modelAndView() { return null; } @@ -144,5 +144,5 @@ public class ModelAndViewMethodReturnValueHandlerTests { String viewName() { return null; } - -} \ No newline at end of file + +} diff --git a/org.springframework.web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java b/org.springframework.web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java index dceda243b5..b92133765e 100644 --- a/org.springframework.web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java +++ b/org.springframework.web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,8 +35,8 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.ModelAndViewContainer; /** - * Abstract base class for resolving method arguments from a named value. Request parameters, request headers, and - * path variables are examples of named values. Each may have a name, a required flag, and a default value. + * Abstract base class for resolving method arguments from a named value. Request parameters, request headers, and + * path variables are examples of named values. Each may have a name, a required flag, and a default value. *
Subclasses define how to do the following: *
A default value string can contain ${...} placeholders and Spring Expression Language #{...} expressions. + *
A default value string can contain ${...} placeholders and Spring Expression Language #{...} expressions. * For this to work a {@link ConfigurableBeanFactory} must be supplied to the class constructor. - *
A {@link WebDataBinder} is created to apply type conversion to the resolved argument value if it doesn't + *
A {@link WebDataBinder} is created to apply type conversion to the resolved argument value if it doesn't
* match the method parameter type.
- *
+ *
* @author Arjen Poutsma
* @author Rossen Stoyanchev
* @since 3.1
@@ -63,7 +63,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
new ConcurrentHashMap Note: This class is provided for backwards compatibility.
- * However it is recommended to re-write a {@code WebArgumentResolver} as
- * {@code HandlerMethodArgumentResolver}. Since {@link #supportsParameter}
- * can only be implemented by actually resolving the value and then checking
- * the result is not {@code WebArgumentResolver#UNRESOLVED} any exceptions
- * raised must be absorbed and ignored since it's not clear whether the adapter
- * doesn't support the parameter or whether it failed for an internal reason.
+ * However it is recommended to re-write a {@code WebArgumentResolver} as
+ * {@code HandlerMethodArgumentResolver}. Since {@link #supportsParameter}
+ * can only be implemented by actually resolving the value and then checking
+ * the result is not {@code WebArgumentResolver#UNRESOLVED} any exceptions
+ * raised must be absorbed and ignored since it's not clear whether the adapter
+ * doesn't support the parameter or whether it failed for an internal reason.
* The {@code HandlerMethodArgumentResolver} contract also provides access to
* model attributes and to {@code WebDataBinderFactory} (for type conversion).
*
@@ -60,7 +60,7 @@ public abstract class AbstractWebArgumentResolverAdapter implements HandlerMetho
}
/**
- * Actually resolve the value and check the resolved value is not
+ * Actually resolve the value and check the resolved value is not
* {@link WebArgumentResolver#UNRESOLVED} absorbing _any_ exceptions.
*/
public boolean supportsParameter(MethodParameter parameter) {
@@ -88,21 +88,22 @@ public abstract class AbstractWebArgumentResolverAdapter implements HandlerMetho
/**
* Delegate to the {@link WebArgumentResolver} instance.
- * @exception IllegalStateException if the resolved value is not assignable
+ * @exception IllegalStateException if the resolved value is not assignable
* to the method parameter.
*/
- 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);
if (result == WebArgumentResolver.UNRESOLVED || !ClassUtils.isAssignableValue(paramType, result)) {
throw new IllegalStateException(
- "Standard argument type [" + paramType.getName() + "] in method " + parameter.getMethod() +
+ "Standard argument type [" + paramType.getName() + "] in method " + parameter.getMethod() +
"resolved to incompatible value of type [" + (result != null ? result.getClass() : null) +
"]. Consider declaring the argument type in a less specific fashion.");
}
return result;
}
-}
\ No newline at end of file
+}
diff --git a/org.springframework.web/src/main/java/org/springframework/web/method/annotation/ErrorsMethodArgumentResolver.java b/org.springframework.web/src/main/java/org/springframework/web/method/annotation/ErrorsMethodArgumentResolver.java
index 89d7af0705..2caca5b17c 100644
--- a/org.springframework.web/src/main/java/org/springframework/web/method/annotation/ErrorsMethodArgumentResolver.java
+++ b/org.springframework.web/src/main/java/org/springframework/web/method/annotation/ErrorsMethodArgumentResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * Copyright 2002-2012 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.
@@ -29,12 +29,12 @@ import org.springframework.web.method.support.ModelAndViewContainer;
/**
* Resolves {@link Errors} method arguments.
- *
+ *
* An {@code Errors} method argument is expected to appear immediately after
* the model attribute in the method signature. It is resolved by expecting the
* last two attributes added to the model to be the model attribute and its
- * {@link BindingResult}.
- *
+ * {@link BindingResult}.
+ *
* @author Rossen Stoyanchev
* @since 3.1
*/
@@ -45,10 +45,11 @@ public class ErrorsMethodArgumentResolver implements HandlerMethodArgumentResolv
return Errors.class.isAssignableFrom(paramType);
}
- 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) {
int lastIndex = model.size()-1;
@@ -63,4 +64,4 @@ public class ErrorsMethodArgumentResolver implements HandlerMethodArgumentResolv
"argument in the controller method signature: " + parameter.getMethod());
}
-}
\ No newline at end of file
+}
diff --git a/org.springframework.web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java b/org.springframework.web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java
index 064a76e85a..df430b5f0d 100644
--- a/org.springframework.web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java
+++ b/org.springframework.web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * Copyright 2002-2012 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,12 +27,12 @@ import org.springframework.web.method.support.ModelAndViewContainer;
/**
* Resolves {@link Map} method arguments and handles {@link Map} return values.
- *
- * A Map return value can be interpreted in more than one ways depending
- * on the presence of annotations like {@code @ModelAttribute} or
+ *
+ * A Map return value can be interpreted in more than one ways depending
+ * on the presence of annotations like {@code @ModelAttribute} or
* {@code @ResponseBody}. Therefore this handler should be configured after
* the handlers that support these annotations.
- *
+ *
* @author Rossen Stoyanchev
* @since 3.1
*/
@@ -42,10 +42,11 @@ public class MapMethodProcessor implements HandlerMethodArgumentResolver, Handle
return Map.class.isAssignableFrom(parameter.getParameterType());
}
- 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();
}
@@ -54,10 +55,11 @@ public class MapMethodProcessor implements HandlerMethodArgumentResolver, Handle
}
@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;
}
@@ -66,8 +68,8 @@ public class MapMethodProcessor implements HandlerMethodArgumentResolver, Handle
}
else {
// should not happen
- throw new UnsupportedOperationException("Unexpected return type: " +
+ throw new UnsupportedOperationException("Unexpected return type: " +
returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
}
}
-}
\ No newline at end of file
+}
diff --git a/org.springframework.web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java b/org.springframework.web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java
index a1521296aa..5ac23425f6 100644
--- a/org.springframework.web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java
+++ b/org.springframework.web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * Copyright 2002-2012 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,15 +39,15 @@ import org.springframework.web.method.support.ModelAndViewContainer;
/**
* Resolves method arguments annotated with {@code @ModelAttribute} and handles
* return values from methods annotated with {@code @ModelAttribute}.
- *
- * Model attributes are obtained from the model or if not found possibly
- * created with a default constructor if it is available. Once created, the
- * attributed is populated with request data via data binding and also
- * validation may be applied if the argument is annotated with
+ *
+ * Model attributes are obtained from the model or if not found possibly
+ * created with a default constructor if it is available. Once created, the
+ * attributed is populated with request data via data binding and also
+ * validation may be applied if the argument is annotated with
* {@code @javax.validation.Valid}.
*
- * When this handler is created with {@code annotationNotRequired=true},
- * any non-simple type argument and return value is regarded as a model
+ * When this handler is created with {@code annotationNotRequired=true},
+ * any non-simple type argument and return value is regarded as a model
* attribute with or without the presence of an {@code @ModelAttribute}.
*
* @author Rossen Stoyanchev
@@ -58,10 +58,10 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
protected Log logger = LogFactory.getLog(this.getClass());
private final boolean annotationNotRequired;
-
+
/**
* @param annotationNotRequired if "true", non-simple method arguments and
- * return values are considered model attributes with or without a
+ * return values are considered model attributes with or without a
* {@code @ModelAttribute} annotation.
*/
public ModelAttributeMethodProcessor(boolean annotationNotRequired) {
@@ -85,18 +85,19 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
}
/**
- * Resolve the argument from the model or if not found instantiate it with
- * its default if it is available. The model attribute is then populated
+ * Resolve the argument from the model or if not found instantiate it with
+ * its default if it is available. The model attribute is then populated
* with request values via data binding and optionally validated
* if {@code @java.validation.Valid} is present on the argument.
* @throws BindException if data binding and validation result in an error
* and the next method parameter is not of type {@link Errors}.
* @throws Exception if WebDataBinder initialization fails.
*/
- public final Object resolveArgument(MethodParameter parameter,
- ModelAndViewContainer mavContainer,
- NativeWebRequest request,
- WebDataBinderFactory binderFactory) throws Exception {
+ public final Object resolveArgument(
+ MethodParameter parameter, ModelAndViewContainer mavContainer,
+ NativeWebRequest request, WebDataBinderFactory binderFactory)
+ throws Exception {
+
String name = ModelFactory.getNameForParameter(parameter);
Object target = (mavContainer.containsAttribute(name)) ?
mavContainer.getModel().get(name) : createAttribute(name, parameter, binderFactory, request);
@@ -130,7 +131,7 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
return BeanUtils.instantiateClass(parameter.getParameterType());
}
-
+
/**
* Extension point to bind the request to the target object.
* @param binder the data binder instance to use for the binding
@@ -158,7 +159,7 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
/**
* Whether to raise a {@link BindException} on bind or validation errors.
- * The default implementation returns {@code true} if the next method
+ * The default implementation returns {@code true} if the next method
* argument is not of type {@link Errors}.
* @param binder the data binder used to perform data binding
* @param parameter the method argument
@@ -167,12 +168,12 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
int i = parameter.getParameterIndex();
Class>[] paramTypes = parameter.getMethod().getParameterTypes();
boolean hasBindingResult = (paramTypes.length > (i + 1) && Errors.class.isAssignableFrom(paramTypes[i + 1]));
-
+
return !hasBindingResult;
}
/**
- * Return {@code true} if there is a method-level {@code @ModelAttribute}
+ * Return {@code true} if there is a method-level {@code @ModelAttribute}
* or if it is a non-simple type when {@code annotationNotRequired=true}.
*/
public boolean supportsReturnType(MethodParameter returnType) {
@@ -190,13 +191,14 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
/**
* Add non-null return values to the {@link ModelAndViewContainer}.
*/
- 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) {
String name = ModelFactory.getNameForReturnValue(returnValue, returnType);
mavContainer.addAttribute(name, returnValue);
}
}
-}
\ No newline at end of file
+}
diff --git a/org.springframework.web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.java b/org.springframework.web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.java
index b3952424e2..c529efd8a3 100644
--- a/org.springframework.web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.java
+++ b/org.springframework.web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * Copyright 2002-2012 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,13 +25,13 @@ import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.method.support.ModelAndViewContainer;
/**
- * Resolves {@link Model} arguments and handles {@link Model} return values.
- *
- * A {@link Model} return type has a set purpose. Therefore this handler
- * should be configured ahead of handlers that support any return value type
+ * Resolves {@link Model} arguments and handles {@link Model} return values.
+ *
+ * A {@link Model} return type has a set purpose. Therefore this handler
+ * should be configured ahead of handlers that support any return value type
* annotated with {@code @ModelAttribute} or {@code @ResponseBody} to ensure
* they don't take over.
- *
+ *
* @author Rossen Stoyanchev
* @since 3.1
*/
@@ -41,10 +41,11 @@ public class ModelMethodProcessor implements HandlerMethodArgumentResolver, Hand
return Model.class.isAssignableFrom(parameter.getParameterType());
}
- 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();
}
@@ -52,10 +53,11 @@ public class ModelMethodProcessor implements HandlerMethodArgumentResolver, Hand
return Model.class.isAssignableFrom(returnType.getParameterType());
}
- 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;
}
@@ -64,8 +66,8 @@ public class ModelMethodProcessor implements HandlerMethodArgumentResolver, Hand
}
else {
// should not happen
- throw new UnsupportedOperationException("Unexpected return type: " +
+ throw new UnsupportedOperationException("Unexpected return type: " +
returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
}
}
-}
\ No newline at end of file
+}
diff --git a/org.springframework.web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMapMethodArgumentResolver.java b/org.springframework.web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMapMethodArgumentResolver.java
index a58d96cc27..4843782efb 100644
--- a/org.springframework.web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMapMethodArgumentResolver.java
+++ b/org.springframework.web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMapMethodArgumentResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,13 +31,13 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;
/**
- * Resolves {@link Map} method arguments annotated with {@code @RequestHeader}.
- * For individual header values annotated with {@code @RequestHeader} see
+ * Resolves {@link Map} method arguments annotated with {@code @RequestHeader}.
+ * For individual header values annotated with {@code @RequestHeader} see
* {@link RequestHeaderMethodArgumentResolver} instead.
- *
- * The created {@link Map} contains all request header name/value pairs.
+ *
+ * The created {@link Map} contains all request header name/value pairs.
* The method parameter type may be a {@link MultiValueMap} to receive all
- * values for a header, not only the first one.
+ * values for a header, not only the first one.
*
* @author Arjen Poutsma
* @author Rossen Stoyanchev
@@ -50,10 +50,11 @@ public class RequestHeaderMapMethodArgumentResolver implements HandlerMethodArgu
&& Map.class.isAssignableFrom(parameter.getParameterType());
}
- 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)) {
@@ -82,4 +83,4 @@ public class RequestHeaderMapMethodArgumentResolver implements HandlerMethodArgu
return result;
}
}
-}
\ No newline at end of file
+}
diff --git a/org.springframework.web/src/main/java/org/springframework/web/method/annotation/RequestParamMapMethodArgumentResolver.java b/org.springframework.web/src/main/java/org/springframework/web/method/annotation/RequestParamMapMethodArgumentResolver.java
index 435aafdbb8..befe7178d9 100644
--- a/org.springframework.web/src/main/java/org/springframework/web/method/annotation/RequestParamMapMethodArgumentResolver.java
+++ b/org.springframework.web/src/main/java/org/springframework/web/method/annotation/RequestParamMapMethodArgumentResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * Copyright 2002-2012 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,12 +30,12 @@ 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
+ *
+ * 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
@@ -55,10 +55,11 @@ public class RequestParamMapMethodArgumentResolver implements HandlerMethodArgum
return false;
}
- 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();
Map Argument resolution often requires a {@link WebDataBinder} for data binding or for type conversion.
+ *
+ * Argument resolution often requires a {@link WebDataBinder} for data binding or for type conversion.
* Use the {@link #setDataBinderFactory(WebDataBinderFactory)} property to supply a binder factory to pass to
- * argument resolvers.
- *
- * Use {@link #setHandlerMethodArgumentResolvers(HandlerMethodArgumentResolverComposite)} to customize
+ * argument resolvers.
+ *
+ * Use {@link #setHandlerMethodArgumentResolvers(HandlerMethodArgumentResolverComposite)} to customize
* the list of argument resolvers.
- *
+ *
* @author Rossen Stoyanchev
* @since 3.1
*/
@@ -99,20 +99,20 @@ public class InvocableHandlerMethod extends HandlerMethod {
}
/**
- * Invoke the method after resolving its argument values in the context of the given request. Argument
- * values are commonly resolved through {@link HandlerMethodArgumentResolver}s. The {@code provideArgs}
- * parameter however may supply argument values to be used directly, i.e. without argument resolution.
- * Examples of provided argument values include a {@link WebDataBinder}, a {@link SessionStatus}, or
+ * Invoke the method after resolving its argument values in the context of the given request. Argument
+ * values are commonly resolved through {@link HandlerMethodArgumentResolver}s. The {@code provideArgs}
+ * parameter however may supply argument values to be used directly, i.e. without argument resolution.
+ * Examples of provided argument values include a {@link WebDataBinder}, a {@link SessionStatus}, or
* a thrown exception instance. Provided argument values are checked before argument resolvers.
- *
+ *
* @param request the current request
* @param mavContainer the {@link ModelAndViewContainer} for the current request
* @param providedArgs argument values to try to use without view resolution
* @return the raw value returned by the invoked method
- * @exception Exception raised if no suitable argument resolver can be found, or the method raised an exception
+ * @exception Exception raised if no suitable argument resolver can be found, or the method raised an exception
*/
- public final Object invokeForRequest(NativeWebRequest request,
- ModelAndViewContainer mavContainer,
+ public final Object invokeForRequest(NativeWebRequest request,
+ ModelAndViewContainer mavContainer,
Object... providedArgs) throws Exception {
Object[] args = getMethodArgumentValues(request, mavContainer, providedArgs);
@@ -135,9 +135,10 @@ public class InvocableHandlerMethod extends HandlerMethod {
/**
* Get the method argument values for the current request.
*/
- private Object[] getMethodArgumentValues(NativeWebRequest request,
- ModelAndViewContainer mavContainer,
- Object... providedArgs) throws Exception {
+ private Object[] getMethodArgumentValues(
+ NativeWebRequest request, ModelAndViewContainer mavContainer,
+ Object... providedArgs) throws Exception {
+
MethodParameter[] parameters = getMethodParameters();
Object[] args = new Object[parameters.length];
for (int i = 0; i < parameters.length; i++) {
@@ -187,7 +188,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
sb.append("Method [").append(getBridgedMethod().toGenericString()).append("]\n");
return sb.toString();
}
-
+
/**
* Attempt to resolve a method parameter from the list of provided argument values.
*/
@@ -202,7 +203,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
}
return null;
}
-
+
/**
* Invoke the handler method with the given argument values.
*/
@@ -215,7 +216,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
String msg = getInvocationErrorMessage(e.getMessage(), args);
throw new IllegalArgumentException(msg, e);
}
- catch (InvocationTargetException e) {
+ catch (InvocationTargetException e) {
// Unwrap for HandlerExceptionResolvers ...
Throwable targetException = e.getTargetException();
if (targetException instanceof RuntimeException) {
@@ -233,7 +234,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
}
}
}
-
+
private String getInvocationErrorMessage(String message, Object[] resolvedArgs) {
StringBuilder sb = new StringBuilder(getDetailedErrorMessage(message));
sb.append("Resolved arguments: \n");
@@ -250,4 +251,4 @@ public class InvocableHandlerMethod extends HandlerMethod {
return sb.toString();
}
-}
\ No newline at end of file
+}