Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
cfc560c4
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,发现更多精彩内容 >>
提交
cfc560c4
编写于
7月 02, 2016
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Leniently accept custom DeferredResult etc subclasses for null values
Issue: SPR-14423
上级
498d896e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
63 addition
and
29 deletion
+63
-29
spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethod.java
.../messaging/handler/invocation/InvocableHandlerMethod.java
+3
-3
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java
.../mvc/method/annotation/ServletInvocableHandlerMethod.java
+3
-9
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethodTests.java
...method/annotation/ServletInvocableHandlerMethodTests.java
+57
-17
未找到文件。
spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethod.java
浏览文件 @
cfc560c4
...
...
@@ -283,10 +283,10 @@ public class InvocableHandlerMethod extends HandlerMethod {
if
(
this
.
returnValue
!=
null
)
{
return
this
.
returnValue
.
getClass
();
}
if
(
ResolvableType
.
NONE
.
equals
(
this
.
returnType
))
{
throw
new
IllegalArgumentException
(
"Expected Future-like type with generic parameter"
);
if
(
!
ResolvableType
.
NONE
.
equals
(
this
.
returnType
))
{
return
this
.
returnType
.
getRawClass
(
);
}
return
this
.
returnType
.
getRawClass
();
return
super
.
getParameterType
();
}
@Override
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java
浏览文件 @
cfc560c4
...
...
@@ -281,16 +281,10 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
if
(
this
.
returnValue
!=
null
)
{
return
this
.
returnValue
.
getClass
();
}
Class
<?>
parameterType
=
super
.
getParameterType
();
if
(
ResponseBodyEmitter
.
class
.
isAssignableFrom
(
parameterType
)
||
StreamingResponseBody
.
class
.
isAssignableFrom
(
parameterType
))
{
return
parameterType
;
if
(!
ResolvableType
.
NONE
.
equals
(
this
.
returnType
))
{
return
this
.
returnType
.
getRawClass
();
}
if
(
ResolvableType
.
NONE
.
equals
(
this
.
returnType
))
{
throw
new
IllegalArgumentException
(
"Expected one of Callable, DeferredResult, or ListenableFuture: "
+
super
.
getParameterType
());
}
return
this
.
returnType
.
getRawClass
();
return
super
.
getParameterType
();
}
@Override
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethodTests.java
浏览文件 @
cfc560c4
...
...
@@ -56,6 +56,7 @@ import static org.mockito.Mockito.*;
*
* @author Rossen Stoyanchev
* @author Sam Brannen
* @author Juergen Hoeller
*/
public
class
ServletInvocableHandlerMethodTests
{
...
...
@@ -126,9 +127,7 @@ public class ServletInvocableHandlerMethodTests {
this
.
mavContainer
.
isRequestHandled
());
}
// SPR-9159
@Test
@Test
// SPR-9159
public
void
invokeAndHandle_NotVoidWithResponseStatusAndReason
()
throws
Exception
{
ServletInvocableHandlerMethod
handlerMethod
=
getHandlerMethod
(
new
Handler
(),
"responseStatusWithReason"
);
handlerMethod
.
invokeAndHandle
(
this
.
webRequest
,
this
.
mavContainer
);
...
...
@@ -138,7 +137,7 @@ public class ServletInvocableHandlerMethodTests {
assertEquals
(
"400 Bad Request"
,
this
.
response
.
getErrorMessage
());
}
@Test
(
expected
=
HttpMessageNotWritableException
.
class
)
@Test
(
expected
=
HttpMessageNotWritableException
.
class
)
public
void
invokeAndHandle_Exception
()
throws
Exception
{
this
.
returnValueHandlers
.
addHandler
(
new
ExceptionRaisingReturnValueHandler
());
...
...
@@ -169,23 +168,47 @@ public class ServletInvocableHandlerMethodTests {
@Test
public
void
wrapConcurrentResult_MethodLevelResponseBody
()
throws
Exception
{
wrapConcurrentResult_ResponseBody
(
new
MethodLevelResponseBodyHandler
());
wrapConcurrentResult_ResponseBody
(
new
MethodLevelResponseBodyHandler
(),
"bar"
,
String
.
class
);
}
@Test
public
void
wrapConcurrentResult_MethodLevelResponseBodyEmpty
()
throws
Exception
{
wrapConcurrentResult_ResponseBody
(
new
MethodLevelResponseBodyHandler
(),
null
,
String
.
class
);
}
@Test
public
void
wrapConcurrentResult_TypeLevelResponseBody
()
throws
Exception
{
wrapConcurrentResult_ResponseBody
(
new
TypeLevelResponseBodyHandler
());
wrapConcurrentResult_ResponseBody
(
new
TypeLevelResponseBodyHandler
(),
"bar"
,
String
.
class
);
}
@Test
public
void
wrapConcurrentResult_TypeLevelResponseBodyEmpty
()
throws
Exception
{
wrapConcurrentResult_ResponseBody
(
new
TypeLevelResponseBodyHandler
(),
null
,
String
.
class
);
}
@Test
public
void
wrapConcurrentResult_DeferredResultSubclass
()
throws
Exception
{
wrapConcurrentResult_ResponseBody
(
new
DeferredResultSubclassHandler
(),
"bar"
,
String
.
class
);
}
private
void
wrapConcurrentResult_ResponseBody
(
Object
handler
)
throws
Exception
{
@Test
public
void
wrapConcurrentResult_DeferredResultSubclassEmpty
()
throws
Exception
{
wrapConcurrentResult_ResponseBody
(
new
DeferredResultSubclassHandler
(),
null
,
CustomDeferredResult
.
class
);
}
private
void
wrapConcurrentResult_ResponseBody
(
Object
handler
,
Object
result
,
Class
<?>
expectedReturnType
)
throws
Exception
{
List
<
HttpMessageConverter
<?>>
converters
=
new
ArrayList
<>();
converters
.
add
(
new
StringHttpMessageConverter
());
this
.
returnValueHandlers
.
addHandler
(
new
ModelAndViewMethodReturnValueHandler
());
this
.
returnValueHandlers
.
addHandler
(
new
RequestResponseBodyMethodProcessor
(
converters
));
ServletInvocableHandlerMethod
handlerMethod
=
getHandlerMethod
(
handler
,
"handle"
);
handlerMethod
=
handlerMethod
.
wrapConcurrentResult
(
"bar"
);
handlerMethod
.
invokeAndHandle
(
this
.
webRequest
,
this
.
mavContainer
);
assertEquals
(
"bar"
,
this
.
response
.
getContentAsString
());
handlerMethod
=
handlerMethod
.
wrapConcurrentResult
(
result
);
handlerMethod
.
invokeAndHandle
(
this
.
webRequest
,
this
.
mavContainer
);
assertEquals
((
result
!=
null
?
result
.
toString
()
:
""
),
this
.
response
.
getContentAsString
());
assertEquals
(
expectedReturnType
,
handlerMethod
.
getReturnValueType
(
result
).
getParameterType
());
}
@Test
...
...
@@ -200,9 +223,7 @@ public class ServletInvocableHandlerMethodTests {
assertEquals
(
"bar"
,
this
.
response
.
getContentAsString
());
}
// SPR-12287
@Test
@Test
// SPR-12287
public
void
wrapConcurrentResult_ResponseEntityNullBody
()
throws
Exception
{
List
<
HttpMessageConverter
<?>>
converters
=
new
ArrayList
<>();
converters
.
add
(
new
StringHttpMessageConverter
());
...
...
@@ -256,9 +277,7 @@ public class ServletInvocableHandlerMethodTests {
assertEquals
(
""
,
this
.
response
.
getContentAsString
());
}
// SPR-12287 (16/Oct/14 comments)
@Test
@Test
// SPR-12287 (16/Oct/14 comments)
public
void
responseEntityRawTypeWithNullBody
()
throws
Exception
{
List
<
HttpMessageConverter
<?>>
converters
=
Collections
.
singletonList
(
new
StringHttpMessageConverter
());
List
<
Object
>
advice
=
Collections
.
singletonList
(
mock
(
ResponseBodyAdvice
.
class
));
...
...
@@ -281,6 +300,7 @@ public class ServletInvocableHandlerMethodTests {
return
handlerMethod
;
}
@SuppressWarnings
(
"unused"
)
@ResponseStatus
@Retention
(
RetentionPolicy
.
RUNTIME
)
...
...
@@ -290,6 +310,7 @@ public class ServletInvocableHandlerMethodTests {
HttpStatus
responseStatus
()
default
HttpStatus
.
INTERNAL_SERVER_ERROR
;
}
@SuppressWarnings
(
"unused"
)
private
static
class
Handler
{
...
...
@@ -321,6 +342,7 @@ public class ServletInvocableHandlerMethodTests {
}
}
@SuppressWarnings
(
"unused"
)
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
private
static
class
ResponseStatusHandler
{
...
...
@@ -329,6 +351,7 @@ public class ServletInvocableHandlerMethodTests {
}
}
private
static
class
MethodLevelResponseBodyHandler
{
@ResponseBody
...
...
@@ -337,6 +360,7 @@ public class ServletInvocableHandlerMethodTests {
}
}
@SuppressWarnings
(
"unused"
)
@ResponseBody
private
static
class
TypeLevelResponseBodyHandler
{
...
...
@@ -346,6 +370,20 @@ public class ServletInvocableHandlerMethodTests {
}
}
private
static
class
DeferredResultSubclassHandler
{
@ResponseBody
public
CustomDeferredResult
handle
()
{
return
new
CustomDeferredResult
();
}
}
private
static
class
CustomDeferredResult
extends
DeferredResult
<
String
>
{
}
@SuppressWarnings
(
"unused"
)
private
static
class
ResponseEntityHandler
{
...
...
@@ -358,6 +396,7 @@ public class ServletInvocableHandlerMethodTests {
}
}
private
static
class
ExceptionRaisingReturnValueHandler
implements
HandlerMethodReturnValueHandler
{
@Override
...
...
@@ -372,6 +411,7 @@ public class ServletInvocableHandlerMethodTests {
}
}
@SuppressWarnings
(
"unused"
)
private
static
class
AsyncHandler
{
...
...
@@ -384,4 +424,4 @@ public class ServletInvocableHandlerMethodTests {
}
}
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录