Polish "Support flash attrs..." and related classes
- Eliminate trailing whitespace
- Update long method signatures to follow framework whitespace
conventions
Based on the following search,
$ git grep -A3 '^.public .* .*([^\{;]*$' */src/main
the strong convention throughout the framework when dealing with
methods having long signatures (i.e. many parameters) is to break
immediately after the opening paren, indent two tabs deeper and break
lines around 90 characters as necessary. Such signatures should also
be followed by a newline after the opening curly brace to break
things up visually.
The files edited in this commit had a particularly different style of
intenting arguments to align with each other vertically, but the
alignment only worked if one's tabstop is set at four spaces.
When viewed at a different tabstop value, the effect is is jarring,
both in that it is misaligned and significantly different from most
of the framework. The convention described above reads well at any
tabstop value.
This commit is contained in:
parent
92f8446eea
commit
d7d1b495f2
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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
|
* Resolves {@link HttpEntity} method argument values and also handles
|
||||||
* both {@link HttpEntity} and {@link ResponseEntity} return values.
|
* both {@link HttpEntity} and {@link ResponseEntity} return values.
|
||||||
*
|
*
|
||||||
* <p>An {@link HttpEntity} return type has a set purpose. Therefore this
|
* <p>An {@link HttpEntity} return type has a set purpose. Therefore this
|
||||||
* handler should be configured ahead of handlers that support any return
|
* handler should be configured ahead of handlers that support any return
|
||||||
* value type annotated with {@code @ModelAttribute} or {@code @ResponseBody}
|
* value type annotated with {@code @ModelAttribute} or {@code @ResponseBody}
|
||||||
* to ensure they don't take over.
|
* to ensure they don't take over.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
|
|
@ -66,10 +66,9 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro
|
||||||
return HttpEntity.class.equals(parameterType) || ResponseEntity.class.equals(parameterType);
|
return HttpEntity.class.equals(parameterType) || ResponseEntity.class.equals(parameterType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object resolveArgument(MethodParameter parameter,
|
public Object resolveArgument(
|
||||||
ModelAndViewContainer mavContainer,
|
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||||
NativeWebRequest webRequest,
|
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||||
WebDataBinderFactory binderFactory)
|
|
||||||
throws IOException, HttpMediaTypeNotSupportedException {
|
throws IOException, HttpMediaTypeNotSupportedException {
|
||||||
|
|
||||||
HttpInputMessage inputMessage = createInputMessage(webRequest);
|
HttpInputMessage inputMessage = createInputMessage(webRequest);
|
||||||
|
|
@ -100,11 +99,11 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro
|
||||||
+ "in method " + parameter.getMethod() + "is not parameterized");
|
+ "in method " + parameter.getMethod() + "is not parameterized");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleReturnValue(Object returnValue,
|
public void handleReturnValue(
|
||||||
MethodParameter returnType,
|
Object returnValue, MethodParameter returnType,
|
||||||
ModelAndViewContainer mavContainer,
|
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
|
||||||
NativeWebRequest webRequest) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
mavContainer.setRequestHandled(true);
|
mavContainer.setRequestHandled(true);
|
||||||
|
|
||||||
if (returnValue == null) {
|
if (returnValue == null) {
|
||||||
|
|
@ -135,4 +134,4 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,15 +25,15 @@ import org.springframework.web.servlet.SmartView;
|
||||||
import org.springframework.web.servlet.View;
|
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}.
|
* information to the {@link ModelAndViewContainer}.
|
||||||
*
|
*
|
||||||
* <p>If the return value is {@code null}, the
|
* <p>If the return value is {@code null}, the
|
||||||
* {@link ModelAndViewContainer#setRequestHandled(boolean)} flag is set to
|
* {@link ModelAndViewContainer#setRequestHandled(boolean)} flag is set to
|
||||||
* {@code false} to indicate the request was handled directly.
|
* {@code false} to indicate the request was handled directly.
|
||||||
*
|
*
|
||||||
* <p>A {@link ModelAndView} return type has a set purpose. Therefore this
|
* <p>A {@link ModelAndView} return type has a set purpose. Therefore this
|
||||||
* handler should be configured ahead of handlers that support any return
|
* handler should be configured ahead of handlers that support any return
|
||||||
* value type annotated with {@code @ModelAttribute} or {@code @ResponseBody}
|
* value type annotated with {@code @ModelAttribute} or {@code @ResponseBody}
|
||||||
* to ensure they don't take over.
|
* to ensure they don't take over.
|
||||||
*
|
*
|
||||||
|
|
@ -41,20 +41,21 @@ import org.springframework.web.servlet.View;
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturnValueHandler {
|
public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturnValueHandler {
|
||||||
|
|
||||||
public boolean supportsReturnType(MethodParameter returnType) {
|
public boolean supportsReturnType(MethodParameter returnType) {
|
||||||
return ModelAndView.class.isAssignableFrom(returnType.getParameterType());
|
return ModelAndView.class.isAssignableFrom(returnType.getParameterType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleReturnValue(Object returnValue,
|
public void handleReturnValue(
|
||||||
MethodParameter returnType,
|
Object returnValue, MethodParameter returnType,
|
||||||
ModelAndViewContainer mavContainer,
|
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
|
||||||
NativeWebRequest webRequest) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
if (returnValue == null) {
|
if (returnValue == null) {
|
||||||
mavContainer.setRequestHandled(true);
|
mavContainer.setRequestHandled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelAndView mav = (ModelAndView) returnValue;
|
ModelAndView mav = (ModelAndView) returnValue;
|
||||||
if (mav.isReference()) {
|
if (mav.isReference()) {
|
||||||
String viewName = mav.getViewName();
|
String viewName = mav.getViewName();
|
||||||
|
|
@ -75,4 +76,4 @@ public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturn
|
||||||
mavContainer.addAllAttributes(mav.getModel());
|
mavContainer.addAllAttributes(mav.getModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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;
|
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
|
* attempts to handle _any_ return value type (i.e. returns {@code true} for
|
||||||
* all return types).
|
* all return types).
|
||||||
*
|
*
|
||||||
* <p>The return value is handled either with a {@link ModelAndViewResolver}
|
* <p>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
|
* 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
|
* type. If neither of these succeeds (essentially simple type other than
|
||||||
* String), {@link UnsupportedOperationException} is raised.
|
* String), {@link UnsupportedOperationException} is raised.
|
||||||
*
|
*
|
||||||
* <p><strong>Note:</strong> This class is primarily needed to support
|
* <p><strong>Note:</strong> This class is primarily needed to support
|
||||||
* {@link ModelAndViewResolver}, which unfortunately cannot be properly
|
* {@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
|
* {@link HandlerMethodReturnValueHandler#supportsReturnType} method
|
||||||
* cannot be implemented. Hence {@code ModelAndViewResolver}s are limited
|
* cannot be implemented. Hence {@code ModelAndViewResolver}s are limited
|
||||||
* to always being invoked at the end after all other return value
|
* to always being invoked at the end after all other return value
|
||||||
* handlers have been given a chance. It is recommended to re-implement
|
* handlers have been given a chance. It is recommended to re-implement
|
||||||
* a {@code ModelAndViewResolver} as {@code HandlerMethodReturnValueHandler},
|
* a {@code ModelAndViewResolver} as {@code HandlerMethodReturnValueHandler},
|
||||||
* which also provides better access to the return type and method information.
|
* which also provides better access to the return type and method information.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
|
|
@ -71,10 +71,10 @@ public class ModelAndViewResolverMethodReturnValueHandler implements HandlerMeth
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleReturnValue(Object returnValue,
|
public void handleReturnValue(
|
||||||
MethodParameter returnType,
|
Object returnValue, MethodParameter returnType,
|
||||||
ModelAndViewContainer mavContainer,
|
ModelAndViewContainer mavContainer, NativeWebRequest request)
|
||||||
NativeWebRequest request) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
if (this.mavResolvers != null) {
|
if (this.mavResolvers != null) {
|
||||||
for (ModelAndViewResolver mavResolver : this.mavResolvers) {
|
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)) {
|
if (this.modelAttributeProcessor.supportsReturnType(returnType)) {
|
||||||
this.modelAttributeProcessor.handleReturnValue(returnValue, returnType, mavContainer, request);
|
this.modelAttributeProcessor.handleReturnValue(returnValue, returnType, mavContainer, request);
|
||||||
|
|
@ -104,4 +104,4 @@ public class ModelAndViewResolverMethodReturnValueHandler implements HandlerMeth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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;
|
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves method arguments of type {@link RedirectAttributes}.
|
* Resolves method arguments of type {@link RedirectAttributes}.
|
||||||
*
|
*
|
||||||
* <p>This resolver must be listed ahead of {@link org.springframework.web.method.annotation.ModelMethodProcessor} and
|
* <p>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}
|
* {@link org.springframework.web.method.annotation.MapMethodProcessor}, which support {@link Map} and {@link Model}
|
||||||
* arguments both of which are "super" types of {@code RedirectAttributes}
|
* 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());
|
return RedirectAttributes.class.isAssignableFrom(parameter.getParameterType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object resolveArgument(MethodParameter parameter,
|
public Object resolveArgument(
|
||||||
ModelAndViewContainer mavContainer,
|
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||||
NativeWebRequest webRequest,
|
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||||
WebDataBinderFactory binderFactory) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
DataBinder dataBinder = binderFactory.createBinder(webRequest, null, null);
|
DataBinder dataBinder = binderFactory.createBinder(webRequest, null, null);
|
||||||
ModelMap redirectAttributes = new RedirectAttributesModelMap(dataBinder);
|
ModelMap redirectAttributes = new RedirectAttributesModelMap(dataBinder);
|
||||||
mavContainer.setRedirectModel(redirectAttributes);
|
mavContainer.setRedirectModel(redirectAttributes);
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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 mavContainer the {@link ModelAndViewContainer} for the current request
|
||||||
* @param providedArgs argument values to try to use without the need for view resolution
|
* @param providedArgs argument values to try to use without the need for view resolution
|
||||||
*/
|
*/
|
||||||
public final void invokeAndHandle(NativeWebRequest request,
|
public final void invokeAndHandle(
|
||||||
ModelAndViewContainer mavContainer,
|
NativeWebRequest request, ModelAndViewContainer mavContainer,
|
||||||
Object...providedArgs) throws Exception {
|
Object... providedArgs) throws Exception {
|
||||||
|
|
||||||
Object returnValue = invokeForRequest(request, mavContainer, providedArgs);
|
Object returnValue = invokeForRequest(request, mavContainer, providedArgs);
|
||||||
|
|
||||||
|
|
@ -124,7 +124,7 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
|
||||||
sb.append("[value=" + returnValue + "]");
|
sb.append("[value=" + returnValue + "]");
|
||||||
return getDetailedErrorMessage(sb.toString());
|
return getDetailedErrorMessage(sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the response status according to the {@link ResponseStatus} annotation.
|
* Set the response status according to the {@link ResponseStatus} annotation.
|
||||||
*/
|
*/
|
||||||
|
|
@ -157,4 +157,4 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
|
||||||
private boolean hasResponseStatus() {
|
private boolean hasResponseStatus() {
|
||||||
return responseStatus != null;
|
return responseStatus != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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;
|
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:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>{@link WebRequest}
|
* <li>{@link WebRequest}
|
||||||
* <li>{@link ServletRequest}
|
* <li>{@link ServletRequest}
|
||||||
|
|
@ -57,20 +57,20 @@ public class ServletRequestMethodArgumentResolver implements HandlerMethodArgume
|
||||||
|
|
||||||
public boolean supportsParameter(MethodParameter parameter) {
|
public boolean supportsParameter(MethodParameter parameter) {
|
||||||
Class<?> paramType = parameter.getParameterType();
|
Class<?> paramType = parameter.getParameterType();
|
||||||
return WebRequest.class.isAssignableFrom(paramType) ||
|
return WebRequest.class.isAssignableFrom(paramType) ||
|
||||||
ServletRequest.class.isAssignableFrom(paramType) ||
|
ServletRequest.class.isAssignableFrom(paramType) ||
|
||||||
MultipartRequest.class.isAssignableFrom(paramType) ||
|
MultipartRequest.class.isAssignableFrom(paramType) ||
|
||||||
HttpSession.class.isAssignableFrom(paramType) ||
|
HttpSession.class.isAssignableFrom(paramType) ||
|
||||||
Principal.class.isAssignableFrom(paramType) ||
|
Principal.class.isAssignableFrom(paramType) ||
|
||||||
Locale.class.equals(paramType) ||
|
Locale.class.equals(paramType) ||
|
||||||
InputStream.class.isAssignableFrom(paramType) ||
|
InputStream.class.isAssignableFrom(paramType) ||
|
||||||
Reader.class.isAssignableFrom(paramType);
|
Reader.class.isAssignableFrom(paramType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object resolveArgument(MethodParameter parameter,
|
public Object resolveArgument(
|
||||||
ModelAndViewContainer mavContainer,
|
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||||
NativeWebRequest webRequest,
|
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||||
WebDataBinderFactory binderFactory) throws IOException {
|
throws IOException {
|
||||||
|
|
||||||
Class<?> paramType = parameter.getParameterType();
|
Class<?> paramType = parameter.getParameterType();
|
||||||
if (WebRequest.class.isAssignableFrom(paramType)) {
|
if (WebRequest.class.isAssignableFrom(paramType)) {
|
||||||
|
|
@ -108,4 +108,4 @@ public class ServletRequestMethodArgumentResolver implements HandlerMethodArgume
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -47,20 +47,20 @@ public class ServletResponseMethodArgumentResolver implements HandlerMethodArgum
|
||||||
public boolean supportsParameter(MethodParameter parameter) {
|
public boolean supportsParameter(MethodParameter parameter) {
|
||||||
Class<?> paramType = parameter.getParameterType();
|
Class<?> paramType = parameter.getParameterType();
|
||||||
return ServletResponse.class.isAssignableFrom(paramType)
|
return ServletResponse.class.isAssignableFrom(paramType)
|
||||||
|| OutputStream.class.isAssignableFrom(paramType)
|
|| OutputStream.class.isAssignableFrom(paramType)
|
||||||
|| Writer.class.isAssignableFrom(paramType);
|
|| Writer.class.isAssignableFrom(paramType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set {@link ModelAndViewContainer#setRequestHandled(boolean)} to
|
* Set {@link ModelAndViewContainer#setRequestHandled(boolean)} to
|
||||||
* {@code false} to indicate that the method signature provides access
|
* {@code false} to indicate that the method signature provides access
|
||||||
* to the response. If subsequently the underlying method returns
|
* to the response. If subsequently the underlying method returns
|
||||||
* {@code null}, the request is considered directly handled.
|
* {@code null}, the request is considered directly handled.
|
||||||
*/
|
*/
|
||||||
public Object resolveArgument(MethodParameter parameter,
|
public Object resolveArgument(
|
||||||
ModelAndViewContainer mavContainer,
|
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||||
NativeWebRequest webRequest,
|
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||||
WebDataBinderFactory binderFactory) throws IOException {
|
throws IOException {
|
||||||
|
|
||||||
mavContainer.setRequestHandled(true);
|
mavContainer.setRequestHandled(true);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -28,7 +28,7 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolvers argument values of type {@link UriComponentsBuilder}.
|
* Resolvers argument values of type {@link UriComponentsBuilder}.
|
||||||
*
|
*
|
||||||
* <p>The returned instance is initialized via
|
* <p>The returned instance is initialized via
|
||||||
* {@link ServletUriComponentsBuilder#fromServletMapping(HttpServletRequest)}.
|
* {@link ServletUriComponentsBuilder#fromServletMapping(HttpServletRequest)}.
|
||||||
*
|
*
|
||||||
|
|
@ -41,11 +41,11 @@ public class UriComponentsBuilderMethodArgumentResolver implements HandlerMethod
|
||||||
return UriComponentsBuilder.class.isAssignableFrom(parameter.getParameterType());
|
return UriComponentsBuilder.class.isAssignableFrom(parameter.getParameterType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object resolveArgument(MethodParameter parameter,
|
public Object resolveArgument(
|
||||||
ModelAndViewContainer mavContainer,
|
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||||
NativeWebRequest webRequest,
|
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||||
WebDataBinderFactory binderFactory) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
|
HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
|
||||||
return ServletUriComponentsBuilder.fromServletMapping(request);
|
return ServletUriComponentsBuilder.fromServletMapping(request);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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}.
|
* Handles return values that are of type {@link View}.
|
||||||
*
|
*
|
||||||
* <p>A {@code null} return value is left as-is leaving it to the configured
|
* <p>A {@code null} return value is left as-is leaving it to the configured
|
||||||
* {@link RequestToViewNameTranslator} to select a view name by convention.
|
* {@link RequestToViewNameTranslator} to select a view name by convention.
|
||||||
*
|
*
|
||||||
* <p>A {@link View} return type has a set purpose. Therefore this handler
|
* <p>A {@link View} return type has a set purpose. Therefore this handler
|
||||||
* should be configured ahead of handlers that support any return value type
|
* should be configured ahead of handlers that support any return value type
|
||||||
* annotated with {@code @ModelAttribute} or {@code @ResponseBody} to ensure
|
* annotated with {@code @ModelAttribute} or {@code @ResponseBody} to ensure
|
||||||
* they don't take over.
|
* they don't take over.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
|
|
@ -44,10 +44,11 @@ public class ViewMethodReturnValueHandler implements HandlerMethodReturnValueHan
|
||||||
return View.class.isAssignableFrom(returnType.getParameterType());
|
return View.class.isAssignableFrom(returnType.getParameterType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleReturnValue(Object returnValue,
|
public void handleReturnValue(
|
||||||
MethodParameter returnType,
|
Object returnValue, MethodParameter returnType,
|
||||||
ModelAndViewContainer mavContainer,
|
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
|
||||||
NativeWebRequest webRequest) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
if (returnValue == null) {
|
if (returnValue == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -62,7 +63,7 @@ public class ViewMethodReturnValueHandler implements HandlerMethodReturnValueHan
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// should not happen
|
// should not happen
|
||||||
throw new UnsupportedOperationException("Unexpected return type: " +
|
throw new UnsupportedOperationException("Unexpected return type: " +
|
||||||
returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
|
returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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
|
* Handles return values of types {@code void} and {@code String} interpreting
|
||||||
* them as view name reference.
|
* them as view name reference.
|
||||||
*
|
*
|
||||||
* <p>A {@code null} return value, either due to a {@code void} return type or
|
* <p>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
|
* as the actual return value is left as-is allowing the configured
|
||||||
* {@link RequestToViewNameTranslator} to select a view name by convention.
|
* {@link RequestToViewNameTranslator} to select a view name by convention.
|
||||||
*
|
*
|
||||||
* <p>A String return value can be interpreted in more than one ways depending
|
* <p>A String return value can be interpreted in more than one ways depending
|
||||||
* on the presence of annotations like {@code @ModelAttribute} or
|
* on the presence of annotations like {@code @ModelAttribute} or
|
||||||
* {@code @ResponseBody}. Therefore this handler should be configured after
|
* {@code @ResponseBody}. Therefore this handler should be configured after
|
||||||
* the handlers that support these annotations.
|
* the handlers that support these annotations.
|
||||||
*
|
*
|
||||||
|
|
@ -45,10 +45,11 @@ public class ViewNameMethodReturnValueHandler implements HandlerMethodReturnValu
|
||||||
return (void.class.equals(paramType) || String.class.equals(paramType));
|
return (void.class.equals(paramType) || String.class.equals(paramType));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleReturnValue(Object returnValue,
|
public void handleReturnValue(
|
||||||
MethodParameter returnType,
|
Object returnValue, MethodParameter returnType,
|
||||||
ModelAndViewContainer mavContainer,
|
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
|
||||||
NativeWebRequest webRequest) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
if (returnValue == null) {
|
if (returnValue == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -61,7 +62,7 @@ public class ViewNameMethodReturnValueHandler implements HandlerMethodReturnValu
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// should not happen
|
// should not happen
|
||||||
throw new UnsupportedOperationException("Unexpected return type: " +
|
throw new UnsupportedOperationException("Unexpected return type: " +
|
||||||
returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
|
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.
|
* Whether the given view name is a redirect view reference.
|
||||||
* @param viewName the view name to check, never {@code null}
|
* @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.
|
* reference; "false" otherwise.
|
||||||
*/
|
*/
|
||||||
protected boolean isRedirectViewName(String viewName) {
|
protected boolean isRedirectViewName(String viewName) {
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ import org.springframework.web.servlet.view.RedirectView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test fixture with {@link ModelAndViewMethodReturnValueHandler}.
|
* Test fixture with {@link ModelAndViewMethodReturnValueHandler}.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class ModelAndViewMethodReturnValueHandlerTests {
|
public class ModelAndViewMethodReturnValueHandlerTests {
|
||||||
|
|
@ -57,7 +57,7 @@ public class ModelAndViewMethodReturnValueHandlerTests {
|
||||||
this.webRequest = new ServletWebRequest(new MockHttpServletRequest());
|
this.webRequest = new ServletWebRequest(new MockHttpServletRequest());
|
||||||
this.returnParamModelAndView = getReturnValueParam("modelAndView");
|
this.returnParamModelAndView = getReturnValueParam("modelAndView");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsReturnType() throws Exception {
|
public void supportsReturnType() throws Exception {
|
||||||
assertTrue(handler.supportsReturnType(returnParamModelAndView));
|
assertTrue(handler.supportsReturnType(returnParamModelAndView));
|
||||||
|
|
@ -68,7 +68,7 @@ public class ModelAndViewMethodReturnValueHandlerTests {
|
||||||
public void handleViewReference() throws Exception {
|
public void handleViewReference() throws Exception {
|
||||||
ModelAndView mav = new ModelAndView("viewName", "attrName", "attrValue");
|
ModelAndView mav = new ModelAndView("viewName", "attrName", "attrValue");
|
||||||
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
|
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
|
||||||
|
|
||||||
assertEquals("viewName", mavContainer.getView());
|
assertEquals("viewName", mavContainer.getView());
|
||||||
assertEquals("attrValue", mavContainer.getModel().get("attrName"));
|
assertEquals("attrValue", mavContainer.getModel().get("attrName"));
|
||||||
}
|
}
|
||||||
|
|
@ -77,7 +77,7 @@ public class ModelAndViewMethodReturnValueHandlerTests {
|
||||||
public void handleViewInstance() throws Exception {
|
public void handleViewInstance() throws Exception {
|
||||||
ModelAndView mav = new ModelAndView(new RedirectView(), "attrName", "attrValue");
|
ModelAndView mav = new ModelAndView(new RedirectView(), "attrName", "attrValue");
|
||||||
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
|
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
|
||||||
|
|
||||||
assertEquals(RedirectView.class, mavContainer.getView().getClass());
|
assertEquals(RedirectView.class, mavContainer.getView().getClass());
|
||||||
assertEquals("attrValue", mavContainer.getModel().get("attrName"));
|
assertEquals("attrValue", mavContainer.getModel().get("attrName"));
|
||||||
}
|
}
|
||||||
|
|
@ -85,7 +85,7 @@ public class ModelAndViewMethodReturnValueHandlerTests {
|
||||||
@Test
|
@Test
|
||||||
public void handleNull() throws Exception {
|
public void handleNull() throws Exception {
|
||||||
handler.handleReturnValue(null, returnParamModelAndView, mavContainer, webRequest);
|
handler.handleReturnValue(null, returnParamModelAndView, mavContainer, webRequest);
|
||||||
|
|
||||||
assertTrue(mavContainer.isRequestHandled());
|
assertTrue(mavContainer.isRequestHandled());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,10 +93,10 @@ public class ModelAndViewMethodReturnValueHandlerTests {
|
||||||
public void handleRedirectAttributesWithViewReference() throws Exception {
|
public void handleRedirectAttributesWithViewReference() throws Exception {
|
||||||
RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
|
RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
|
||||||
mavContainer.setRedirectModel(redirectAttributes);
|
mavContainer.setRedirectModel(redirectAttributes);
|
||||||
|
|
||||||
ModelAndView mav = new ModelAndView(new RedirectView(), "attrName", "attrValue");
|
ModelAndView mav = new ModelAndView(new RedirectView(), "attrName", "attrValue");
|
||||||
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
|
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
|
||||||
|
|
||||||
assertEquals(RedirectView.class, mavContainer.getView().getClass());
|
assertEquals(RedirectView.class, mavContainer.getView().getClass());
|
||||||
assertEquals("attrValue", mavContainer.getModel().get("attrName"));
|
assertEquals("attrValue", mavContainer.getModel().get("attrName"));
|
||||||
assertSame("RedirectAttributes should be used if controller redirects", redirectAttributes,
|
assertSame("RedirectAttributes should be used if controller redirects", redirectAttributes,
|
||||||
|
|
@ -107,24 +107,24 @@ public class ModelAndViewMethodReturnValueHandlerTests {
|
||||||
public void handleRedirectAttributesWithViewInstance() throws Exception {
|
public void handleRedirectAttributesWithViewInstance() throws Exception {
|
||||||
RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
|
RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
|
||||||
mavContainer.setRedirectModel(redirectAttributes);
|
mavContainer.setRedirectModel(redirectAttributes);
|
||||||
|
|
||||||
ModelAndView mav = new ModelAndView("redirect:viewName", "attrName", "attrValue");
|
ModelAndView mav = new ModelAndView("redirect:viewName", "attrName", "attrValue");
|
||||||
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
|
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
|
||||||
|
|
||||||
ModelMap model = mavContainer.getModel();
|
ModelMap model = mavContainer.getModel();
|
||||||
assertEquals("redirect:viewName", mavContainer.getViewName());
|
assertEquals("redirect:viewName", mavContainer.getViewName());
|
||||||
assertEquals("attrValue", model.get("attrName"));
|
assertEquals("attrValue", model.get("attrName"));
|
||||||
assertSame("RedirectAttributes should be used if controller redirects", redirectAttributes, model);
|
assertSame("RedirectAttributes should be used if controller redirects", redirectAttributes, model);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handleRedirectAttributesWithoutRedirect() throws Exception {
|
public void handleRedirectAttributesWithoutRedirect() throws Exception {
|
||||||
RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
|
RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
|
||||||
mavContainer.setRedirectModel(redirectAttributes);
|
mavContainer.setRedirectModel(redirectAttributes);
|
||||||
|
|
||||||
ModelAndView mav = new ModelAndView();
|
ModelAndView mav = new ModelAndView();
|
||||||
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
|
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
|
||||||
|
|
||||||
ModelMap model = mavContainer.getModel();
|
ModelMap model = mavContainer.getModel();
|
||||||
assertEquals(null, mavContainer.getView());
|
assertEquals(null, mavContainer.getView());
|
||||||
assertTrue(mavContainer.getModel().isEmpty());
|
assertTrue(mavContainer.getModel().isEmpty());
|
||||||
|
|
@ -136,7 +136,7 @@ public class ModelAndViewMethodReturnValueHandlerTests {
|
||||||
Method method = getClass().getDeclaredMethod(methodName);
|
Method method = getClass().getDeclaredMethod(methodName);
|
||||||
return new MethodParameter(method, -1);
|
return new MethodParameter(method, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelAndView modelAndView() {
|
ModelAndView modelAndView() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -144,5 +144,5 @@ public class ModelAndViewMethodReturnValueHandlerTests {
|
||||||
String viewName() {
|
String viewName() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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;
|
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract base class for resolving method arguments from a named value. Request parameters, request headers, and
|
* 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.
|
* path variables are examples of named values. Each may have a name, a required flag, and a default value.
|
||||||
* <p>Subclasses define how to do the following:
|
* <p>Subclasses define how to do the following:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>Obtain named value information for a method parameter
|
* <li>Obtain named value information for a method parameter
|
||||||
|
|
@ -44,11 +44,11 @@ import org.springframework.web.method.support.ModelAndViewContainer;
|
||||||
* <li>Handle missing argument values when argument values are required
|
* <li>Handle missing argument values when argument values are required
|
||||||
* <li>Optionally handle a resolved value
|
* <li>Optionally handle a resolved value
|
||||||
* </ul>
|
* </ul>
|
||||||
* <p>A default value string can contain ${...} placeholders and Spring Expression Language #{...} expressions.
|
* <p>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.
|
* For this to work a {@link ConfigurableBeanFactory} must be supplied to the class constructor.
|
||||||
* <p>A {@link WebDataBinder} is created to apply type conversion to the resolved argument value if it doesn't
|
* <p>A {@link WebDataBinder} is created to apply type conversion to the resolved argument value if it doesn't
|
||||||
* match the method parameter type.
|
* match the method parameter type.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
|
|
@ -63,7 +63,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
|
||||||
new ConcurrentHashMap<MethodParameter, NamedValueInfo>();
|
new ConcurrentHashMap<MethodParameter, NamedValueInfo>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param beanFactory a bean factory to use for resolving ${...} placeholder and #{...} SpEL expressions
|
* @param beanFactory a bean factory to use for resolving ${...} placeholder and #{...} SpEL expressions
|
||||||
* in default values, or {@code null} if default values are not expected to contain expressions
|
* in default values, or {@code null} if default values are not expected to contain expressions
|
||||||
*/
|
*/
|
||||||
public AbstractNamedValueMethodArgumentResolver(ConfigurableBeanFactory beanFactory) {
|
public AbstractNamedValueMethodArgumentResolver(ConfigurableBeanFactory beanFactory) {
|
||||||
|
|
@ -71,10 +71,11 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
|
||||||
this.expressionContext = (beanFactory != null) ? new BeanExpressionContext(beanFactory, new RequestScope()) : null;
|
this.expressionContext = (beanFactory != null) ? new BeanExpressionContext(beanFactory, new RequestScope()) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Object resolveArgument(MethodParameter parameter,
|
public final Object resolveArgument(
|
||||||
ModelAndViewContainer mavContainer,
|
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||||
NativeWebRequest webRequest,
|
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||||
WebDataBinderFactory binderFactory) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
Class<?> paramType = parameter.getParameterType();
|
Class<?> paramType = parameter.getParameterType();
|
||||||
|
|
||||||
NamedValueInfo namedValueInfo = getNamedValueInfo(parameter);
|
NamedValueInfo namedValueInfo = getNamedValueInfo(parameter);
|
||||||
|
|
@ -95,7 +96,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
|
||||||
WebDataBinder binder = binderFactory.createBinder(webRequest, null, namedValueInfo.name);
|
WebDataBinder binder = binderFactory.createBinder(webRequest, null, namedValueInfo.name);
|
||||||
arg = binder.convertIfNecessary(arg, paramType, parameter);
|
arg = binder.convertIfNecessary(arg, paramType, parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleResolvedValue(arg, namedValueInfo.name, parameter, mavContainer, webRequest);
|
handleResolvedValue(arg, namedValueInfo.name, parameter, mavContainer, webRequest);
|
||||||
|
|
||||||
return arg;
|
return arg;
|
||||||
|
|
@ -115,9 +116,9 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the {@link NamedValueInfo} object for the given method parameter. Implementations typically
|
* Create the {@link NamedValueInfo} object for the given method parameter. Implementations typically
|
||||||
* retrieve the method annotation by means of {@link MethodParameter#getParameterAnnotation(Class)}.
|
* retrieve the method annotation by means of {@link MethodParameter#getParameterAnnotation(Class)}.
|
||||||
*
|
*
|
||||||
* @param parameter the method parameter
|
* @param parameter the method parameter
|
||||||
* @return the named value information
|
* @return the named value information
|
||||||
*/
|
*/
|
||||||
|
|
@ -136,7 +137,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
|
||||||
String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);
|
String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);
|
||||||
return new NamedValueInfo(name, info.required, defaultValue);
|
return new NamedValueInfo(name, info.required, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves the given parameter type and value name into an argument value.
|
* Resolves the given parameter type and value name into an argument value.
|
||||||
* @param name the name of the value being resolved
|
* @param name the name of the value being resolved
|
||||||
|
|
@ -165,7 +166,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when a named value is required, but {@link #resolveName(String, MethodParameter, NativeWebRequest)}
|
* Invoked when a named value is required, but {@link #resolveName(String, MethodParameter, NativeWebRequest)}
|
||||||
* returned {@code null} and there is no default value. Subclasses typically throw an exception in this case.
|
* returned {@code null} and there is no default value. Subclasses typically throw an exception in this case.
|
||||||
* @param name the name for the value
|
* @param name the name for the value
|
||||||
* @param parameter the method parameter
|
* @param parameter the method parameter
|
||||||
|
|
@ -219,4 +220,4 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
|
||||||
this.defaultValue = defaultValue;
|
this.defaultValue = defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -28,16 +28,16 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An abstract base class adapting a {@link WebArgumentResolver} to the
|
* An abstract base class adapting a {@link WebArgumentResolver} to the
|
||||||
* {@link HandlerMethodArgumentResolver} contract.
|
* {@link HandlerMethodArgumentResolver} contract.
|
||||||
*
|
*
|
||||||
* <p><strong>Note:</strong> This class is provided for backwards compatibility.
|
* <p><strong>Note:</strong> This class is provided for backwards compatibility.
|
||||||
* However it is recommended to re-write a {@code WebArgumentResolver} as
|
* However it is recommended to re-write a {@code WebArgumentResolver} as
|
||||||
* {@code HandlerMethodArgumentResolver}. Since {@link #supportsParameter}
|
* {@code HandlerMethodArgumentResolver}. Since {@link #supportsParameter}
|
||||||
* can only be implemented by actually resolving the value and then checking
|
* can only be implemented by actually resolving the value and then checking
|
||||||
* the result is not {@code WebArgumentResolver#UNRESOLVED} any exceptions
|
* the result is not {@code WebArgumentResolver#UNRESOLVED} any exceptions
|
||||||
* raised must be absorbed and ignored since it's not clear whether the adapter
|
* 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.
|
* doesn't support the parameter or whether it failed for an internal reason.
|
||||||
* The {@code HandlerMethodArgumentResolver} contract also provides access to
|
* The {@code HandlerMethodArgumentResolver} contract also provides access to
|
||||||
* model attributes and to {@code WebDataBinderFactory} (for type conversion).
|
* 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.
|
* {@link WebArgumentResolver#UNRESOLVED} absorbing _any_ exceptions.
|
||||||
*/
|
*/
|
||||||
public boolean supportsParameter(MethodParameter parameter) {
|
public boolean supportsParameter(MethodParameter parameter) {
|
||||||
|
|
@ -88,21 +88,22 @@ public abstract class AbstractWebArgumentResolverAdapter implements HandlerMetho
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delegate to the {@link WebArgumentResolver} instance.
|
* 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.
|
* to the method parameter.
|
||||||
*/
|
*/
|
||||||
public Object resolveArgument(MethodParameter parameter,
|
public Object resolveArgument(
|
||||||
ModelAndViewContainer mavContainer,
|
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||||
NativeWebRequest webRequest,
|
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||||
WebDataBinderFactory binderFactory) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
Class<?> paramType = parameter.getParameterType();
|
Class<?> paramType = parameter.getParameterType();
|
||||||
Object result = this.adaptee.resolveArgument(parameter, webRequest);
|
Object result = this.adaptee.resolveArgument(parameter, webRequest);
|
||||||
if (result == WebArgumentResolver.UNRESOLVED || !ClassUtils.isAssignableValue(paramType, result)) {
|
if (result == WebArgumentResolver.UNRESOLVED || !ClassUtils.isAssignableValue(paramType, result)) {
|
||||||
throw new IllegalStateException(
|
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) +
|
"resolved to incompatible value of type [" + (result != null ? result.getClass() : null) +
|
||||||
"]. Consider declaring the argument type in a less specific fashion.");
|
"]. Consider declaring the argument type in a less specific fashion.");
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.
|
* Resolves {@link Errors} method arguments.
|
||||||
*
|
*
|
||||||
* <p>An {@code Errors} method argument is expected to appear immediately after
|
* <p>An {@code Errors} method argument is expected to appear immediately after
|
||||||
* the model attribute in the method signature. It is resolved by expecting the
|
* 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
|
* last two attributes added to the model to be the model attribute and its
|
||||||
* {@link BindingResult}.
|
* {@link BindingResult}.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
|
|
@ -45,10 +45,11 @@ public class ErrorsMethodArgumentResolver implements HandlerMethodArgumentResolv
|
||||||
return Errors.class.isAssignableFrom(paramType);
|
return Errors.class.isAssignableFrom(paramType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object resolveArgument(MethodParameter parameter,
|
public Object resolveArgument(
|
||||||
ModelAndViewContainer mavContainer,
|
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||||
NativeWebRequest webRequest,
|
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||||
WebDataBinderFactory binderFactory) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
ModelMap model = mavContainer.getModel();
|
ModelMap model = mavContainer.getModel();
|
||||||
if (model.size() > 0) {
|
if (model.size() > 0) {
|
||||||
int lastIndex = model.size()-1;
|
int lastIndex = model.size()-1;
|
||||||
|
|
@ -63,4 +64,4 @@ public class ErrorsMethodArgumentResolver implements HandlerMethodArgumentResolv
|
||||||
"argument in the controller method signature: " + parameter.getMethod());
|
"argument in the controller method signature: " + parameter.getMethod());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.
|
* Resolves {@link Map} method arguments and handles {@link Map} return values.
|
||||||
*
|
*
|
||||||
* <p>A Map return value can be interpreted in more than one ways depending
|
* <p>A Map return value can be interpreted in more than one ways depending
|
||||||
* on the presence of annotations like {@code @ModelAttribute} or
|
* on the presence of annotations like {@code @ModelAttribute} or
|
||||||
* {@code @ResponseBody}. Therefore this handler should be configured after
|
* {@code @ResponseBody}. Therefore this handler should be configured after
|
||||||
* the handlers that support these annotations.
|
* the handlers that support these annotations.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
|
|
@ -42,10 +42,11 @@ public class MapMethodProcessor implements HandlerMethodArgumentResolver, Handle
|
||||||
return Map.class.isAssignableFrom(parameter.getParameterType());
|
return Map.class.isAssignableFrom(parameter.getParameterType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object resolveArgument(MethodParameter parameter,
|
public Object resolveArgument(
|
||||||
ModelAndViewContainer mavContainer,
|
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||||
NativeWebRequest webRequest,
|
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||||
WebDataBinderFactory binderFactory) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
return mavContainer.getModel();
|
return mavContainer.getModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,10 +55,11 @@ public class MapMethodProcessor implements HandlerMethodArgumentResolver, Handle
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
public void handleReturnValue(Object returnValue,
|
public void handleReturnValue(
|
||||||
MethodParameter returnType,
|
Object returnValue, MethodParameter returnType,
|
||||||
ModelAndViewContainer mavContainer,
|
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
|
||||||
NativeWebRequest webRequest) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
if (returnValue == null) {
|
if (returnValue == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -66,8 +68,8 @@ public class MapMethodProcessor implements HandlerMethodArgumentResolver, Handle
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// should not happen
|
// should not happen
|
||||||
throw new UnsupportedOperationException("Unexpected return type: " +
|
throw new UnsupportedOperationException("Unexpected return type: " +
|
||||||
returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
|
returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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
|
* Resolves method arguments annotated with {@code @ModelAttribute} and handles
|
||||||
* return values from methods annotated with {@code @ModelAttribute}.
|
* return values from methods annotated with {@code @ModelAttribute}.
|
||||||
*
|
*
|
||||||
* <p>Model attributes are obtained from the model or if not found possibly
|
* <p>Model attributes are obtained from the model or if not found possibly
|
||||||
* created with a default constructor if it is available. Once created, the
|
* created with a default constructor if it is available. Once created, the
|
||||||
* attributed is populated with request data via data binding and also
|
* attributed is populated with request data via data binding and also
|
||||||
* validation may be applied if the argument is annotated with
|
* validation may be applied if the argument is annotated with
|
||||||
* {@code @javax.validation.Valid}.
|
* {@code @javax.validation.Valid}.
|
||||||
*
|
*
|
||||||
* <p>When this handler is created with {@code annotationNotRequired=true},
|
* <p>When this handler is created with {@code annotationNotRequired=true},
|
||||||
* any non-simple type argument and return value is regarded as a model
|
* any non-simple type argument and return value is regarded as a model
|
||||||
* attribute with or without the presence of an {@code @ModelAttribute}.
|
* attribute with or without the presence of an {@code @ModelAttribute}.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
|
|
@ -58,10 +58,10 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
|
||||||
protected Log logger = LogFactory.getLog(this.getClass());
|
protected Log logger = LogFactory.getLog(this.getClass());
|
||||||
|
|
||||||
private final boolean annotationNotRequired;
|
private final boolean annotationNotRequired;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param annotationNotRequired if "true", non-simple method arguments and
|
* @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.
|
* {@code @ModelAttribute} annotation.
|
||||||
*/
|
*/
|
||||||
public ModelAttributeMethodProcessor(boolean annotationNotRequired) {
|
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
|
* 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
|
* its default if it is available. The model attribute is then populated
|
||||||
* with request values via data binding and optionally validated
|
* with request values via data binding and optionally validated
|
||||||
* if {@code @java.validation.Valid} is present on the argument.
|
* if {@code @java.validation.Valid} is present on the argument.
|
||||||
* @throws BindException if data binding and validation result in an error
|
* @throws BindException if data binding and validation result in an error
|
||||||
* and the next method parameter is not of type {@link Errors}.
|
* and the next method parameter is not of type {@link Errors}.
|
||||||
* @throws Exception if WebDataBinder initialization fails.
|
* @throws Exception if WebDataBinder initialization fails.
|
||||||
*/
|
*/
|
||||||
public final Object resolveArgument(MethodParameter parameter,
|
public final Object resolveArgument(
|
||||||
ModelAndViewContainer mavContainer,
|
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||||
NativeWebRequest request,
|
NativeWebRequest request, WebDataBinderFactory binderFactory)
|
||||||
WebDataBinderFactory binderFactory) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
String name = ModelFactory.getNameForParameter(parameter);
|
String name = ModelFactory.getNameForParameter(parameter);
|
||||||
Object target = (mavContainer.containsAttribute(name)) ?
|
Object target = (mavContainer.containsAttribute(name)) ?
|
||||||
mavContainer.getModel().get(name) : createAttribute(name, parameter, binderFactory, request);
|
mavContainer.getModel().get(name) : createAttribute(name, parameter, binderFactory, request);
|
||||||
|
|
@ -130,7 +131,7 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
|
||||||
|
|
||||||
return BeanUtils.instantiateClass(parameter.getParameterType());
|
return BeanUtils.instantiateClass(parameter.getParameterType());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extension point to bind the request to the target object.
|
* Extension point to bind the request to the target object.
|
||||||
* @param binder the data binder instance to use for the binding
|
* @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.
|
* 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}.
|
* argument is not of type {@link Errors}.
|
||||||
* @param binder the data binder used to perform data binding
|
* @param binder the data binder used to perform data binding
|
||||||
* @param parameter the method argument
|
* @param parameter the method argument
|
||||||
|
|
@ -167,12 +168,12 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
|
||||||
int i = parameter.getParameterIndex();
|
int i = parameter.getParameterIndex();
|
||||||
Class<?>[] paramTypes = parameter.getMethod().getParameterTypes();
|
Class<?>[] paramTypes = parameter.getMethod().getParameterTypes();
|
||||||
boolean hasBindingResult = (paramTypes.length > (i + 1) && Errors.class.isAssignableFrom(paramTypes[i + 1]));
|
boolean hasBindingResult = (paramTypes.length > (i + 1) && Errors.class.isAssignableFrom(paramTypes[i + 1]));
|
||||||
|
|
||||||
return !hasBindingResult;
|
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}.
|
* or if it is a non-simple type when {@code annotationNotRequired=true}.
|
||||||
*/
|
*/
|
||||||
public boolean supportsReturnType(MethodParameter returnType) {
|
public boolean supportsReturnType(MethodParameter returnType) {
|
||||||
|
|
@ -190,13 +191,14 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
|
||||||
/**
|
/**
|
||||||
* Add non-null return values to the {@link ModelAndViewContainer}.
|
* Add non-null return values to the {@link ModelAndViewContainer}.
|
||||||
*/
|
*/
|
||||||
public void handleReturnValue(Object returnValue,
|
public void handleReturnValue(
|
||||||
MethodParameter returnType,
|
Object returnValue, MethodParameter returnType,
|
||||||
ModelAndViewContainer mavContainer,
|
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
|
||||||
NativeWebRequest webRequest) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
if (returnValue != null) {
|
if (returnValue != null) {
|
||||||
String name = ModelFactory.getNameForReturnValue(returnValue, returnType);
|
String name = ModelFactory.getNameForReturnValue(returnValue, returnType);
|
||||||
mavContainer.addAttribute(name, returnValue);
|
mavContainer.addAttribute(name, returnValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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;
|
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves {@link Model} arguments and handles {@link Model} return values.
|
* Resolves {@link Model} arguments and handles {@link Model} return values.
|
||||||
*
|
*
|
||||||
* <p>A {@link Model} return type has a set purpose. Therefore this handler
|
* <p>A {@link Model} return type has a set purpose. Therefore this handler
|
||||||
* should be configured ahead of handlers that support any return value type
|
* should be configured ahead of handlers that support any return value type
|
||||||
* annotated with {@code @ModelAttribute} or {@code @ResponseBody} to ensure
|
* annotated with {@code @ModelAttribute} or {@code @ResponseBody} to ensure
|
||||||
* they don't take over.
|
* they don't take over.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
|
|
@ -41,10 +41,11 @@ public class ModelMethodProcessor implements HandlerMethodArgumentResolver, Hand
|
||||||
return Model.class.isAssignableFrom(parameter.getParameterType());
|
return Model.class.isAssignableFrom(parameter.getParameterType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object resolveArgument(MethodParameter parameter,
|
public Object resolveArgument(
|
||||||
ModelAndViewContainer mavContainer,
|
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||||
NativeWebRequest webRequest,
|
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||||
WebDataBinderFactory binderFactory) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
return mavContainer.getModel();
|
return mavContainer.getModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,10 +53,11 @@ public class ModelMethodProcessor implements HandlerMethodArgumentResolver, Hand
|
||||||
return Model.class.isAssignableFrom(returnType.getParameterType());
|
return Model.class.isAssignableFrom(returnType.getParameterType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleReturnValue(Object returnValue,
|
public void handleReturnValue(
|
||||||
MethodParameter returnType,
|
Object returnValue, MethodParameter returnType,
|
||||||
ModelAndViewContainer mavContainer,
|
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
|
||||||
NativeWebRequest webRequest) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
if (returnValue == null) {
|
if (returnValue == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -64,8 +66,8 @@ public class ModelMethodProcessor implements HandlerMethodArgumentResolver, Hand
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// should not happen
|
// should not happen
|
||||||
throw new UnsupportedOperationException("Unexpected return type: " +
|
throw new UnsupportedOperationException("Unexpected return type: " +
|
||||||
returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
|
returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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;
|
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves {@link Map} method arguments annotated with {@code @RequestHeader}.
|
* Resolves {@link Map} method arguments annotated with {@code @RequestHeader}.
|
||||||
* For individual header values annotated with {@code @RequestHeader} see
|
* For individual header values annotated with {@code @RequestHeader} see
|
||||||
* {@link RequestHeaderMethodArgumentResolver} instead.
|
* {@link RequestHeaderMethodArgumentResolver} instead.
|
||||||
*
|
*
|
||||||
* <p>The created {@link Map} contains all request header name/value pairs.
|
* <p>The created {@link Map} contains all request header name/value pairs.
|
||||||
* The method parameter type may be a {@link MultiValueMap} to receive all
|
* 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 Arjen Poutsma
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
|
|
@ -50,10 +50,11 @@ public class RequestHeaderMapMethodArgumentResolver implements HandlerMethodArgu
|
||||||
&& Map.class.isAssignableFrom(parameter.getParameterType());
|
&& Map.class.isAssignableFrom(parameter.getParameterType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object resolveArgument(MethodParameter parameter,
|
public Object resolveArgument(
|
||||||
ModelAndViewContainer mavContainer,
|
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||||
NativeWebRequest webRequest,
|
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||||
WebDataBinderFactory binderFactory) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
Class<?> paramType = parameter.getParameterType();
|
Class<?> paramType = parameter.getParameterType();
|
||||||
|
|
||||||
if (MultiValueMap.class.isAssignableFrom(paramType)) {
|
if (MultiValueMap.class.isAssignableFrom(paramType)) {
|
||||||
|
|
@ -82,4 +83,4 @@ public class RequestHeaderMapMethodArgumentResolver implements HandlerMethodArgu
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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;
|
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves {@link Map} method arguments annotated with an @{@link RequestParam} where the annotation does not
|
* 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}
|
* specify a request parameter name. See {@link RequestParamMethodArgumentResolver} for resolving {@link Map}
|
||||||
* method arguments with a request parameter name.
|
* method arguments with a request parameter name.
|
||||||
*
|
*
|
||||||
* <p>The created {@link Map} contains all request parameter name/value pairs. If the method parameter type
|
* <p>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
|
* is {@link MultiValueMap} instead, the created map contains all request parameters and all there values for
|
||||||
* cases where request parameters have multiple values.
|
* cases where request parameters have multiple values.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
|
|
@ -55,10 +55,11 @@ public class RequestParamMapMethodArgumentResolver implements HandlerMethodArgum
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object resolveArgument(MethodParameter parameter,
|
public Object resolveArgument(
|
||||||
ModelAndViewContainer mavContainer,
|
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||||
NativeWebRequest webRequest,
|
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||||
WebDataBinderFactory binderFactory) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
Class<?> paramType = parameter.getParameterType();
|
Class<?> paramType = parameter.getParameterType();
|
||||||
|
|
||||||
Map<String, String[]> parameterMap = webRequest.getParameterMap();
|
Map<String, String[]> parameterMap = webRequest.getParameterMap();
|
||||||
|
|
@ -81,4 +82,4 @@ public class RequestParamMapMethodArgumentResolver implements HandlerMethodArgum
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -24,7 +24,7 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves a {@link SessionStatus} argument by obtaining it from
|
* Resolves a {@link SessionStatus} argument by obtaining it from
|
||||||
* the {@link ModelAndViewContainer}.
|
* the {@link ModelAndViewContainer}.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
|
|
@ -36,10 +36,11 @@ public class SessionStatusMethodArgumentResolver implements HandlerMethodArgumen
|
||||||
return SessionStatus.class.equals(parameter.getParameterType());
|
return SessionStatus.class.equals(parameter.getParameterType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object resolveArgument(MethodParameter parameter,
|
public Object resolveArgument(
|
||||||
ModelAndViewContainer mavContainer,
|
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||||
NativeWebRequest webRequest,
|
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||||
WebDataBinderFactory binderFactory) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
return mavContainer.getSessionStatus();
|
return mavContainer.getSessionStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -31,8 +31,8 @@ import org.springframework.web.context.request.NativeWebRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves method parameters by delegating to a list of registered {@link HandlerMethodArgumentResolver}s.
|
* Resolves method parameters by delegating to a list of registered {@link HandlerMethodArgumentResolver}s.
|
||||||
* Previously resolved method parameters are cached for faster lookups.
|
* Previously resolved method parameters are cached for faster lookups.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
|
|
@ -40,12 +40,12 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu
|
||||||
|
|
||||||
protected final Log logger = LogFactory.getLog(getClass());
|
protected final Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
private final List<HandlerMethodArgumentResolver> argumentResolvers =
|
private final List<HandlerMethodArgumentResolver> argumentResolvers =
|
||||||
new ArrayList<HandlerMethodArgumentResolver>();
|
new ArrayList<HandlerMethodArgumentResolver>();
|
||||||
|
|
||||||
private final Map<MethodParameter, HandlerMethodArgumentResolver> argumentResolverCache =
|
private final Map<MethodParameter, HandlerMethodArgumentResolver> argumentResolverCache =
|
||||||
new ConcurrentHashMap<MethodParameter, HandlerMethodArgumentResolver>();
|
new ConcurrentHashMap<MethodParameter, HandlerMethodArgumentResolver>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a read-only list with the contained resolvers, or an empty list.
|
* Return a read-only list with the contained resolvers, or an empty list.
|
||||||
*/
|
*/
|
||||||
|
|
@ -54,7 +54,7 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the given {@linkplain MethodParameter method parameter} is supported by any registered
|
* Whether the given {@linkplain MethodParameter method parameter} is supported by any registered
|
||||||
* {@link HandlerMethodArgumentResolver}.
|
* {@link HandlerMethodArgumentResolver}.
|
||||||
*/
|
*/
|
||||||
public boolean supportsParameter(MethodParameter parameter) {
|
public boolean supportsParameter(MethodParameter parameter) {
|
||||||
|
|
@ -65,10 +65,11 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu
|
||||||
* Iterate over registered {@link HandlerMethodArgumentResolver}s and invoke the one that supports it.
|
* Iterate over registered {@link HandlerMethodArgumentResolver}s and invoke the one that supports it.
|
||||||
* @exception IllegalStateException if no suitable {@link HandlerMethodArgumentResolver} is found.
|
* @exception IllegalStateException if no suitable {@link HandlerMethodArgumentResolver} is found.
|
||||||
*/
|
*/
|
||||||
public Object resolveArgument(MethodParameter parameter,
|
public Object resolveArgument(
|
||||||
ModelAndViewContainer mavContainer,
|
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||||
NativeWebRequest webRequest,
|
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||||
WebDataBinderFactory binderFactory) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
HandlerMethodArgumentResolver resolver = getArgumentResolver(parameter);
|
HandlerMethodArgumentResolver resolver = getArgumentResolver(parameter);
|
||||||
Assert.notNull(resolver, "Unknown parameter type [" + parameter.getParameterType().getName() + "]");
|
Assert.notNull(resolver, "Unknown parameter type [" + parameter.getParameterType().getName() + "]");
|
||||||
return resolver.resolveArgument(parameter, mavContainer, webRequest, binderFactory);
|
return resolver.resolveArgument(parameter, mavContainer, webRequest, binderFactory);
|
||||||
|
|
@ -94,7 +95,7 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the given {@link HandlerMethodArgumentResolver}.
|
* Add the given {@link HandlerMethodArgumentResolver}.
|
||||||
*/
|
*/
|
||||||
|
|
@ -116,4 +117,4 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -29,17 +29,17 @@ import org.springframework.util.Assert;
|
||||||
import org.springframework.web.context.request.NativeWebRequest;
|
import org.springframework.web.context.request.NativeWebRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles method return values by delegating to a list of registered {@link HandlerMethodReturnValueHandler}s.
|
* Handles method return values by delegating to a list of registered {@link HandlerMethodReturnValueHandler}s.
|
||||||
* Previously resolved return types are cached for faster lookups.
|
* Previously resolved return types are cached for faster lookups.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodReturnValueHandler {
|
public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodReturnValueHandler {
|
||||||
|
|
||||||
protected final Log logger = LogFactory.getLog(getClass());
|
protected final Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
private final List<HandlerMethodReturnValueHandler> returnValueHandlers =
|
private final List<HandlerMethodReturnValueHandler> returnValueHandlers =
|
||||||
new ArrayList<HandlerMethodReturnValueHandler>();
|
new ArrayList<HandlerMethodReturnValueHandler>();
|
||||||
|
|
||||||
private final Map<MethodParameter, HandlerMethodReturnValueHandler> returnValueHandlerCache =
|
private final Map<MethodParameter, HandlerMethodReturnValueHandler> returnValueHandlerCache =
|
||||||
|
|
@ -53,7 +53,7 @@ public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodRe
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the given {@linkplain MethodParameter method return type} is supported by any registered
|
* Whether the given {@linkplain MethodParameter method return type} is supported by any registered
|
||||||
* {@link HandlerMethodReturnValueHandler}.
|
* {@link HandlerMethodReturnValueHandler}.
|
||||||
*/
|
*/
|
||||||
public boolean supportsReturnType(MethodParameter returnType) {
|
public boolean supportsReturnType(MethodParameter returnType) {
|
||||||
|
|
@ -64,10 +64,11 @@ public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodRe
|
||||||
* Iterate over registered {@link HandlerMethodReturnValueHandler}s and invoke the one that supports it.
|
* Iterate over registered {@link HandlerMethodReturnValueHandler}s and invoke the one that supports it.
|
||||||
* @exception IllegalStateException if no suitable {@link HandlerMethodReturnValueHandler} is found.
|
* @exception IllegalStateException if no suitable {@link HandlerMethodReturnValueHandler} is found.
|
||||||
*/
|
*/
|
||||||
public void handleReturnValue(Object returnValue,
|
public void handleReturnValue(
|
||||||
MethodParameter returnType,
|
Object returnValue, MethodParameter returnType,
|
||||||
ModelAndViewContainer mavContainer,
|
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
|
||||||
NativeWebRequest webRequest) throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
HandlerMethodReturnValueHandler handler = getReturnValueHandler(returnType);
|
HandlerMethodReturnValueHandler handler = getReturnValueHandler(returnType);
|
||||||
Assert.notNull(handler, "Unknown return value type [" + returnType.getParameterType().getName() + "]");
|
Assert.notNull(handler, "Unknown return value type [" + returnType.getParameterType().getName() + "]");
|
||||||
handler.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
|
handler.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
|
||||||
|
|
@ -92,8 +93,8 @@ public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodRe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the given {@link HandlerMethodReturnValueHandler}.
|
* Add the given {@link HandlerMethodReturnValueHandler}.
|
||||||
*/
|
*/
|
||||||
|
|
@ -115,4 +116,4 @@ public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodRe
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -32,16 +32,16 @@ import org.springframework.web.context.request.NativeWebRequest;
|
||||||
import org.springframework.web.method.HandlerMethod;
|
import org.springframework.web.method.HandlerMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a method for invoking the handler method for a given request after resolving its method argument
|
* Provides a method for invoking the handler method for a given request after resolving its method argument
|
||||||
* values through registered {@link HandlerMethodArgumentResolver}s.
|
* values through registered {@link HandlerMethodArgumentResolver}s.
|
||||||
*
|
*
|
||||||
* <p>Argument resolution often requires a {@link WebDataBinder} for data binding or for type conversion.
|
* <p>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
|
* Use the {@link #setDataBinderFactory(WebDataBinderFactory)} property to supply a binder factory to pass to
|
||||||
* argument resolvers.
|
* argument resolvers.
|
||||||
*
|
*
|
||||||
* <p>Use {@link #setHandlerMethodArgumentResolvers(HandlerMethodArgumentResolverComposite)} to customize
|
* <p>Use {@link #setHandlerMethodArgumentResolvers(HandlerMethodArgumentResolverComposite)} to customize
|
||||||
* the list of argument resolvers.
|
* the list of argument resolvers.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 3.1
|
* @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. <p>Argument
|
* Invoke the method after resolving its argument values in the context of the given request. <p>Argument
|
||||||
* values are commonly resolved through {@link HandlerMethodArgumentResolver}s. The {@code provideArgs}
|
* 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.
|
* 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
|
* 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.
|
* a thrown exception instance. Provided argument values are checked before argument resolvers.
|
||||||
*
|
*
|
||||||
* @param request the current request
|
* @param request the current request
|
||||||
* @param mavContainer the {@link ModelAndViewContainer} for the current request
|
* @param mavContainer the {@link ModelAndViewContainer} for the current request
|
||||||
* @param providedArgs argument values to try to use without view resolution
|
* @param providedArgs argument values to try to use without view resolution
|
||||||
* @return the raw value returned by the invoked method
|
* @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,
|
public final Object invokeForRequest(NativeWebRequest request,
|
||||||
ModelAndViewContainer mavContainer,
|
ModelAndViewContainer mavContainer,
|
||||||
Object... providedArgs) throws Exception {
|
Object... providedArgs) throws Exception {
|
||||||
Object[] args = getMethodArgumentValues(request, mavContainer, providedArgs);
|
Object[] args = getMethodArgumentValues(request, mavContainer, providedArgs);
|
||||||
|
|
||||||
|
|
@ -135,9 +135,10 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||||
/**
|
/**
|
||||||
* Get the method argument values for the current request.
|
* Get the method argument values for the current request.
|
||||||
*/
|
*/
|
||||||
private Object[] getMethodArgumentValues(NativeWebRequest request,
|
private Object[] getMethodArgumentValues(
|
||||||
ModelAndViewContainer mavContainer,
|
NativeWebRequest request, ModelAndViewContainer mavContainer,
|
||||||
Object... providedArgs) throws Exception {
|
Object... providedArgs) throws Exception {
|
||||||
|
|
||||||
MethodParameter[] parameters = getMethodParameters();
|
MethodParameter[] parameters = getMethodParameters();
|
||||||
Object[] args = new Object[parameters.length];
|
Object[] args = new Object[parameters.length];
|
||||||
for (int i = 0; i < parameters.length; i++) {
|
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");
|
sb.append("Method [").append(getBridgedMethod().toGenericString()).append("]\n");
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to resolve a method parameter from the list of provided argument values.
|
* Attempt to resolve a method parameter from the list of provided argument values.
|
||||||
*/
|
*/
|
||||||
|
|
@ -202,7 +203,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoke the handler method with the given argument values.
|
* Invoke the handler method with the given argument values.
|
||||||
*/
|
*/
|
||||||
|
|
@ -215,7 +216,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||||
String msg = getInvocationErrorMessage(e.getMessage(), args);
|
String msg = getInvocationErrorMessage(e.getMessage(), args);
|
||||||
throw new IllegalArgumentException(msg, e);
|
throw new IllegalArgumentException(msg, e);
|
||||||
}
|
}
|
||||||
catch (InvocationTargetException e) {
|
catch (InvocationTargetException e) {
|
||||||
// Unwrap for HandlerExceptionResolvers ...
|
// Unwrap for HandlerExceptionResolvers ...
|
||||||
Throwable targetException = e.getTargetException();
|
Throwable targetException = e.getTargetException();
|
||||||
if (targetException instanceof RuntimeException) {
|
if (targetException instanceof RuntimeException) {
|
||||||
|
|
@ -233,7 +234,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getInvocationErrorMessage(String message, Object[] resolvedArgs) {
|
private String getInvocationErrorMessage(String message, Object[] resolvedArgs) {
|
||||||
StringBuilder sb = new StringBuilder(getDetailedErrorMessage(message));
|
StringBuilder sb = new StringBuilder(getDetailedErrorMessage(message));
|
||||||
sb.append("Resolved arguments: \n");
|
sb.append("Resolved arguments: \n");
|
||||||
|
|
@ -250,4 +251,4 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue