Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
c5ca56bd
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,体验更适合开发者的 AI 搜索 >>
提交
c5ca56bd
编写于
10月 12, 2018
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish
上级
05830912
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
45 deletion
+30
-45
spring-test/src/main/java/org/springframework/test/web/reactive/server/ExchangeResult.java
...ingframework/test/web/reactive/server/ExchangeResult.java
+2
-2
spring-test/src/main/java/org/springframework/test/web/reactive/server/WiretapConnector.java
...gframework/test/web/reactive/server/WiretapConnector.java
+28
-43
未找到文件。
spring-test/src/main/java/org/springframework/test/web/reactive/server/ExchangeResult.java
浏览文件 @
c5ca56bd
...
...
@@ -231,7 +231,7 @@ public class ExchangeResult {
return
body
.
map
(
bytes
->
{
if
(
contentType
==
null
)
{
return
"Unknown content type ("
+
bytes
.
length
+
" bytes)
"
;
return
bytes
.
length
+
" bytes of content (unknown content-type).
"
;
}
Charset
charset
=
contentType
.
getCharset
();
if
(
charset
!=
null
)
{
...
...
@@ -240,7 +240,7 @@ public class ExchangeResult {
if
(
PRINTABLE_MEDIA_TYPES
.
stream
().
anyMatch
(
contentType:
:
isCompatibleWith
))
{
return
new
String
(
bytes
,
StandardCharsets
.
UTF_8
);
}
return
"Unknown charset ("
+
bytes
.
length
+
" bytes)
"
;
return
bytes
.
length
+
" bytes of content.
"
;
})
.
defaultIfEmpty
(
"No content"
)
.
onErrorResume
(
ex
->
Mono
.
just
(
"Failed to obtain content: "
+
ex
.
getMessage
()))
...
...
spring-test/src/main/java/org/springframework/test/web/reactive/server/WiretapConnector.java
浏览文件 @
c5ca56bd
...
...
@@ -24,7 +24,6 @@ import java.util.concurrent.atomic.AtomicReference;
import
java.util.function.Function
;
import
org.reactivestreams.Publisher
;
import
org.reactivestreams.Subscription
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
reactor.core.publisher.MonoProcessor
;
...
...
@@ -115,10 +114,8 @@ class WiretapConnector implements ClientHttpConnector {
public
ExchangeResult
createExchangeResult
(
Duration
timeout
,
@Nullable
String
uriTemplate
)
{
return
new
ExchangeResult
(
this
.
request
,
this
.
response
,
Mono
.
defer
(()
->
this
.
request
.
getRecorder
().
getContent
()),
Mono
.
defer
(()
->
this
.
response
.
getRecorder
().
getContent
()),
timeout
,
uriTemplate
);
return
new
ExchangeResult
(
this
.
request
,
this
.
response
,
this
.
request
.
getRecorder
().
getContent
(),
this
.
response
.
getRecorder
().
getContent
(),
timeout
,
uriTemplate
);
}
}
...
...
@@ -137,11 +134,11 @@ class WiretapConnector implements ClientHttpConnector {
@Nullable
private
final
Flux
<?
extends
Publisher
<?
extends
DataBuffer
>>
publisherNested
;
private
final
DataBuffer
buffer
;
private
final
DataBuffer
buffer
=
bufferFactory
.
allocateBuffer
()
;
private
final
MonoProcessor
<
byte
[]>
content
;
private
final
MonoProcessor
<
byte
[]>
content
=
MonoProcessor
.
create
()
;
private
volatile
boolean
subscriberRegistered
;
private
boolean
hasContentConsumer
;
public
WiretapRecorder
(
@Nullable
Publisher
<?
extends
DataBuffer
>
publisher
,
...
...
@@ -153,22 +150,23 @@ class WiretapConnector implements ClientHttpConnector {
this
.
publisher
=
publisher
!=
null
?
Flux
.
from
(
publisher
)
.
doOnSubscribe
(
this
::
handleOnSubscrib
e
)
.
doOnNext
(
this
::
handleOnNext
)
.
doOnSubscribe
(
s
->
this
.
hasContentConsumer
=
tru
e
)
.
doOnNext
(
this
.
buffer
::
write
)
.
doOnError
(
this
::
handleOnError
)
.
doOnCancel
(
this
::
handleOnComplete
)
.
doOnComplete
(
this
::
handleOnComplete
)
:
null
;
this
.
publisherNested
=
publisherNested
!=
null
?
Flux
.
from
(
publisherNested
)
.
doOnSubscribe
(
this
::
handleOnSubscrib
e
)
.
map
(
p
->
Flux
.
from
(
p
).
doOnNext
(
this
::
handleOnNext
).
doOnError
(
this
::
handleOnError
))
.
doOnSubscribe
(
s
->
this
.
hasContentConsumer
=
tru
e
)
.
map
(
p
->
Flux
.
from
(
p
).
doOnNext
(
this
.
buffer
::
write
).
doOnError
(
this
::
handleOnError
))
.
doOnError
(
this
::
handleOnError
)
.
doOnCancel
(
this
::
handleOnComplete
)
.
doOnComplete
(
this
::
handleOnComplete
)
:
null
;
this
.
buffer
=
bufferFactory
.
allocateBuffer
();
this
.
content
=
MonoProcessor
.
create
();
if
(
publisher
==
null
&&
publisherNested
==
null
)
{
this
.
content
.
onComplete
();
}
}
...
...
@@ -183,39 +181,26 @@ class WiretapConnector implements ClientHttpConnector {
}
public
Mono
<
byte
[]>
getContent
()
{
// No publisher (e.g. request#setComplete)
if
(
this
.
publisher
==
null
&&
this
.
publisherNested
==
null
)
{
return
Mono
.
empty
();
}
if
(
this
.
content
.
isTerminated
())
{
return
this
.
content
;
}
if
(
this
.
subscriberRegistered
)
{
return
Mono
.
error
(
new
IllegalStateException
(
"Subscriber registered but content is not yet fully consumed."
));
}
else
{
// No subscriber, e.g.:
// - mock server request body never consumed (error before read)
// - FluxExchangeResult#getResponseBodyContent called
(
this
.
publisher
!=
null
?
this
.
publisher
:
this
.
publisherNested
)
.
onErrorMap
(
ex
->
new
IllegalStateException
(
"Content was not been consumed and "
+
"an error was raised on attempt to produce it:"
,
ex
))
.
subscribe
();
return
Mono
.
defer
(()
->
{
if
(
this
.
content
.
isTerminated
())
{
return
this
.
content
;
}
if
(!
this
.
hasContentConsumer
)
{
// Couple of possible cases:
// 1. Mock server never consumed request body (e.g. error before read)
// 2. FluxExchangeResult: getResponseBodyContent called before getResponseBody
//noinspection ConstantConditions
(
this
.
publisher
!=
null
?
this
.
publisher
:
this
.
publisherNested
)
.
onErrorMap
(
ex
->
new
IllegalStateException
(
"Content was not been consumed and "
+
"an error was raised on attempt to produce it:"
,
ex
))
.
subscribe
();
}
return
this
.
content
;
}
}
);
}
private
void
handleOnSubscribe
(
Subscription
subscription
)
{
this
.
subscriberRegistered
=
true
;
}
private
void
handleOnNext
(
DataBuffer
nextBuffer
)
{
this
.
buffer
.
write
(
nextBuffer
);
}
private
void
handleOnError
(
Throwable
ex
)
{
if
(!
this
.
content
.
isTerminated
())
{
this
.
content
.
onError
(
ex
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录