Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dk131072
spring-framework
提交
135738f9
S
spring-framework
项目概览
dk131072
/
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,发现更多精彩内容 >>
提交
135738f9
编写于
1月 25, 2016
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
AbstractController supports HTTP OPTIONS
Issue: SPR-13130
上级
a730e55d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
38 addition
and
9 deletion
+38
-9
spring-test/src/main/java/org/springframework/test/web/servlet/setup/AbstractMockMvcBuilder.java
...mework/test/web/servlet/setup/AbstractMockMvcBuilder.java
+2
-2
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/AbstractController.java
...g/springframework/web/servlet/mvc/AbstractController.java
+14
-1
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ParameterizableViewController.java
...mework/web/servlet/mvc/ParameterizableViewController.java
+6
-0
spring-webmvc/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java
...ingframework/web/servlet/support/WebContentGenerator.java
+4
-5
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/ParameterizableViewControllerTests.java
...k/web/servlet/mvc/ParameterizableViewControllerTests.java
+12
-1
未找到文件。
spring-test/src/main/java/org/springframework/test/web/servlet/setup/AbstractMockMvcBuilder.java
浏览文件 @
135738f9
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
6
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -55,7 +55,7 @@ public abstract class AbstractMockMvcBuilder<B extends AbstractMockMvcBuilder<B>
private
final
List
<
ResultHandler
>
globalResultHandlers
=
new
ArrayList
<
ResultHandler
>();
private
Boolean
dispatchOptions
=
Boolean
.
FALS
E
;
private
Boolean
dispatchOptions
=
Boolean
.
TRU
E
;
private
final
List
<
MockMvcConfigurer
>
configurers
=
new
ArrayList
<
MockMvcConfigurer
>(
4
);
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/AbstractController.java
浏览文件 @
135738f9
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -16,10 +16,15 @@
package
org.springframework.web.servlet.mvc
;
import
java.util.Arrays
;
import
java.util.List
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.support.WebContentGenerator
;
import
org.springframework.web.util.WebUtils
;
...
...
@@ -87,6 +92,7 @@ import org.springframework.web.util.WebUtils;
*
* @author Rod Johnson
* @author Juergen Hoeller
* @author Rossen Stoyanchev
* @see WebContentInterceptor
*/
public
abstract
class
AbstractController
extends
WebContentGenerator
implements
Controller
{
...
...
@@ -149,6 +155,13 @@ public abstract class AbstractController extends WebContentGenerator implements
public
ModelAndView
handleRequest
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
Exception
{
String
[]
supportedMethods
=
getSupportedMethods
();
if
(
HttpMethod
.
OPTIONS
.
matches
(
request
.
getMethod
())
&&
!
ObjectUtils
.
isEmpty
(
supportedMethods
))
{
List
<
String
>
value
=
Arrays
.
asList
(
supportedMethods
);
response
.
setHeader
(
"Allow"
,
StringUtils
.
collectionToCommaDelimitedString
(
value
));
return
null
;
}
// Delegate to WebContentGenerator for checking and preparing.
checkRequest
(
request
);
prepareResponse
(
response
);
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ParameterizableViewController.java
浏览文件 @
135738f9
...
...
@@ -19,6 +19,7 @@ package org.springframework.web.servlet.mvc;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.View
;
...
...
@@ -43,6 +44,11 @@ public class ParameterizableViewController extends AbstractController {
private
boolean
statusOnly
;
public
ParameterizableViewController
()
{
super
(
false
);
setSupportedMethods
(
HttpMethod
.
GET
.
name
(),
HttpMethod
.
HEAD
.
name
());
}
/**
* Set a view name for the ModelAndView to return, to be resolved by the
* DispatcherServlet via a ViewResolver. Will override any pre-existing
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java
浏览文件 @
135738f9
...
...
@@ -17,10 +17,9 @@
package
org.springframework.web.servlet.support
;
import
java.util.Arrays
;
import
java.util.HashSet
;
import
java.util.
Linked
HashSet
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
...
...
@@ -111,7 +110,7 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport {
*/
public
WebContentGenerator
(
boolean
restrictDefaultSupportedMethods
)
{
if
(
restrictDefaultSupportedMethods
)
{
this
.
supportedMethods
=
new
HashSet
<
String
>(
4
);
this
.
supportedMethods
=
new
Linked
HashSet
<
String
>(
4
);
this
.
supportedMethods
.
add
(
METHOD_GET
);
this
.
supportedMethods
.
add
(
METHOD_HEAD
);
this
.
supportedMethods
.
add
(
METHOD_POST
);
...
...
@@ -123,7 +122,7 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport {
* @param supportedMethods the supported HTTP methods for this content generator
*/
public
WebContentGenerator
(
String
...
supportedMethods
)
{
this
.
supportedMethods
=
new
HashSet
<
String
>(
Arrays
.
asList
(
supportedMethods
));
this
.
supportedMethods
=
new
Linked
HashSet
<
String
>(
Arrays
.
asList
(
supportedMethods
));
}
...
...
@@ -134,7 +133,7 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport {
*/
public
final
void
setSupportedMethods
(
String
...
methods
)
{
if
(
methods
!=
null
)
{
this
.
supportedMethods
=
new
HashSet
<
String
>(
Arrays
.
asList
(
methods
));
this
.
supportedMethods
=
new
Linked
HashSet
<
String
>(
Arrays
.
asList
(
methods
));
}
else
{
this
.
supportedMethods
=
null
;
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/ParameterizableViewControllerTests.java
浏览文件 @
135738f9
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
6
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -19,6 +19,7 @@ package org.springframework.web.servlet.mvc;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.mock.web.test.MockHttpServletRequest
;
import
org.springframework.mock.web.test.MockHttpServletResponse
;
import
org.springframework.ui.ModelMap
;
...
...
@@ -69,4 +70,14 @@ public class ParameterizableViewControllerTests {
assertEquals
(
"value"
,
mav
.
getModel
().
get
(
"name"
));
}
@Test
public
void
handleRequestHttpOptions
()
throws
Exception
{
this
.
request
.
setMethod
(
HttpMethod
.
OPTIONS
.
name
());
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
ModelAndView
mav
=
this
.
controller
.
handleRequest
(
this
.
request
,
response
);
assertNull
(
mav
);
assertEquals
(
"GET,HEAD"
,
response
.
getHeader
(
"Allow"
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录