Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
6634d1f5
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,发现更多精彩内容 >>
提交
6634d1f5
编写于
8月 17, 2015
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use Streams from reactor-streams
上级
69d4eaaa
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
22 addition
and
102 deletion
+22
-102
spring-web-reactive/build.gradle
spring-web-reactive/build.gradle
+1
-0
spring-web-reactive/src/main/java/org/springframework/reactive/web/DispatcherHttpHandler.java
...g/springframework/reactive/web/DispatcherHttpHandler.java
+12
-59
spring-web-reactive/src/test/java/org/springframework/reactive/web/DispatcherApp.java
.../java/org/springframework/reactive/web/DispatcherApp.java
+9
-43
未找到文件。
spring-web-reactive/build.gradle
浏览文件 @
6634d1f5
...
@@ -23,6 +23,7 @@ dependencies {
...
@@ -23,6 +23,7 @@ dependencies {
compile
"org.springframework:spring-web:4.2.0.RELEASE"
compile
"org.springframework:spring-web:4.2.0.RELEASE"
compile
"org.reactivestreams:reactive-streams:1.0.0"
compile
"org.reactivestreams:reactive-streams:1.0.0"
compile
"io.projectreactor:reactor-core:2.0.5.RELEASE"
compile
"io.projectreactor:reactor-core:2.0.5.RELEASE"
compile
"io.projectreactor:reactor-net:2.0.5.RELEASE"
compile
"org.slf4j:slf4j-api:1.7.6"
compile
"org.slf4j:slf4j-api:1.7.6"
compile
"ch.qos.logback:logback-classic:1.1.2"
compile
"ch.qos.logback:logback-classic:1.1.2"
...
...
spring-web-reactive/src/main/java/org/springframework/reactive/web/DispatcherHttpHandler.java
浏览文件 @
6634d1f5
...
@@ -19,10 +19,10 @@ import java.util.ArrayList;
...
@@ -19,10 +19,10 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.List
;
import
org.reactivestreams.Publisher
;
import
org.reactivestreams.Publisher
;
import
org.reactivestreams.Subscriber
;
import
org.reactivestreams.Subscription
;
import
reactor.core.reactivestreams.PublisherFactory
;
import
reactor.core.reactivestreams.PublisherFactory
;
import
reactor.core.reactivestreams.SubscriberWithContext
;
import
reactor.core.reactivestreams.SubscriberWithContext
;
import
reactor.rx.Promises
;
import
reactor.rx.Streams
;
import
org.springframework.beans.factory.BeanFactoryUtils
;
import
org.springframework.beans.factory.BeanFactoryUtils
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
...
@@ -64,64 +64,17 @@ public class DispatcherHttpHandler implements HttpHandler {
...
@@ -64,64 +64,17 @@ public class DispatcherHttpHandler implements HttpHandler {
}
}
HandlerAdapter
handlerAdapter
=
getHandlerAdapter
(
handler
);
HandlerAdapter
handlerAdapter
=
getHandlerAdapter
(
handler
);
final
Publisher
<
HandlerResult
>
resultPublisher
=
handlerAdapter
.
handle
(
request
,
response
,
handler
);
Publisher
<
HandlerResult
>
resultPublisher
=
handlerAdapter
.
handle
(
request
,
response
,
handler
);
return
new
Publisher
<
Void
>()
{
return
Streams
.
wrap
(
resultPublisher
).
concatMap
((
HandlerResult
result
)
->
{
for
(
HandlerResultHandler
resultHandler
:
resultHandlers
)
{
@Override
if
(
resultHandler
.
supports
(
result
))
{
public
void
subscribe
(
final
Subscriber
<?
super
Void
>
subscriber
)
{
return
resultHandler
.
handleResult
(
request
,
response
,
result
);
}
resultPublisher
.
subscribe
(
new
Subscriber
<
HandlerResult
>()
{
@Override
public
void
onSubscribe
(
Subscription
subscription
)
{
subscription
.
request
(
Long
.
MAX_VALUE
);
}
@Override
public
void
onNext
(
HandlerResult
result
)
{
for
(
HandlerResultHandler
resultHandler
:
resultHandlers
)
{
if
(
resultHandler
.
supports
(
result
))
{
Publisher
<
Void
>
publisher
=
resultHandler
.
handleResult
(
request
,
response
,
result
);
publisher
.
subscribe
(
new
Subscriber
<
Void
>()
{
@Override
public
void
onSubscribe
(
Subscription
subscription
)
{
subscription
.
request
(
Long
.
MAX_VALUE
);
}
@Override
public
void
onNext
(
Void
aVoid
)
{
// no op
}
@Override
public
void
onError
(
Throwable
error
)
{
// Result handling error (no exception handling mechanism yet)
subscriber
.
onError
(
error
);
}
@Override
public
void
onComplete
()
{
subscriber
.
onComplete
();
}
});
}
}
}
@Override
public
void
onError
(
Throwable
error
)
{
// Application handler error (no exception handling mechanism yet)
subscriber
.
onError
(
error
);
}
@Override
public
void
onComplete
()
{
// do nothing
}
});
}
}
};
String
error
=
"No HandlerResultHandler for "
+
result
.
getReturnValue
();
return
Promises
.
error
(
new
IllegalStateException
(
error
));
});
}
}
protected
Object
getHandler
(
ServerHttpRequest
request
)
{
protected
Object
getHandler
(
ServerHttpRequest
request
)
{
...
...
spring-web-reactive/src/test/java/org/springframework/reactive/web/DispatcherApp.java
浏览文件 @
6634d1f5
...
@@ -22,9 +22,8 @@ import java.util.Map;
...
@@ -22,9 +22,8 @@ import java.util.Map;
import
io.netty.buffer.ByteBuf
;
import
io.netty.buffer.ByteBuf
;
import
io.reactivex.netty.protocol.http.server.HttpServer
;
import
io.reactivex.netty.protocol.http.server.HttpServer
;
import
org.reactivestreams.Publisher
;
import
org.reactivestreams.Publisher
;
import
org.reactivestreams.Subscriber
;
import
reactor.rx.Stream
;
import
org.reactivestreams.Subscription
;
import
reactor.rx.Streams
;
import
reactor.core.reactivestreams.PublisherFactory
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
import
org.springframework.reactive.web.rxnetty.RequestHandlerAdapter
;
import
org.springframework.reactive.web.rxnetty.RequestHandlerAdapter
;
...
@@ -81,12 +80,8 @@ public class DispatcherApp {
...
@@ -81,12 +80,8 @@ public class DispatcherApp {
@Override
@Override
public
Publisher
<
String
>
handle
(
ServerHttpRequest
request
,
ServerHttpResponse
response
)
{
public
Publisher
<
String
>
handle
(
ServerHttpRequest
request
,
ServerHttpResponse
response
)
{
return
PublisherFactory
.
forEach
((
subscriber
)
->
{
return
Streams
.
just
(
"Hello world."
);
subscriber
.
onNext
(
"Hello world."
);
subscriber
.
onComplete
();
});
}
}
}
}
private
static
class
PlainTextHandlerAdapter
implements
HandlerAdapter
{
private
static
class
PlainTextHandlerAdapter
implements
HandlerAdapter
{
...
@@ -97,36 +92,10 @@ public class DispatcherApp {
...
@@ -97,36 +92,10 @@ public class DispatcherApp {
}
}
@Override
@Override
public
Publisher
<
HandlerResult
>
handle
(
ServerHttpRequest
request
,
ServerHttpResponse
response
,
public
Publisher
<
HandlerResult
>
handle
(
ServerHttpRequest
request
,
ServerHttpResponse
response
,
Object
handler
)
{
Object
handler
)
{
Publisher
<
String
>
resultPublisher
=
((
PlainTextHandler
)
handler
).
handle
(
request
,
response
);
Stream
<
String
>
stream
=
Streams
.
wrap
(
resultPublisher
);
PlainTextHandler
textHandler
=
(
PlainTextHandler
)
handler
;
return
stream
.
concatMap
((
returnValue
)
->
Streams
.
just
(
new
HandlerResult
(
returnValue
)));
final
Publisher
<
String
>
resultPublisher
=
textHandler
.
handle
(
request
,
response
);
return
PublisherFactory
.
forEach
((
subscriber
)
->
{
resultPublisher
.
subscribe
(
new
Subscriber
<
Object
>()
{
@Override
public
void
onSubscribe
(
Subscription
subscription
)
{
subscription
.
request
(
Long
.
MAX_VALUE
);
}
@Override
public
void
onNext
(
Object
result
)
{
subscriber
.
onNext
(
new
HandlerResult
(
result
));
}
@Override
public
void
onError
(
Throwable
error
)
{
subscriber
.
onError
(
error
);
}
@Override
public
void
onComplete
()
{
subscriber
.
onComplete
();
}
});
});
}
}
}
}
...
@@ -141,11 +110,8 @@ public class DispatcherApp {
...
@@ -141,11 +110,8 @@ public class DispatcherApp {
@Override
@Override
public
Publisher
<
Void
>
handleResult
(
ServerHttpRequest
request
,
ServerHttpResponse
response
,
HandlerResult
result
)
{
public
Publisher
<
Void
>
handleResult
(
ServerHttpRequest
request
,
ServerHttpResponse
response
,
HandlerResult
result
)
{
response
.
getHeaders
().
setContentType
(
MediaType
.
TEXT_PLAIN
);
response
.
getHeaders
().
setContentType
(
MediaType
.
TEXT_PLAIN
);
return
response
.
writeWith
(
PublisherFactory
.
forEach
((
writeSubscriber
)
->
{
byte
[]
bytes
=
((
String
)
result
.
getReturnValue
()).
getBytes
(
Charset
.
forName
(
"UTF-8"
));
Charset
charset
=
Charset
.
forName
(
"UTF-8"
);
return
response
.
writeWith
(
Streams
.
just
(
bytes
));
writeSubscriber
.
onNext
(((
String
)
result
.
getReturnValue
()).
getBytes
(
charset
));
writeSubscriber
.
onComplete
();
}));
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录