Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
57dc8199
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,发现更多精彩内容 >>
提交
57dc8199
编写于
11月 20, 2015
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add ReactiveHttpFilter
上级
0f8a4bf7
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
272 addition
and
1 deletion
+272
-1
spring-web-reactive/src/main/java/org/springframework/http/server/FilterChainHttpHandler.java
...g/springframework/http/server/FilterChainHttpHandler.java
+68
-0
spring-web-reactive/src/main/java/org/springframework/http/server/ReactiveHttpFilter.java
...a/org/springframework/http/server/ReactiveHttpFilter.java
+30
-0
spring-web-reactive/src/main/java/org/springframework/http/server/ReactiveHttpFilterChain.java
.../springframework/http/server/ReactiveHttpFilterChain.java
+31
-0
spring-web-reactive/src/test/java/org/springframework/http/server/FilterChainHttpHandlerTests.java
...ingframework/http/server/FilterChainHttpHandlerTests.java
+142
-0
spring-web-reactive/src/test/java/org/springframework/web/reactive/handler/SimpleUrlHandlerMappingIntegrationTests.java
...tive/handler/SimpleUrlHandlerMappingIntegrationTests.java
+1
-1
未找到文件。
spring-web-reactive/src/main/java/org/springframework/http/server/FilterChainHttpHandler.java
0 → 100644
浏览文件 @
57dc8199
/*
* Copyright 2002-2015 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.http.server
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
import
org.reactivestreams.Publisher
;
import
org.springframework.util.Assert
;
/**
* An {@link ReactiveHttpHandler} decorator that delegates to a list of
* {@link ReactiveHttpFilter}s and the target {@link ReactiveHttpHandler}.
*
* @author Rossen Stoyanchev
*/
public
class
FilterChainHttpHandler
implements
ReactiveHttpHandler
{
private
final
List
<
ReactiveHttpFilter
>
filters
;
private
final
ReactiveHttpHandler
targetHandler
;
public
FilterChainHttpHandler
(
ReactiveHttpHandler
targetHandler
,
ReactiveHttpFilter
...
filters
)
{
Assert
.
notNull
(
targetHandler
,
"'targetHandler' is required."
);
this
.
filters
=
(
filters
!=
null
?
Arrays
.
asList
(
filters
)
:
Collections
.
emptyList
());
this
.
targetHandler
=
targetHandler
;
}
@Override
public
Publisher
<
Void
>
handle
(
ReactiveServerHttpRequest
request
,
ReactiveServerHttpResponse
response
)
{
return
new
DefaultHttpFilterChain
().
filter
(
request
,
response
);
}
private
class
DefaultHttpFilterChain
implements
ReactiveHttpFilterChain
{
private
int
index
;
@Override
public
Publisher
<
Void
>
filter
(
ReactiveServerHttpRequest
request
,
ReactiveServerHttpResponse
response
)
{
if
(
this
.
index
<
filters
.
size
())
{
ReactiveHttpFilter
filter
=
filters
.
get
(
this
.
index
++);
return
filter
.
filter
(
request
,
response
,
this
);
}
else
{
return
targetHandler
.
handle
(
request
,
response
);
}
}
}
}
spring-web-reactive/src/main/java/org/springframework/http/server/ReactiveHttpFilter.java
0 → 100644
浏览文件 @
57dc8199
/*
* Copyright 2002-2015 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.http.server
;
import
org.reactivestreams.Publisher
;
/**
* @author Rossen Stoyanchev
*/
public
interface
ReactiveHttpFilter
{
Publisher
<
Void
>
filter
(
ReactiveServerHttpRequest
request
,
ReactiveServerHttpResponse
response
,
ReactiveHttpFilterChain
chain
);
}
spring-web-reactive/src/main/java/org/springframework/http/server/ReactiveHttpFilterChain.java
0 → 100644
浏览文件 @
57dc8199
/*
* Copyright 2002-2015 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.http.server
;
import
org.reactivestreams.Publisher
;
import
org.springframework.http.server.ReactiveServerHttpRequest
;
import
org.springframework.http.server.ReactiveServerHttpResponse
;
/**
* @author Rossen Stoyanchev
*/
public
interface
ReactiveHttpFilterChain
{
Publisher
<
Void
>
filter
(
ReactiveServerHttpRequest
request
,
ReactiveServerHttpResponse
response
);
}
spring-web-reactive/src/test/java/org/springframework/http/server/FilterChainHttpHandlerTests.java
0 → 100644
浏览文件 @
57dc8199
/*
* Copyright 2002-2015 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.http.server
;
import
java.util.concurrent.TimeUnit
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.reactivestreams.Publisher
;
import
reactor.Publishers
;
import
reactor.rx.Streams
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
* @author Rossen Stoyanchev
*/
public
class
FilterChainHttpHandlerTests
{
private
ReactiveServerHttpRequest
request
;
private
ReactiveServerHttpResponse
response
;
@Before
public
void
setUp
()
throws
Exception
{
this
.
request
=
mock
(
ReactiveServerHttpRequest
.
class
);
this
.
response
=
mock
(
ReactiveServerHttpResponse
.
class
);
}
@Test
public
void
multipleFilters
()
throws
Exception
{
StubHandler
handler
=
new
StubHandler
();
TestFilter
filter1
=
new
TestFilter
();
TestFilter
filter2
=
new
TestFilter
();
TestFilter
filter3
=
new
TestFilter
();
FilterChainHttpHandler
filterHandler
=
new
FilterChainHttpHandler
(
handler
,
filter1
,
filter2
,
filter3
);
Publisher
<
Void
>
voidPublisher
=
filterHandler
.
handle
(
this
.
request
,
this
.
response
);
Streams
.
wrap
(
voidPublisher
).
toList
().
await
(
10
,
TimeUnit
.
SECONDS
);
assertTrue
(
filter1
.
invoked
());
assertTrue
(
filter2
.
invoked
());
assertTrue
(
filter3
.
invoked
());
assertTrue
(
handler
.
invoked
());
}
@Test
public
void
zeroFilters
()
throws
Exception
{
StubHandler
handler
=
new
StubHandler
();
FilterChainHttpHandler
filterHandler
=
new
FilterChainHttpHandler
(
handler
);
Publisher
<
Void
>
voidPublisher
=
filterHandler
.
handle
(
this
.
request
,
this
.
response
);
Streams
.
wrap
(
voidPublisher
).
toList
().
await
(
10
,
TimeUnit
.
SECONDS
);
assertTrue
(
handler
.
invoked
());
}
@Test
public
void
shortcircuitFilter
()
throws
Exception
{
StubHandler
handler
=
new
StubHandler
();
TestFilter
filter1
=
new
TestFilter
();
ShortcircuitingFilter
filter2
=
new
ShortcircuitingFilter
();
TestFilter
filter3
=
new
TestFilter
();
FilterChainHttpHandler
filterHandler
=
new
FilterChainHttpHandler
(
handler
,
filter1
,
filter2
,
filter3
);
Publisher
<
Void
>
voidPublisher
=
filterHandler
.
handle
(
this
.
request
,
this
.
response
);
Streams
.
wrap
(
voidPublisher
).
toList
().
await
(
10
,
TimeUnit
.
SECONDS
);
assertTrue
(
filter1
.
invoked
());
assertTrue
(
filter2
.
invoked
());
assertFalse
(
filter3
.
invoked
());
assertFalse
(
handler
.
invoked
());
}
private
static
class
TestFilter
implements
ReactiveHttpFilter
{
private
boolean
invoked
;
public
boolean
invoked
()
{
return
this
.
invoked
;
}
@Override
public
Publisher
<
Void
>
filter
(
ReactiveServerHttpRequest
req
,
ReactiveServerHttpResponse
res
,
ReactiveHttpFilterChain
chain
)
{
this
.
invoked
=
true
;
return
doFilter
(
req
,
res
,
chain
);
}
public
Publisher
<
Void
>
doFilter
(
ReactiveServerHttpRequest
req
,
ReactiveServerHttpResponse
res
,
ReactiveHttpFilterChain
chain
)
{
return
chain
.
filter
(
req
,
res
);
}
}
private
static
class
ShortcircuitingFilter
extends
TestFilter
{
@Override
public
Publisher
<
Void
>
doFilter
(
ReactiveServerHttpRequest
req
,
ReactiveServerHttpResponse
res
,
ReactiveHttpFilterChain
chain
)
{
return
Publishers
.
empty
();
}
}
private
static
class
StubHandler
implements
ReactiveHttpHandler
{
private
boolean
invoked
;
public
boolean
invoked
()
{
return
this
.
invoked
;
}
@Override
public
Publisher
<
Void
>
handle
(
ReactiveServerHttpRequest
req
,
ReactiveServerHttpResponse
res
)
{
this
.
invoked
=
true
;
return
Publishers
.
empty
();
}
}
}
spring-web-reactive/src/test/java/org/springframework/web/reactive/handler/SimpleUrlHandlerMappingIntegrationTests.java
浏览文件 @
57dc8199
...
...
@@ -55,7 +55,7 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler
StaticWebApplicationContext
wac
=
new
StaticWebApplicationContext
();
wac
.
registerSingleton
(
"hm"
,
TestHandlerMapping
.
class
);
wac
.
registerSingleton
(
"ha"
,
HttpHandlerAdapter
.
class
);
wac
.
registerSingleton
(
"
hh
rh"
,
SimpleHandlerResultHandler
.
class
);
wac
.
registerSingleton
(
"rh"
,
SimpleHandlerResultHandler
.
class
);
wac
.
refresh
();
DispatcherHandler
dispatcherHandler
=
new
DispatcherHandler
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录