Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
普通程序员一名
spring-framework
提交
4764fa53
S
spring-framework
项目概览
普通程序员一名
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
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,发现更多精彩内容 >>
提交
4764fa53
编写于
6月 07, 2010
作者:
A
Arjen Poutsma
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SPR-7259 - ResponseStatus.reason() ignored for @ExceptionHandler methods
上级
f72c431e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
14 addition
and
5 deletion
+14
-5
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java
.../annotation/AnnotationMethodHandlerExceptionResolver.java
+12
-4
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerExceptionResolverTests.java
...tation/AnnotationMethodHandlerExceptionResolverTests.java
+2
-1
未找到文件。
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java
浏览文件 @
4764fa53
...
...
@@ -45,6 +45,7 @@ import org.springframework.core.annotation.AnnotationUtils;
import
org.springframework.http.HttpInputMessage
;
import
org.springframework.http.HttpOutputMessage
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.converter.ByteArrayHttpMessageConverter
;
import
org.springframework.http.converter.FormHttpMessageConverter
;
import
org.springframework.http.converter.HttpMessageConverter
;
...
...
@@ -56,6 +57,7 @@ import org.springframework.ui.Model;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
...
...
@@ -347,10 +349,16 @@ public class AnnotationMethodHandlerExceptionResolver extends AbstractHandlerExc
private
ModelAndView
getModelAndView
(
Method
handlerMethod
,
Object
returnValue
,
ServletWebRequest
webRequest
)
throws
Exception
{
ResponseStatus
responseStatus
=
AnnotationUtils
.
findAnnotation
(
handlerMethod
,
ResponseStatus
.
class
);
if
(
responseStatus
!=
null
)
{
HttpServletResponse
response
=
webRequest
.
getResponse
();
response
.
setStatus
(
responseStatus
.
value
().
value
());
ResponseStatus
responseStatusAnn
=
AnnotationUtils
.
findAnnotation
(
handlerMethod
,
ResponseStatus
.
class
);
if
(
responseStatusAnn
!=
null
)
{
HttpStatus
responseStatus
=
responseStatusAnn
.
value
();
String
reason
=
responseStatusAnn
.
reason
();
if
(!
StringUtils
.
hasText
(
reason
))
{
webRequest
.
getResponse
().
setStatus
(
responseStatus
.
value
());
}
else
{
webRequest
.
getResponse
().
sendError
(
responseStatus
.
value
(),
reason
);
}
}
if
(
returnValue
!=
null
&&
AnnotationUtils
.
findAnnotation
(
handlerMethod
,
ResponseBody
.
class
)
!=
null
)
{
...
...
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerExceptionResolverTests.java
浏览文件 @
4764fa53
...
...
@@ -78,6 +78,7 @@ public class AnnotationMethodHandlerExceptionResolverTests {
assertNotNull
(
"No ModelAndView returned"
,
mav
);
assertEquals
(
"Invalid view name returned"
,
"Y:SocketException"
,
mav
.
getViewName
());
assertEquals
(
"Invalid status code returned"
,
406
,
response
.
getStatus
());
assertEquals
(
"Invalid status reason returned"
,
"This is simply unacceptable!"
,
response
.
getErrorMessage
());
}
@Test
...
...
@@ -149,7 +150,7 @@ public class AnnotationMethodHandlerExceptionResolverTests {
}
@ExceptionHandler
(
SocketException
.
class
)
@ResponseStatus
(
HttpStatus
.
NOT_ACCEPTABLE
)
@ResponseStatus
(
value
=
HttpStatus
.
NOT_ACCEPTABLE
,
reason
=
"This is simply unacceptable!"
)
public
String
handleSocketException
(
Exception
ex
,
HttpServletResponse
response
)
{
return
"Y:"
+
ClassUtils
.
getShortName
(
ex
.
getClass
());
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录