Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
ffec4444
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ffec4444
编写于
4月 06, 2011
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Configurable arg resolvers and return value handlers
上级
ca9a3b45
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
224 addition
and
113 deletion
+224
-113
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMethodAdapter.java
...method/annotation/RequestMappingHandlerMethodAdapter.java
+107
-41
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMethodExceptionResolver.java
...otation/RequestMappingHandlerMethodExceptionResolver.java
+57
-11
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java
.../mvc/method/annotation/ServletInvocableHandlerMethod.java
+4
-4
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ControllerMethodAnnotationDetectionTests.java
.../annotation/ControllerMethodAnnotationDetectionTests.java
+6
-6
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethodTests.java
...method/annotation/ServletInvocableHandlerMethodTests.java
+3
-3
org.springframework.web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolverComposite.java
...ethod/support/HandlerMethodArgumentResolverComposite.java
+4
-4
org.springframework.web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerComposite.java
...hod/support/HandlerMethodReturnValueHandlerComposite.java
+4
-4
org.springframework.web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java
...gframework/web/method/support/InvocableHandlerMethod.java
+4
-5
org.springframework.web/src/test/java/org/springframework/web/method/annotation/InitBinderMethodDataBinderFactoryTests.java
...od/annotation/InitBinderMethodDataBinderFactoryTests.java
+5
-5
org.springframework.web/src/test/java/org/springframework/web/method/annotation/ModelFactoryTests.java
...ingframework/web/method/annotation/ModelFactoryTests.java
+3
-3
org.springframework.web/src/test/java/org/springframework/web/method/support/HandlerMethodArgumentResolverCompositeTests.java
.../support/HandlerMethodArgumentResolverCompositeTests.java
+12
-12
org.springframework.web/src/test/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerCompositeTests.java
...upport/HandlerMethodReturnValueHandlerCompositeTests.java
+12
-12
org.springframework.web/src/test/java/org/springframework/web/method/support/InvocableHandlerMethodTests.java
...ework/web/method/support/InvocableHandlerMethodTests.java
+3
-3
未找到文件。
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMethodAdapter.java
浏览文件 @
ffec4444
...
...
@@ -68,8 +68,10 @@ import org.springframework.web.method.annotation.support.RequestHeaderMethodArgu
import
org.springframework.web.method.annotation.support.RequestParamMapMethodArgumentResolver
;
import
org.springframework.web.method.annotation.support.RequestParamMethodArgumentResolver
;
import
org.springframework.web.method.annotation.support.WebArgumentResolverAdapter
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolverContainer
;
import
org.springframework.web.method.support.HandlerMethodReturnValueHandlerContainer
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolver
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolverComposite
;
import
org.springframework.web.method.support.HandlerMethodReturnValueHandler
;
import
org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite
;
import
org.springframework.web.method.support.InvocableHandlerMethod
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver
;
...
...
@@ -120,11 +122,11 @@ public class RequestMappingHandlerMethodAdapter extends AbstractHandlerMethodAda
private
final
Map
<
Class
<?>,
Set
<
Method
>>
initBinderMethodCache
=
new
ConcurrentHashMap
<
Class
<?>,
Set
<
Method
>>();
private
final
HandlerMethodReturnValueHandlerContainer
returnValueHandlers
=
new
HandlerMethodReturnValueHandlerContainer
()
;
private
HandlerMethodReturnValueHandlerComposite
returnValueHandlers
;
private
final
HandlerMethodArgumentResolverContainer
requestMethodArgResolvers
=
new
HandlerMethodArgumentResolverContainer
()
;
private
HandlerMethodArgumentResolverComposite
argumentResolvers
;
private
final
HandlerMethodArgumentResolverContainer
binderMethodArgResolvers
=
new
HandlerMethodArgumentResolverContainer
()
;
private
HandlerMethodArgumentResolverComposite
initBinderArgumentResolvers
;
/**
* Create a {@link RequestMappingHandlerMethodAdapter} instance.
...
...
@@ -244,6 +246,42 @@ public class RequestMappingHandlerMethodAdapter extends AbstractHandlerMethodAda
this
.
parameterNameDiscoverer
=
parameterNameDiscoverer
;
}
/**
* Set the {@link HandlerMethodArgumentResolver}s to use to resolve argument values for {@link RequestMapping}
* and {@link ModelAttribute} methods. This is an optional property.
* @param argumentResolvers the argument resolvers to use
*/
public
void
setHandlerMethodArgumentResolvers
(
HandlerMethodArgumentResolver
[]
argumentResolvers
)
{
this
.
argumentResolvers
=
new
HandlerMethodArgumentResolverComposite
();
for
(
HandlerMethodArgumentResolver
resolver
:
argumentResolvers
)
{
this
.
argumentResolvers
.
registerArgumentResolver
(
resolver
);
}
}
/**
* Set the {@link HandlerMethodReturnValueHandler}s to use to handle the return values of
* {@link RequestMapping} methods. This is an optional property.
* @param returnValueHandlers the return value handlers to use
*/
public
void
setHandlerMethodReturnValueHandlers
(
HandlerMethodReturnValueHandler
[]
returnValueHandlers
)
{
this
.
returnValueHandlers
=
new
HandlerMethodReturnValueHandlerComposite
();
for
(
HandlerMethodReturnValueHandler
handler
:
returnValueHandlers
)
{
this
.
returnValueHandlers
.
registerReturnValueHandler
(
handler
);
}
}
/**
* Set the {@link HandlerMethodArgumentResolver}s to use to resolve argument values for {@link InitBinder}
* methods. This is an optional property.
* @param argumentResolvers the argument resolvers to use
*/
public
void
setInitBinderMethodArgumentResolvers
(
HandlerMethodArgumentResolver
[]
argumentResolvers
)
{
this
.
initBinderArgumentResolvers
=
new
HandlerMethodArgumentResolverComposite
();
for
(
HandlerMethodArgumentResolver
resolver
:
argumentResolvers
)
{
this
.
initBinderArgumentResolvers
.
registerArgumentResolver
(
resolver
);
}
}
public
void
setBeanFactory
(
BeanFactory
beanFactory
)
{
if
(
beanFactory
instanceof
ConfigurableBeanFactory
)
{
this
.
beanFactory
=
(
ConfigurableBeanFactory
)
beanFactory
;
...
...
@@ -251,61 +289,89 @@ public class RequestMappingHandlerMethodAdapter extends AbstractHandlerMethodAda
}
public
void
afterPropertiesSet
()
throws
Exception
{
init
RequestMethodArg
Resolvers
();
init
BinderMethodArgResolv
ers
();
init
ReturnValueHandl
ers
();
init
HandlerMethodArgument
Resolvers
();
init
HandlerMethodReturnValueHandl
ers
();
init
BinderMethodArgumentResolv
ers
();
}
private
void
initRequestMethodArgResolvers
()
{
requestMethodArgResolvers
.
registerArgumentResolver
(
new
RequestParamMethodArgumentResolver
(
beanFactory
,
false
));
requestMethodArgResolvers
.
registerArgumentResolver
(
new
RequestParamMapMethodArgumentResolver
());
requestMethodArgResolvers
.
registerArgumentResolver
(
new
PathVariableMethodArgumentResolver
(
beanFactory
));
requestMethodArgResolvers
.
registerArgumentResolver
(
new
ServletModelAttributeMethodProcessor
(
false
));
requestMethodArgResolvers
.
registerArgumentResolver
(
new
RequestResponseBodyMethodProcessor
(
messageConverters
));
requestMethodArgResolvers
.
registerArgumentResolver
(
new
RequestHeaderMethodArgumentResolver
(
beanFactory
));
requestMethodArgResolvers
.
registerArgumentResolver
(
new
RequestHeaderMapMethodArgumentResolver
());
requestMethodArgResolvers
.
registerArgumentResolver
(
new
ServletCookieValueMethodArgumentResolver
(
beanFactory
));
requestMethodArgResolvers
.
registerArgumentResolver
(
new
ExpressionValueMethodArgumentResolver
(
beanFactory
));
private
void
initHandlerMethodArgumentResolvers
()
{
if
(
argumentResolvers
!=
null
)
{
return
;
}
argumentResolvers
=
new
HandlerMethodArgumentResolverComposite
();
// Annotation-based resolvers
argumentResolvers
.
registerArgumentResolver
(
new
RequestParamMethodArgumentResolver
(
beanFactory
,
false
));
argumentResolvers
.
registerArgumentResolver
(
new
RequestParamMapMethodArgumentResolver
());
argumentResolvers
.
registerArgumentResolver
(
new
PathVariableMethodArgumentResolver
(
beanFactory
));
argumentResolvers
.
registerArgumentResolver
(
new
ServletModelAttributeMethodProcessor
(
false
));
argumentResolvers
.
registerArgumentResolver
(
new
RequestResponseBodyMethodProcessor
(
messageConverters
));
argumentResolvers
.
registerArgumentResolver
(
new
RequestHeaderMethodArgumentResolver
(
beanFactory
));
argumentResolvers
.
registerArgumentResolver
(
new
RequestHeaderMapMethodArgumentResolver
());
argumentResolvers
.
registerArgumentResolver
(
new
ServletCookieValueMethodArgumentResolver
(
beanFactory
));
argumentResolvers
.
registerArgumentResolver
(
new
ExpressionValueMethodArgumentResolver
(
beanFactory
));
if
(
customArgumentResolvers
!=
null
)
{
for
(
WebArgumentResolver
customResolver
:
customArgumentResolvers
)
{
requestMethodArg
Resolvers
.
registerArgumentResolver
(
new
WebArgumentResolverAdapter
(
customResolver
));
argument
Resolvers
.
registerArgumentResolver
(
new
WebArgumentResolverAdapter
(
customResolver
));
}
}
requestMethodArgResolvers
.
registerArgumentResolver
(
new
ServletRequestMethodArgumentResolver
());
requestMethodArgResolvers
.
registerArgumentResolver
(
new
ServletResponseMethodArgumentResolver
());
requestMethodArgResolvers
.
registerArgumentResolver
(
new
HttpEntityMethodProcessor
(
messageConverters
));
requestMethodArgResolvers
.
registerArgumentResolver
(
new
ModelMethodProcessor
());
requestMethodArgResolvers
.
registerArgumentResolver
(
new
ErrorsMethodArgumentResolver
());
requestMethodArgResolvers
.
registerArgumentResolver
(
new
RequestParamMethodArgumentResolver
(
beanFactory
,
true
));
requestMethodArgResolvers
.
registerArgumentResolver
(
new
ServletModelAttributeMethodProcessor
(
true
));
// Type-based resolvers
argumentResolvers
.
registerArgumentResolver
(
new
ServletRequestMethodArgumentResolver
());
argumentResolvers
.
registerArgumentResolver
(
new
ServletResponseMethodArgumentResolver
());
argumentResolvers
.
registerArgumentResolver
(
new
HttpEntityMethodProcessor
(
messageConverters
));
argumentResolvers
.
registerArgumentResolver
(
new
ModelMethodProcessor
());
argumentResolvers
.
registerArgumentResolver
(
new
ErrorsMethodArgumentResolver
());
// Default-mode resolution
argumentResolvers
.
registerArgumentResolver
(
new
RequestParamMethodArgumentResolver
(
beanFactory
,
true
));
argumentResolvers
.
registerArgumentResolver
(
new
ServletModelAttributeMethodProcessor
(
true
));
}
private
void
initBinderMethodArgResolvers
()
{
binderMethodArgResolvers
.
registerArgumentResolver
(
new
RequestParamMethodArgumentResolver
(
beanFactory
,
false
));
binderMethodArgResolvers
.
registerArgumentResolver
(
new
RequestParamMapMethodArgumentResolver
());
binderMethodArgResolvers
.
registerArgumentResolver
(
new
PathVariableMethodArgumentResolver
(
beanFactory
));
binderMethodArgResolvers
.
registerArgumentResolver
(
new
ExpressionValueMethodArgumentResolver
(
beanFactory
));
private
void
initBinderMethodArgumentResolvers
()
{
if
(
initBinderArgumentResolvers
!=
null
)
{
return
;
}
initBinderArgumentResolvers
=
new
HandlerMethodArgumentResolverComposite
();
// Annotation-based resolvers
initBinderArgumentResolvers
.
registerArgumentResolver
(
new
RequestParamMethodArgumentResolver
(
beanFactory
,
false
));
initBinderArgumentResolvers
.
registerArgumentResolver
(
new
RequestParamMapMethodArgumentResolver
());
initBinderArgumentResolvers
.
registerArgumentResolver
(
new
PathVariableMethodArgumentResolver
(
beanFactory
));
initBinderArgumentResolvers
.
registerArgumentResolver
(
new
ExpressionValueMethodArgumentResolver
(
beanFactory
));
if
(
customArgumentResolvers
!=
null
)
{
for
(
WebArgumentResolver
customResolver
:
customArgumentResolvers
)
{
binderMethodArg
Resolvers
.
registerArgumentResolver
(
new
WebArgumentResolverAdapter
(
customResolver
));
initBinderArgument
Resolvers
.
registerArgumentResolver
(
new
WebArgumentResolverAdapter
(
customResolver
));
}
}
// Type-based resolvers
initBinderArgumentResolvers
.
registerArgumentResolver
(
new
ServletRequestMethodArgumentResolver
());
initBinderArgumentResolvers
.
registerArgumentResolver
(
new
ServletResponseMethodArgumentResolver
());
binderMethodArgResolvers
.
registerArgumentResolver
(
new
ServletRequestMethodArgumentResolver
());
binderMethodArgResolvers
.
registerArgumentResolver
(
new
ServletResponseMethodArgumentResolver
());
binderMethodArgResolvers
.
registerArgumentResolver
(
new
RequestParamMethodArgumentResolver
(
beanFactory
,
true
));
// Default-mode resolution
initBinderArgumentResolvers
.
registerArgumentResolver
(
new
RequestParamMethodArgumentResolver
(
beanFactory
,
true
));
}
private
void
initReturnValueHandlers
()
{
private
void
initHandlerMethodReturnValueHandlers
()
{
if
(
returnValueHandlers
!=
null
)
{
return
;
}
returnValueHandlers
=
new
HandlerMethodReturnValueHandlerComposite
();
// Annotation-based handlers
returnValueHandlers
.
registerReturnValueHandler
(
new
RequestResponseBodyMethodProcessor
(
messageConverters
));
returnValueHandlers
.
registerReturnValueHandler
(
new
ModelAttributeMethodProcessor
(
false
));
// Type-based handlers
returnValueHandlers
.
registerReturnValueHandler
(
new
ModelAndViewMethodReturnValueHandler
());
returnValueHandlers
.
registerReturnValueHandler
(
new
ModelMethodProcessor
());
returnValueHandlers
.
registerReturnValueHandler
(
new
ViewMethodReturnValueHandler
());
returnValueHandlers
.
registerReturnValueHandler
(
new
HttpEntityMethodProcessor
(
messageConverters
));
// Default handler
returnValueHandlers
.
registerReturnValueHandler
(
new
DefaultMethodReturnValueHandler
(
customModelAndViewResolvers
));
}
...
...
@@ -317,7 +383,7 @@ public class RequestMappingHandlerMethodAdapter extends AbstractHandlerMethodAda
private
boolean
supportsMethodParameters
(
MethodParameter
[]
methodParameters
)
{
for
(
MethodParameter
methodParameter
:
methodParameters
)
{
if
(!
this
.
requestMethodArg
Resolvers
.
supportsParameter
(
methodParameter
))
{
if
(!
this
.
argument
Resolvers
.
supportsParameter
(
methodParameter
))
{
return
false
;
}
}
...
...
@@ -407,7 +473,7 @@ public class RequestMappingHandlerMethodAdapter extends AbstractHandlerMethodAda
for
(
Method
method
:
binderMethods
)
{
Object
bean
=
handlerMethod
.
getBean
();
InvocableHandlerMethod
binderMethod
=
new
InvocableHandlerMethod
(
bean
,
method
);
binderMethod
.
set
ArgumentResolverContainer
(
this
.
binderMethodArg
Resolvers
);
binderMethod
.
set
HandlerMethodArgumentResolvers
(
this
.
initBinderArgument
Resolvers
);
binderMethod
.
setDataBinderFactory
(
new
DefaultDataBinderFactory
(
this
.
webBindingInitializer
));
binderMethod
.
setParameterNameDiscoverer
(
this
.
parameterNameDiscoverer
);
...
...
@@ -429,7 +495,7 @@ public class RequestMappingHandlerMethodAdapter extends AbstractHandlerMethodAda
for
(
Method
method
:
attributeMethods
)
{
InvocableHandlerMethod
attrMethod
=
new
InvocableHandlerMethod
(
handlerMethod
.
getBean
(),
method
);
attrMethod
.
set
ArgumentResolverContainer
(
this
.
requestMethodArg
Resolvers
);
attrMethod
.
set
HandlerMethodArgumentResolvers
(
this
.
argument
Resolvers
);
attrMethod
.
setDataBinderFactory
(
binderFactory
);
attrMethod
.
setParameterNameDiscoverer
(
this
.
parameterNameDiscoverer
);
modelAttrMethods
.
add
(
attrMethod
);
...
...
@@ -442,8 +508,8 @@ public class RequestMappingHandlerMethodAdapter extends AbstractHandlerMethodAda
WebDataBinderFactory
binderFactory
)
{
Method
method
=
handlerMethod
.
getMethod
();
ServletInvocableHandlerMethod
requestMethod
=
new
ServletInvocableHandlerMethod
(
handlerMethod
.
getBean
(),
method
);
requestMethod
.
set
ArgumentResolverContainer
(
this
.
requestMethodArg
Resolvers
);
requestMethod
.
setReturnValueHandlers
(
this
.
returnValueHandlers
);
requestMethod
.
set
HandlerMethodArgumentResolvers
(
this
.
argument
Resolvers
);
requestMethod
.
set
HandlerMethod
ReturnValueHandlers
(
this
.
returnValueHandlers
);
requestMethod
.
setDataBinderFactory
(
binderFactory
);
requestMethod
.
setParameterNameDiscoverer
(
this
.
parameterNameDiscoverer
);
return
requestMethod
;
...
...
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMethodExceptionResolver.java
浏览文件 @
ffec4444
...
...
@@ -44,8 +44,10 @@ import org.springframework.web.method.annotation.ExceptionMethodMapping;
import
org.springframework.web.method.annotation.support.ModelAttributeMethodProcessor
;
import
org.springframework.web.method.annotation.support.ModelMethodProcessor
;
import
org.springframework.web.method.annotation.support.WebArgumentResolverAdapter
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolverContainer
;
import
org.springframework.web.method.support.HandlerMethodReturnValueHandlerContainer
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolver
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolverComposite
;
import
org.springframework.web.method.support.HandlerMethodReturnValueHandler
;
import
org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolver
;
import
org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver
;
...
...
@@ -68,8 +70,6 @@ import org.springframework.web.servlet.mvc.method.annotation.support.ViewMethodR
*
* @author Rossen Stoyanchev
* @since 3.1
* @see #setCustomArgumentResolvers(WebArgumentResolver[])
* @see #setCustomModelAndViewResolvers(ModelAndViewResolver[])
* @see #setMessageConverters(HttpMessageConverter[])
*/
public
class
RequestMappingHandlerMethodExceptionResolver
extends
AbstractHandlerMethodExceptionResolver
implements
...
...
@@ -84,9 +84,9 @@ public class RequestMappingHandlerMethodExceptionResolver extends AbstractHandle
private
final
Map
<
Class
<?>,
ExceptionMethodMapping
>
exceptionMethodMappingCache
=
new
ConcurrentHashMap
<
Class
<?>,
ExceptionMethodMapping
>();
private
final
HandlerMethodArgumentResolverContainer
argumentResolvers
=
new
HandlerMethodArgumentResolverContainer
()
;
private
HandlerMethodArgumentResolverComposite
argumentResolvers
;
private
final
HandlerMethodReturnValueHandlerContainer
returnValueHandlers
=
new
HandlerMethodReturnValueHandlerContainer
()
;
private
HandlerMethodReturnValueHandlerComposite
returnValueHandlers
;
/**
* Creates an instance of {@link RequestMappingHandlerMethodExceptionResolver}.
...
...
@@ -145,25 +145,71 @@ public class RequestMappingHandlerMethodExceptionResolver extends AbstractHandle
this
.
customModelAndViewResolvers
=
customModelAndViewResolvers
;
}
/**
* Set the {@link HandlerMethodArgumentResolver}s to use to resolve argument values for
* {@link ExceptionHandler} methods. This is an optional property.
* @param argumentResolvers the argument resolvers to use
*/
public
void
setHandlerMethodArgumentResolvers
(
HandlerMethodArgumentResolver
[]
argumentResolvers
)
{
this
.
argumentResolvers
=
new
HandlerMethodArgumentResolverComposite
();
for
(
HandlerMethodArgumentResolver
resolver
:
argumentResolvers
)
{
this
.
argumentResolvers
.
registerArgumentResolver
(
resolver
);
}
}
/**
* Set the {@link HandlerMethodReturnValueHandler}s to use to handle the return values of
* {@link ExceptionHandler} methods. This is an optional property.
* @param returnValueHandlers the return value handlers to use
*/
public
void
setHandlerMethodReturnValueHandlers
(
HandlerMethodReturnValueHandler
[]
returnValueHandlers
)
{
this
.
returnValueHandlers
=
new
HandlerMethodReturnValueHandlerComposite
();
for
(
HandlerMethodReturnValueHandler
handler
:
returnValueHandlers
)
{
this
.
returnValueHandlers
.
registerReturnValueHandler
(
handler
);
}
}
public
void
afterPropertiesSet
()
throws
Exception
{
initMethodArgumentResolvers
();
initMethodReturnValueHandlers
();
}
private
void
initMethodArgumentResolvers
()
{
if
(
argumentResolvers
!=
null
)
{
return
;
}
argumentResolvers
=
new
HandlerMethodArgumentResolverComposite
();
argumentResolvers
.
registerArgumentResolver
(
new
ServletRequestMethodArgumentResolver
());
argumentResolvers
.
registerArgumentResolver
(
new
ServletResponseMethodArgumentResolver
());
if
(
customArgumentResolvers
!=
null
)
{
for
(
WebArgumentResolver
customResolver
:
customArgumentResolvers
)
{
argumentResolvers
.
registerArgumentResolver
(
new
WebArgumentResolverAdapter
(
customResolver
));
}
}
}
argumentResolvers
.
registerArgumentResolver
(
new
ServletRequestMethodArgumentResolver
());
argumentResolvers
.
registerArgumentResolver
(
new
ServletResponseMethodArgumentResolver
());
private
void
initMethodReturnValueHandlers
()
{
if
(
returnValueHandlers
!=
null
)
{
return
;
}
returnValueHandlers
=
new
HandlerMethodReturnValueHandlerComposite
();
// Annotation-based handlers
returnValueHandlers
.
registerReturnValueHandler
(
new
RequestResponseBodyMethodProcessor
(
messageConverters
));
returnValueHandlers
.
registerReturnValueHandler
(
new
ModelAttributeMethodProcessor
(
false
));
// Type-based handlers
returnValueHandlers
.
registerReturnValueHandler
(
new
ModelAndViewMethodReturnValueHandler
());
returnValueHandlers
.
registerReturnValueHandler
(
new
ModelMethodProcessor
());
returnValueHandlers
.
registerReturnValueHandler
(
new
ViewMethodReturnValueHandler
());
returnValueHandlers
.
registerReturnValueHandler
(
new
HttpEntityMethodProcessor
(
messageConverters
));
// Default handler
returnValueHandlers
.
registerReturnValueHandler
(
new
DefaultMethodReturnValueHandler
(
customModelAndViewResolvers
));
}
@Override
protected
ModelAndView
doResolveHandlerMethodException
(
HttpServletRequest
request
,
HttpServletResponse
response
,
...
...
@@ -176,8 +222,8 @@ public class RequestMappingHandlerMethodExceptionResolver extends AbstractHandle
if
(
method
!=
null
)
{
Object
handler
=
handlerMethod
.
getBean
();
ServletInvocableHandlerMethod
exceptionHandler
=
new
ServletInvocableHandlerMethod
(
handler
,
method
);
exceptionHandler
.
set
ArgumentResolverContainer
(
argumentResolvers
);
exceptionHandler
.
setReturnValueHandlers
(
returnValueHandlers
);
exceptionHandler
.
set
HandlerMethodArgumentResolvers
(
argumentResolvers
);
exceptionHandler
.
set
HandlerMethod
ReturnValueHandlers
(
returnValueHandlers
);
ServletWebRequest
webRequest
=
new
ServletWebRequest
(
request
,
response
);
ModelMap
model
=
new
ExtendedModelMap
();
...
...
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java
浏览文件 @
ffec4444
...
...
@@ -27,7 +27,7 @@ import org.springframework.web.bind.support.SessionStatus;
import
org.springframework.web.context.request.NativeWebRequest
;
import
org.springframework.web.context.request.ServletWebRequest
;
import
org.springframework.web.method.support.HandlerMethodReturnValueHandler
;
import
org.springframework.web.method.support.HandlerMethodReturnValueHandlerCo
ntainer
;
import
org.springframework.web.method.support.HandlerMethodReturnValueHandlerCo
mposite
;
import
org.springframework.web.method.support.InvocableHandlerMethod
;
import
org.springframework.web.method.support.ModelAndViewContainer
;
import
org.springframework.web.servlet.HandlerAdapter
;
...
...
@@ -47,9 +47,9 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
private
String
responseReason
;
private
HandlerMethodReturnValueHandlerCo
ntainer
returnValueHandlers
;
private
HandlerMethodReturnValueHandlerCo
mposite
returnValueHandlers
;
public
void
set
ReturnValueHandlers
(
HandlerMethodReturnValueHandlerContainer
returnValueHandlers
)
{
public
void
set
HandlerMethodReturnValueHandlers
(
HandlerMethodReturnValueHandlerComposite
returnValueHandlers
)
{
this
.
returnValueHandlers
=
returnValueHandlers
;
}
...
...
@@ -72,7 +72,7 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
/**
* Invokes the method via {@link #invokeForRequest(NativeWebRequest, ModelMap, Object...)} and also handles the
* return value by invoking one of the {@link HandlerMethodReturnValueHandler} instances registered via
* {@link #set
ReturnValueHandlers(HandlerMethodReturnValueHandlerContainer
)}.
* {@link #set
HandlerMethodReturnValueHandlers(HandlerMethodReturnValueHandlerComposite
)}.
* If the method is annotated with {@link SessionStatus} the response status will be set.
* @param request the current request
* @param model the model used throughout the current request
...
...
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ControllerMethodAnnotationDetectionTests.java
浏览文件 @
ffec4444
...
...
@@ -47,8 +47,8 @@ import org.springframework.web.context.request.ServletWebRequest;
import
org.springframework.web.context.support.GenericWebApplicationContext
;
import
org.springframework.web.method.HandlerMethodSelector
;
import
org.springframework.web.method.annotation.support.ModelAttributeMethodProcessor
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolverCo
ntainer
;
import
org.springframework.web.method.support.HandlerMethodReturnValueHandlerCo
ntainer
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolverCo
mposite
;
import
org.springframework.web.method.support.HandlerMethodReturnValueHandlerCo
mposite
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod
;
import
org.springframework.web.servlet.mvc.method.annotation.support.DefaultMethodReturnValueHandler
;
...
...
@@ -119,10 +119,10 @@ public class ControllerMethodAnnotationDetectionTests {
if
(
useAutoProxy
)
{
handler
=
getProxyBean
(
handler
);
}
HandlerMethodArgumentResolverCo
ntainer
argResolvers
=
new
HandlerMethodArgumentResolverContainer
();
HandlerMethodArgumentResolverCo
mposite
argResolvers
=
new
HandlerMethodArgumentResolverComposite
();
argResolvers
.
registerArgumentResolver
(
new
ModelAttributeMethodProcessor
(
false
));
HandlerMethodReturnValueHandlerCo
ntainer
handlers
=
new
HandlerMethodReturnValueHandlerContainer
();
HandlerMethodReturnValueHandlerCo
mposite
handlers
=
new
HandlerMethodReturnValueHandlerComposite
();
handlers
.
registerReturnValueHandler
(
new
ModelAttributeMethodProcessor
(
false
));
handlers
.
registerReturnValueHandler
(
new
DefaultMethodReturnValueHandler
(
null
));
...
...
@@ -131,8 +131,8 @@ public class ControllerMethodAnnotationDetectionTests {
Method
method
=
methods
.
iterator
().
next
();
ServletInvocableHandlerMethod
attrMethod
=
new
ServletInvocableHandlerMethod
(
handler
,
method
);
attrMethod
.
set
ArgumentResolverContainer
(
argResolvers
);
attrMethod
.
setReturnValueHandlers
(
handlers
);
attrMethod
.
set
HandlerMethodArgumentResolvers
(
argResolvers
);
attrMethod
.
set
HandlerMethod
ReturnValueHandlers
(
handlers
);
attrMethod
.
setDataBinderFactory
(
new
DefaultDataBinderFactory
(
null
));
return
attrMethod
;
...
...
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethodTests.java
浏览文件 @
ffec4444
...
...
@@ -27,7 +27,7 @@ import org.springframework.mock.web.MockHttpServletRequest;
import
org.springframework.mock.web.MockHttpServletResponse
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
import
org.springframework.web.context.request.ServletWebRequest
;
import
org.springframework.web.method.support.HandlerMethodReturnValueHandlerCo
ntainer
;
import
org.springframework.web.method.support.HandlerMethodReturnValueHandlerCo
mposite
;
import
org.springframework.web.servlet.mvc.method.annotation.support.DefaultMethodReturnValueHandler
;
/**
...
...
@@ -49,12 +49,12 @@ public class ServletInvocableHandlerMethodTests {
@Test
public
void
setResponseStatus
()
throws
Exception
{
HandlerMethodReturnValueHandlerCo
ntainer
handlers
=
new
HandlerMethodReturnValueHandlerContainer
();
HandlerMethodReturnValueHandlerCo
mposite
handlers
=
new
HandlerMethodReturnValueHandlerComposite
();
handlers
.
registerReturnValueHandler
(
new
DefaultMethodReturnValueHandler
(
null
));
Method
method
=
Handler
.
class
.
getDeclaredMethod
(
"responseStatus"
);
ServletInvocableHandlerMethod
handlerMethod
=
new
ServletInvocableHandlerMethod
(
new
Handler
(),
method
);
handlerMethod
.
setReturnValueHandlers
(
handlers
);
handlerMethod
.
set
HandlerMethod
ReturnValueHandlers
(
handlers
);
handlerMethod
.
invokeAndHandle
(
webRequest
,
null
);
...
...
org.springframework.web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolverCo
ntainer
.java
→
org.springframework.web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolverCo
mposite
.java
浏览文件 @
ffec4444
...
...
@@ -37,14 +37,14 @@ import org.springframework.web.context.request.NativeWebRequest;
* @author Rossen Stoyanchev
* @since 3.1
*/
public
class
HandlerMethodArgumentResolverCo
ntainer
implements
HandlerMethodArgumentResolver
{
public
class
HandlerMethodArgumentResolverCo
mposite
implements
HandlerMethodArgumentResolver
{
protected
final
Log
logger
=
LogFactory
.
getLog
(
HandlerMethodArgumentResolverCo
ntainer
.
class
);
protected
final
Log
logger
=
LogFactory
.
getLog
(
HandlerMethodArgumentResolverCo
mposite
.
class
);
private
List
<
HandlerMethodArgumentResolver
>
argumentResolvers
=
private
final
List
<
HandlerMethodArgumentResolver
>
argumentResolvers
=
new
ArrayList
<
HandlerMethodArgumentResolver
>();
private
Map
<
MethodParameter
,
HandlerMethodArgumentResolver
>
argumentResolverCache
=
private
final
Map
<
MethodParameter
,
HandlerMethodArgumentResolver
>
argumentResolverCache
=
new
ConcurrentHashMap
<
MethodParameter
,
HandlerMethodArgumentResolver
>();
/**
...
...
org.springframework.web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerCo
ntainer
.java
→
org.springframework.web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerCo
mposite
.java
浏览文件 @
ffec4444
...
...
@@ -35,14 +35,14 @@ import org.springframework.web.context.request.NativeWebRequest;
* @author Rossen Stoyanchev
* @since 3.1
*/
public
class
HandlerMethodReturnValueHandlerCo
ntainer
implements
HandlerMethodReturnValueHandler
{
public
class
HandlerMethodReturnValueHandlerCo
mposite
implements
HandlerMethodReturnValueHandler
{
protected
final
Log
logger
=
LogFactory
.
getLog
(
HandlerMethodArgumentResolverCo
ntainer
.
class
);
protected
final
Log
logger
=
LogFactory
.
getLog
(
HandlerMethodArgumentResolverCo
mposite
.
class
);
private
List
<
HandlerMethodReturnValueHandler
>
returnValueHandlers
=
private
final
List
<
HandlerMethodReturnValueHandler
>
returnValueHandlers
=
new
ArrayList
<
HandlerMethodReturnValueHandler
>();
private
Map
<
MethodParameter
,
HandlerMethodReturnValueHandler
>
returnValueHandlerCache
=
private
final
Map
<
MethodParameter
,
HandlerMethodReturnValueHandler
>
returnValueHandlerCache
=
new
ConcurrentHashMap
<
MethodParameter
,
HandlerMethodReturnValueHandler
>();
/**
...
...
org.springframework.web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java
浏览文件 @
ffec4444
...
...
@@ -16,7 +16,6 @@
package
org.springframework.web.method.support
;
import
java.io.Serializable
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.util.Arrays
;
...
...
@@ -39,14 +38,14 @@ import org.springframework.web.method.HandlerMethod;
*
* <p>Resolving argument values often requires a {@link WebDataBinder} for data binding and type conversion.
* Use {@link #setDataBinderFactory(WebDataBinderFactory)} to provide a factory for that. The list of argument
* resolvers can be set via {@link #set
ArgumentResolverContainer(HandlerMethodArgumentResolverContainer
)}.
* resolvers can be set via {@link #set
HandlerMethodArgumentResolvers(HandlerMethodArgumentResolverComposite
)}.
*
* @author Rossen Stoyanchev
* @since 3.1
*/
public
class
InvocableHandlerMethod
extends
HandlerMethod
{
private
HandlerMethodArgumentResolverCo
ntainer
argumentResolvers
=
new
HandlerMethodArgumentResolverContainer
();
private
HandlerMethodArgumentResolverCo
mposite
argumentResolvers
=
new
HandlerMethodArgumentResolverComposite
();
private
WebDataBinderFactory
dataBinderFactory
;
...
...
@@ -86,7 +85,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
/**
* Set {@link HandlerMethodArgumentResolver}s to use to use for resolving method argument values.
*/
public
void
set
ArgumentResolverContainer
(
HandlerMethodArgumentResolverContainer
argumentResolvers
)
{
public
void
set
HandlerMethodArgumentResolvers
(
HandlerMethodArgumentResolverComposite
argumentResolvers
)
{
this
.
argumentResolvers
=
argumentResolvers
;
}
...
...
@@ -102,7 +101,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
/**
* Invoke the method after resolving its argument values based on the given request.
* <p>Most argument values are resolved with the help of {@link HandlerMethodArgumentResolver}s
* configured via {@link #set
ArgumentResolverContainer(HandlerMethodArgumentResolverContainer
)}.
* configured via {@link #set
HandlerMethodArgumentResolvers(HandlerMethodArgumentResolverComposite
)}.
* However, the {@code provideArgs} parameter can be used to supply argument values for use
* directly rather than relying on argument resolution - e.g. {@link WebDataBinder},
* {@link SessionStatus}, or the thrown exception in a HandlerExceptionResolver.
...
...
org.springframework.web/src/test/java/org/springframework/web/method/annotation/InitBinderMethodDataBinderFactoryTests.java
浏览文件 @
ffec4444
...
...
@@ -40,7 +40,7 @@ import org.springframework.web.context.request.NativeWebRequest;
import
org.springframework.web.context.request.ServletWebRequest
;
import
org.springframework.web.method.annotation.support.RequestParamMethodArgumentResolver
;
import
org.springframework.web.method.support.InvocableHandlerMethod
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolverCo
ntainer
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolverCo
mposite
;
/**
* Test fixture for {@link InitBinderMethodDataBinderFactory} unit tests.
...
...
@@ -109,7 +109,7 @@ public class InitBinderMethodDataBinderFactoryTests {
public
void
createBinderTypeConversion
()
throws
Exception
{
request
.
setParameter
(
"requestParam"
,
"22"
);
HandlerMethodArgumentResolverCo
ntainer
argResolvers
=
new
HandlerMethodArgumentResolverContainer
();
HandlerMethodArgumentResolverCo
mposite
argResolvers
=
new
HandlerMethodArgumentResolverComposite
();
argResolvers
.
registerArgumentResolver
(
new
RequestParamMethodArgumentResolver
(
null
,
false
));
String
methodName
=
"initBinderTypeConversion"
;
...
...
@@ -122,16 +122,16 @@ public class InitBinderMethodDataBinderFactoryTests {
private
InitBinderMethodDataBinderFactory
createFactory
(
String
methodName
,
Class
<?>...
parameterTypes
)
throws
Exception
{
return
createFactory
(
new
HandlerMethodArgumentResolverCo
ntainer
(),
methodName
,
parameterTypes
);
return
createFactory
(
new
HandlerMethodArgumentResolverCo
mposite
(),
methodName
,
parameterTypes
);
}
private
InitBinderMethodDataBinderFactory
createFactory
(
HandlerMethodArgumentResolverCo
ntainer
argResolvers
,
private
InitBinderMethodDataBinderFactory
createFactory
(
HandlerMethodArgumentResolverCo
mposite
argResolvers
,
String
methodName
,
Class
<?>...
parameterTypes
)
throws
Exception
{
Object
handler
=
new
InitBinderHandler
();
Method
method
=
InitBinderHandler
.
class
.
getMethod
(
methodName
,
parameterTypes
);
InvocableHandlerMethod
controllerMethod
=
new
InvocableHandlerMethod
(
handler
,
method
);
controllerMethod
.
set
ArgumentResolverContainer
(
argResolvers
);
controllerMethod
.
set
HandlerMethodArgumentResolvers
(
argResolvers
);
controllerMethod
.
setDataBinderFactory
(
new
DefaultDataBinderFactory
(
null
));
controllerMethod
.
setParameterNameDiscoverer
(
new
LocalVariableTableParameterNameDiscoverer
());
...
...
org.springframework.web/src/test/java/org/springframework/web/method/annotation/ModelFactoryTests.java
浏览文件 @
ffec4444
...
...
@@ -46,7 +46,7 @@ import org.springframework.web.bind.support.WebDataBinderFactory;
import
org.springframework.web.context.request.NativeWebRequest
;
import
org.springframework.web.context.request.ServletWebRequest
;
import
org.springframework.web.method.annotation.support.ModelMethodProcessor
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolverCo
ntainer
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolverCo
mposite
;
import
org.springframework.web.method.support.InvocableHandlerMethod
;
/**
...
...
@@ -154,11 +154,11 @@ public class ModelFactoryTests {
private
ModelFactory
createFactory
(
Object
handler
,
String
methodName
,
Class
<?>...
parameterTypes
)
throws
Exception
{
Method
method
=
ModelHandler
.
class
.
getMethod
(
methodName
,
parameterTypes
);
HandlerMethodArgumentResolverCo
ntainer
argResolvers
=
new
HandlerMethodArgumentResolverContainer
();
HandlerMethodArgumentResolverCo
mposite
argResolvers
=
new
HandlerMethodArgumentResolverComposite
();
argResolvers
.
registerArgumentResolver
(
new
ModelMethodProcessor
());
InvocableHandlerMethod
controllerMethod
=
new
InvocableHandlerMethod
(
handler
,
method
);
controllerMethod
.
set
ArgumentResolverContainer
(
argResolvers
);
controllerMethod
.
set
HandlerMethodArgumentResolvers
(
argResolvers
);
controllerMethod
.
setDataBinderFactory
(
null
);
controllerMethod
.
setParameterNameDiscoverer
(
new
LocalVariableTableParameterNameDiscoverer
());
...
...
org.springframework.web/src/test/java/org/springframework/web/method/support/HandlerMethodArgumentResolverCo
ntainer
Tests.java
→
org.springframework.web/src/test/java/org/springframework/web/method/support/HandlerMethodArgumentResolverCo
mposite
Tests.java
浏览文件 @
ffec4444
...
...
@@ -27,13 +27,13 @@ import org.junit.Test;
import
org.springframework.core.MethodParameter
;
/**
* Test fixture for {@link HandlerMethodArgumentResolverCo
ntainer
} unit tests.
* Test fixture for {@link HandlerMethodArgumentResolverCo
mposite
} unit tests.
*
* @author Rossen Stoyanchev
*/
public
class
HandlerMethodArgumentResolverCo
ntainer
Tests
{
public
class
HandlerMethodArgumentResolverCo
mposite
Tests
{
private
HandlerMethodArgumentResolverCo
ntainer
container
;
private
HandlerMethodArgumentResolverCo
mposite
composite
;
private
MethodParameter
paramInteger
;
...
...
@@ -41,7 +41,7 @@ public class HandlerMethodArgumentResolverContainerTests {
@Before
public
void
setUp
()
throws
Exception
{
this
.
co
ntainer
=
new
HandlerMethodArgumentResolverContainer
();
this
.
co
mposite
=
new
HandlerMethodArgumentResolverComposite
();
Method
method
=
getClass
().
getDeclaredMethod
(
"handle"
,
Integer
.
class
,
String
.
class
);
this
.
paramInteger
=
new
MethodParameter
(
method
,
0
);
...
...
@@ -52,14 +52,14 @@ public class HandlerMethodArgumentResolverContainerTests {
public
void
supportsParameter
()
throws
Exception
{
registerResolver
(
Integer
.
class
,
null
,
false
);
assertTrue
(
this
.
co
ntainer
.
supportsParameter
(
paramInteger
));
assertFalse
(
this
.
co
ntainer
.
supportsParameter
(
paramString
));
assertTrue
(
this
.
co
mposite
.
supportsParameter
(
paramInteger
));
assertFalse
(
this
.
co
mposite
.
supportsParameter
(
paramString
));
}
@Test
public
void
resolveArgument
()
throws
Exception
{
registerResolver
(
Integer
.
class
,
Integer
.
valueOf
(
55
),
false
);
Object
resolvedValue
=
this
.
co
ntainer
.
resolveArgument
(
paramInteger
,
null
,
null
,
null
);
Object
resolvedValue
=
this
.
co
mposite
.
resolveArgument
(
paramInteger
,
null
,
null
,
null
);
assertEquals
(
Integer
.
valueOf
(
55
),
resolvedValue
);
}
...
...
@@ -68,31 +68,31 @@ public class HandlerMethodArgumentResolverContainerTests {
public
void
resolveArgumentMultipleResolvers
()
throws
Exception
{
registerResolver
(
Integer
.
class
,
Integer
.
valueOf
(
1
),
false
);
registerResolver
(
Integer
.
class
,
Integer
.
valueOf
(
2
),
false
);
Object
resolvedValue
=
this
.
co
ntainer
.
resolveArgument
(
paramInteger
,
null
,
null
,
null
);
Object
resolvedValue
=
this
.
co
mposite
.
resolveArgument
(
paramInteger
,
null
,
null
,
null
);
assertEquals
(
"Didn't use the first registered resolver"
,
Integer
.
valueOf
(
1
),
resolvedValue
);
}
@Test
(
expected
=
IllegalStateException
.
class
)
public
void
noSuitableArgumentResolver
()
throws
Exception
{
this
.
co
ntainer
.
resolveArgument
(
paramString
,
null
,
null
,
null
);
this
.
co
mposite
.
resolveArgument
(
paramString
,
null
,
null
,
null
);
}
@Test
public
void
argResolverUsesResponse
()
throws
Exception
{
registerResolver
(
Integer
.
class
,
null
,
true
);
assertTrue
(
this
.
co
ntainer
.
usesResponseArgument
(
paramInteger
));
assertTrue
(
this
.
co
mposite
.
usesResponseArgument
(
paramInteger
));
}
@Test
public
void
argResolverDoesntUseResponse
()
throws
Exception
{
registerResolver
(
Integer
.
class
,
null
,
false
);
assertFalse
(
this
.
co
ntainer
.
usesResponseArgument
(
paramInteger
));
assertFalse
(
this
.
co
mposite
.
usesResponseArgument
(
paramInteger
));
}
protected
StubArgumentResolver
registerResolver
(
Class
<?>
supportedType
,
Object
stubValue
,
boolean
usesResponse
)
{
StubArgumentResolver
resolver
=
new
StubArgumentResolver
(
supportedType
,
stubValue
,
usesResponse
);
this
.
co
ntainer
.
registerArgumentResolver
(
resolver
);
this
.
co
mposite
.
registerArgumentResolver
(
resolver
);
return
resolver
;
}
...
...
org.springframework.web/src/test/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerCo
ntainer
Tests.java
→
org.springframework.web/src/test/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerCo
mposite
Tests.java
浏览文件 @
ffec4444
...
...
@@ -26,13 +26,13 @@ import org.junit.Test;
import
org.springframework.core.MethodParameter
;
/**
* Test fixture for {@link HandlerMethodReturnValueHandlerCo
ntainer
} unit tests.
* Test fixture for {@link HandlerMethodReturnValueHandlerCo
mposite
} unit tests.
*
* @author Rossen Stoyanchev
*/
public
class
HandlerMethodReturnValueHandlerCo
ntainer
Tests
{
public
class
HandlerMethodReturnValueHandlerCo
mposite
Tests
{
private
HandlerMethodReturnValueHandlerCo
ntainer
container
;
private
HandlerMethodReturnValueHandlerCo
mposite
composite
;
ModelAndViewContainer
mavContainer
;
...
...
@@ -42,7 +42,7 @@ public class HandlerMethodReturnValueHandlerContainerTests {
@Before
public
void
setUp
()
throws
Exception
{
this
.
co
ntainer
=
new
HandlerMethodReturnValueHandlerContainer
();
this
.
co
mposite
=
new
HandlerMethodReturnValueHandlerComposite
();
this
.
paramInteger
=
new
MethodParameter
(
getClass
().
getDeclaredMethod
(
"handleInteger"
),
-
1
);
this
.
paramString
=
new
MethodParameter
(
getClass
().
getDeclaredMethod
(
"handleString"
),
-
1
);
...
...
@@ -54,14 +54,14 @@ public class HandlerMethodReturnValueHandlerContainerTests {
public
void
supportsReturnType
()
throws
Exception
{
registerReturnValueHandler
(
Integer
.
class
,
false
);
assertTrue
(
this
.
co
ntainer
.
supportsReturnType
(
paramInteger
));
assertFalse
(
this
.
co
ntainer
.
supportsReturnType
(
paramString
));
assertTrue
(
this
.
co
mposite
.
supportsReturnType
(
paramInteger
));
assertFalse
(
this
.
co
mposite
.
supportsReturnType
(
paramString
));
}
@Test
public
void
handleReturnValue
()
throws
Exception
{
StubReturnValueHandler
handler
=
registerReturnValueHandler
(
Integer
.
class
,
false
);
this
.
co
ntainer
.
handleReturnValue
(
Integer
.
valueOf
(
55
),
paramInteger
,
mavContainer
,
null
);
this
.
co
mposite
.
handleReturnValue
(
Integer
.
valueOf
(
55
),
paramInteger
,
mavContainer
,
null
);
assertEquals
(
Integer
.
valueOf
(
55
),
handler
.
getUnhandledReturnValue
());
}
...
...
@@ -70,7 +70,7 @@ public class HandlerMethodReturnValueHandlerContainerTests {
public
void
handleReturnValueMultipleHandlers
()
throws
Exception
{
StubReturnValueHandler
handler1
=
registerReturnValueHandler
(
Integer
.
class
,
false
);
StubReturnValueHandler
handler2
=
registerReturnValueHandler
(
Integer
.
class
,
false
);
this
.
co
ntainer
.
handleReturnValue
(
Integer
.
valueOf
(
55
),
paramInteger
,
mavContainer
,
null
);
this
.
co
mposite
.
handleReturnValue
(
Integer
.
valueOf
(
55
),
paramInteger
,
mavContainer
,
null
);
assertEquals
(
"Didn't use the 1st registered handler"
,
Integer
.
valueOf
(
55
),
handler1
.
getUnhandledReturnValue
());
assertNull
(
"Shouldn't have use the 2nd registered handler"
,
handler2
.
getUnhandledReturnValue
());
...
...
@@ -79,24 +79,24 @@ public class HandlerMethodReturnValueHandlerContainerTests {
@Test
(
expected
=
IllegalStateException
.
class
)
public
void
noSuitableReturnValueHandler
()
throws
Exception
{
registerReturnValueHandler
(
Integer
.
class
,
false
);
this
.
co
ntainer
.
handleReturnValue
(
"value"
,
paramString
,
null
,
null
);
this
.
co
mposite
.
handleReturnValue
(
"value"
,
paramString
,
null
,
null
);
}
@Test
public
void
returnValueHandlerUsesResponse
()
throws
Exception
{
registerReturnValueHandler
(
Integer
.
class
,
true
);
assertTrue
(
this
.
co
ntainer
.
usesResponseArgument
(
paramInteger
));
assertTrue
(
this
.
co
mposite
.
usesResponseArgument
(
paramInteger
));
}
@Test
public
void
returnValueHandlerDosntUseResponse
()
throws
Exception
{
registerReturnValueHandler
(
Integer
.
class
,
false
);
assertFalse
(
this
.
co
ntainer
.
usesResponseArgument
(
paramInteger
));
assertFalse
(
this
.
co
mposite
.
usesResponseArgument
(
paramInteger
));
}
protected
StubReturnValueHandler
registerReturnValueHandler
(
Class
<?>
returnType
,
boolean
usesResponse
)
{
StubReturnValueHandler
handler
=
new
StubReturnValueHandler
(
returnType
,
usesResponse
);
this
.
co
ntainer
.
registerReturnValueHandler
(
handler
);
this
.
co
mposite
.
registerReturnValueHandler
(
handler
);
return
handler
;
}
...
...
org.springframework.web/src/test/java/org/springframework/web/method/support/InvocableHandlerMethodTests.java
浏览文件 @
ffec4444
...
...
@@ -38,7 +38,7 @@ import org.springframework.web.context.request.ServletWebRequest;
*/
public
class
InvocableHandlerMethodTests
{
private
HandlerMethodArgumentResolverCo
ntainer
argResolvers
;
private
HandlerMethodArgumentResolverCo
mposite
argResolvers
;
private
NativeWebRequest
webRequest
;
...
...
@@ -46,7 +46,7 @@ public class InvocableHandlerMethodTests {
@Before
public
void
setUp
()
throws
Exception
{
argResolvers
=
new
HandlerMethodArgumentResolverCo
ntainer
();
argResolvers
=
new
HandlerMethodArgumentResolverCo
mposite
();
response
=
new
MockHttpServletResponse
();
this
.
webRequest
=
new
ServletWebRequest
(
new
MockHttpServletRequest
(),
response
);
...
...
@@ -96,7 +96,7 @@ public class InvocableHandlerMethodTests {
throws
Exception
{
Method
method
=
handler
.
getClass
().
getDeclaredMethod
(
methodName
,
paramTypes
);
InvocableHandlerMethod
handlerMethod
=
new
InvocableHandlerMethod
(
handler
,
method
);
handlerMethod
.
set
ArgumentResolverContainer
(
argResolvers
);
handlerMethod
.
set
HandlerMethodArgumentResolvers
(
argResolvers
);
return
handlerMethod
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录