Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
778ef026
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 搜索 >>
提交
778ef026
编写于
9月 17, 2016
作者:
A
Arjen Poutsma
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename BodyInsertor to BodyInserter
上级
b6035ce9
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
87 addition
and
86 deletion
+87
-86
spring-web-reactive/src/main/java/org/springframework/web/reactive/function/BodyInserter.java
...g/springframework/web/reactive/function/BodyInserter.java
+10
-10
spring-web-reactive/src/main/java/org/springframework/web/reactive/function/BodyInserters.java
.../springframework/web/reactive/function/BodyInserters.java
+33
-33
spring-web-reactive/src/main/java/org/springframework/web/reactive/function/DefaultResponseBuilder.java
...amework/web/reactive/function/DefaultResponseBuilder.java
+13
-13
spring-web-reactive/src/main/java/org/springframework/web/reactive/function/Response.java
...a/org/springframework/web/reactive/function/Response.java
+5
-4
spring-web-reactive/src/test/java/org/springframework/web/reactive/function/BodyInsertersTests.java
...ngframework/web/reactive/function/BodyInsertersTests.java
+18
-18
spring-web-reactive/src/test/java/org/springframework/web/reactive/function/DefaultResponseBuilderTests.java
...rk/web/reactive/function/DefaultResponseBuilderTests.java
+1
-1
spring-web-reactive/src/test/java/org/springframework/web/reactive/function/DispatcherHandlerIntegrationTests.java
.../reactive/function/DispatcherHandlerIntegrationTests.java
+2
-2
spring-web-reactive/src/test/java/org/springframework/web/reactive/function/PublisherHandlerFunctionIntegrationTests.java
...ve/function/PublisherHandlerFunctionIntegrationTests.java
+1
-1
spring-web-reactive/src/test/java/org/springframework/web/reactive/function/RouterFunctionTests.java
...gframework/web/reactive/function/RouterFunctionTests.java
+1
-1
spring-web-reactive/src/test/java/org/springframework/web/reactive/function/SseHandlerFunctionIntegrationTests.java
...reactive/function/SseHandlerFunctionIntegrationTests.java
+3
-3
未找到文件。
spring-web-reactive/src/main/java/org/springframework/web/reactive/function/BodyInsert
o
r.java
→
spring-web-reactive/src/main/java/org/springframework/web/reactive/function/BodyInsert
e
r.java
浏览文件 @
778ef026
...
...
@@ -31,10 +31,10 @@ import org.springframework.util.Assert;
* @author Arjen Poutsma
* @since 5.0
* @see Response#body()
* @see Response.BodyBuilder#body(BodyInsert
o
r)
* @see BodyInsert
o
rs
* @see Response.BodyBuilder#body(BodyInsert
e
r)
* @see BodyInsert
e
rs
*/
public
interface
BodyInsert
o
r
<
T
>
{
public
interface
BodyInsert
e
r
<
T
>
{
/**
* Insert into the given response.
...
...
@@ -52,19 +52,19 @@ public interface BodyInsertor<T> {
/**
* Return a new {@code BodyInsert
o
r} described by the given writer and supplier functions.
* @param writer the writer function for the new insert
o
r
* @param supplier the supplier function for the new insert
o
r
* @param <T> the type supplied and written by the insert
o
r
* @return the new {@code BodyInsert
o
r}
* Return a new {@code BodyInsert
e
r} described by the given writer and supplier functions.
* @param writer the writer function for the new insert
e
r
* @param supplier the supplier function for the new insert
e
r
* @param <T> the type supplied and written by the insert
e
r
* @return the new {@code BodyInsert
e
r}
*/
static
<
T
>
BodyInsert
o
r
<
T
>
of
(
BiFunction
<
ServerHttpResponse
,
Configuration
,
Mono
<
Void
>>
writer
,
static
<
T
>
BodyInsert
e
r
<
T
>
of
(
BiFunction
<
ServerHttpResponse
,
Configuration
,
Mono
<
Void
>>
writer
,
Supplier
<
T
>
supplier
)
{
Assert
.
notNull
(
writer
,
"'writer' must not be null"
);
Assert
.
notNull
(
supplier
,
"'supplier' must not be null"
);
return
new
BodyInsert
ors
.
DefaultBodyInserto
r
<
T
>(
writer
,
supplier
);
return
new
BodyInsert
ers
.
DefaultBodyInserte
r
<
T
>(
writer
,
supplier
);
}
}
spring-web-reactive/src/main/java/org/springframework/web/reactive/function/BodyInsert
o
rs.java
→
spring-web-reactive/src/main/java/org/springframework/web/reactive/function/BodyInsert
e
rs.java
浏览文件 @
778ef026
...
...
@@ -37,13 +37,13 @@ import org.springframework.util.Assert;
import
org.springframework.util.ClassUtils
;
/**
* Implementations of {@link BodyInsert
o
r} that write various bodies, such a reactive streams,
* Implementations of {@link BodyInsert
e
r} that write various bodies, such a reactive streams,
* server-sent events, resources, etc.
*
* @author Arjen Poutsma
* @since 5.0
*/
public
abstract
class
BodyInsert
o
rs
{
public
abstract
class
BodyInsert
e
rs
{
private
static
final
ResolvableType
RESOURCE_TYPE
=
ResolvableType
.
forClass
(
Resource
.
class
);
...
...
@@ -52,32 +52,32 @@ public abstract class BodyInsertors {
private
static
final
boolean
jackson2Present
=
ClassUtils
.
isPresent
(
"com.fasterxml.jackson.databind.ObjectMapper"
,
BodyInsert
o
rs
.
class
.
getClassLoader
())
&&
BodyInsert
e
rs
.
class
.
getClassLoader
())
&&
ClassUtils
.
isPresent
(
"com.fasterxml.jackson.core.JsonGenerator"
,
BodyInsert
o
rs
.
class
.
getClassLoader
());
BodyInsert
e
rs
.
class
.
getClassLoader
());
/**
* Return a {@code BodyInsert
o
r} that writes the given single object.
* Return a {@code BodyInsert
e
r} that writes the given single object.
* @param body the body of the response
* @return a {@code BodyInsert
o
r} that writes a single object
* @return a {@code BodyInsert
e
r} that writes a single object
*/
public
static
<
T
>
BodyInsert
o
r
<
T
>
fromObject
(
T
body
)
{
public
static
<
T
>
BodyInsert
e
r
<
T
>
fromObject
(
T
body
)
{
Assert
.
notNull
(
body
,
"'body' must not be null"
);
return
BodyInsert
o
r
.
of
(
return
BodyInsert
e
r
.
of
(
(
response
,
configuration
)
->
writeWithMessageWriters
(
response
,
configuration
,
Mono
.
just
(
body
),
ResolvableType
.
forInstance
(
body
)),
()
->
body
);
}
/**
* Return a {@code BodyInsert
o
r} that writes the given {@link Publisher}.
* Return a {@code BodyInsert
e
r} that writes the given {@link Publisher}.
* @param publisher the publisher to stream to the response body
* @param elementClass the class of elements contained in the publisher
* @param <T> the type of the elements contained in the publisher
* @param <S> the type of the {@code Publisher}.
* @return a {@code BodyInsert
o
r} that writes a {@code Publisher}
* @return a {@code BodyInsert
e
r} that writes a {@code Publisher}
*/
public
static
<
S
extends
Publisher
<
T
>,
T
>
BodyInsert
o
r
<
S
>
fromPublisher
(
S
publisher
,
public
static
<
S
extends
Publisher
<
T
>,
T
>
BodyInsert
e
r
<
S
>
fromPublisher
(
S
publisher
,
Class
<
T
>
elementClass
)
{
Assert
.
notNull
(
publisher
,
"'publisher' must not be null"
);
...
...
@@ -86,19 +86,19 @@ public abstract class BodyInsertors {
}
/**
* Return a {@code BodyInsert
o
r} that writes the given {@link Publisher}.
* Return a {@code BodyInsert
e
r} that writes the given {@link Publisher}.
* @param publisher the publisher to stream to the response body
* @param elementType the type of elements contained in the publisher
* @param <T> the type of the elements contained in the publisher
* @param <S> the type of the {@code Publisher}.
* @return a {@code BodyInsert
o
r} that writes a {@code Publisher}
* @return a {@code BodyInsert
e
r} that writes a {@code Publisher}
*/
public
static
<
S
extends
Publisher
<
T
>,
T
>
BodyInsert
o
r
<
S
>
fromPublisher
(
S
publisher
,
public
static
<
S
extends
Publisher
<
T
>,
T
>
BodyInsert
e
r
<
S
>
fromPublisher
(
S
publisher
,
ResolvableType
elementType
)
{
Assert
.
notNull
(
publisher
,
"'publisher' must not be null"
);
Assert
.
notNull
(
elementType
,
"'elementType' must not be null"
);
return
BodyInsert
o
r
.
of
(
return
BodyInsert
e
r
.
of
(
(
response
,
configuration
)
->
writeWithMessageWriters
(
response
,
configuration
,
publisher
,
elementType
),
()
->
publisher
...
...
@@ -106,17 +106,17 @@ public abstract class BodyInsertors {
}
/**
* Return a {@code BodyInsert
o
r} that writes the given {@code Resource}.
* Return a {@code BodyInsert
e
r} that writes the given {@code Resource}.
* If the resource can be resolved to a {@linkplain Resource#getFile() file}, it will be copied
* using
* <a href="https://en.wikipedia.org/wiki/Zero-copy">zero-copy</a>
* @param resource the resource to write to the response
* @param <T> the type of the {@code Resource}
* @return a {@code BodyInsert
o
r} that writes a {@code Publisher}
* @return a {@code BodyInsert
e
r} that writes a {@code Publisher}
*/
public
static
<
T
extends
Resource
>
BodyInsert
o
r
<
T
>
fromResource
(
T
resource
)
{
public
static
<
T
extends
Resource
>
BodyInsert
e
r
<
T
>
fromResource
(
T
resource
)
{
Assert
.
notNull
(
resource
,
"'resource' must not be null"
);
return
BodyInsert
o
r
.
of
(
return
BodyInsert
e
r
.
of
(
(
response
,
configuration
)
->
{
ResourceHttpMessageWriter
messageWriter
=
new
ResourceHttpMessageWriter
();
MediaType
contentType
=
response
.
getHeaders
().
getContentType
();
...
...
@@ -128,17 +128,17 @@ public abstract class BodyInsertors {
}
/**
* Return a {@code BodyInsert
o
r} that writes the given {@code ServerSentEvent} publisher.
* Return a {@code BodyInsert
e
r} that writes the given {@code ServerSentEvent} publisher.
* @param eventsPublisher the {@code ServerSentEvent} publisher to write to the response body
* @param <T> the type of the elements contained in the {@link ServerSentEvent}
* @return a {@code BodyInsert
o
r} that writes a {@code ServerSentEvent} publisher
* @return a {@code BodyInsert
e
r} that writes a {@code ServerSentEvent} publisher
* @see <a href="https://www.w3.org/TR/eventsource/">Server-Sent Events W3C recommendation</a>
*/
public
static
<
T
,
S
extends
Publisher
<
ServerSentEvent
<
T
>>>
BodyInsert
o
r
<
S
>
fromServerSentEvents
(
public
static
<
T
,
S
extends
Publisher
<
ServerSentEvent
<
T
>>>
BodyInsert
e
r
<
S
>
fromServerSentEvents
(
S
eventsPublisher
)
{
Assert
.
notNull
(
eventsPublisher
,
"'eventsPublisher' must not be null"
);
return
BodyInsert
o
r
.
of
(
return
BodyInsert
e
r
.
of
(
(
response
,
configuration
)
->
{
ServerSentEventHttpMessageWriter
messageWriter
=
sseMessageWriter
();
MediaType
contentType
=
response
.
getHeaders
().
getContentType
();
...
...
@@ -150,16 +150,16 @@ public abstract class BodyInsertors {
}
/**
* Return a {@code BodyInsert
o
r} that writes the given {@code Publisher} publisher as
* Return a {@code BodyInsert
e
r} that writes the given {@code Publisher} publisher as
* Server-Sent Events.
* @param eventsPublisher the publisher to write to the response body as Server-Sent Events
* @param eventClass the class of event contained in the publisher
* @param <T> the type of the elements contained in the publisher
* @return a {@code BodyInsert
o
r} that writes the given {@code Publisher} publisher as
* @return a {@code BodyInsert
e
r} that writes the given {@code Publisher} publisher as
* Server-Sent Events
* @see <a href="https://www.w3.org/TR/eventsource/">Server-Sent Events W3C recommendation</a>
*/
public
static
<
T
,
S
extends
Publisher
<
T
>>
BodyInsert
o
r
<
S
>
fromServerSentEvents
(
S
eventsPublisher
,
public
static
<
T
,
S
extends
Publisher
<
T
>>
BodyInsert
e
r
<
S
>
fromServerSentEvents
(
S
eventsPublisher
,
Class
<
T
>
eventClass
)
{
Assert
.
notNull
(
eventsPublisher
,
"'eventsPublisher' must not be null"
);
...
...
@@ -168,21 +168,21 @@ public abstract class BodyInsertors {
}
/**
* Return a {@code BodyInsert
o
r} that writes the given {@code Publisher} publisher as
* Return a {@code BodyInsert
e
r} that writes the given {@code Publisher} publisher as
* Server-Sent Events.
* @param eventsPublisher the publisher to write to the response body as Server-Sent Events
* @param eventType the type of event contained in the publisher
* @param <T> the type of the elements contained in the publisher
* @return a {@code BodyInsert
o
r} that writes the given {@code Publisher} publisher as
* @return a {@code BodyInsert
e
r} that writes the given {@code Publisher} publisher as
* Server-Sent Events
* @see <a href="https://www.w3.org/TR/eventsource/">Server-Sent Events W3C recommendation</a>
*/
public
static
<
T
,
S
extends
Publisher
<
T
>>
BodyInsert
o
r
<
S
>
fromServerSentEvents
(
S
eventsPublisher
,
public
static
<
T
,
S
extends
Publisher
<
T
>>
BodyInsert
e
r
<
S
>
fromServerSentEvents
(
S
eventsPublisher
,
ResolvableType
eventType
)
{
Assert
.
notNull
(
eventsPublisher
,
"'eventsPublisher' must not be null"
);
Assert
.
notNull
(
eventType
,
"'eventType' must not be null"
);
return
BodyInsert
o
r
.
of
(
return
BodyInsert
e
r
.
of
(
(
response
,
configuration
)
->
{
ServerSentEventHttpMessageWriter
messageWriter
=
sseMessageWriter
();
MediaType
contentType
=
response
.
getHeaders
().
getContentType
();
...
...
@@ -211,7 +211,7 @@ public abstract class BodyInsertors {
.
filter
(
messageWriter
->
messageWriter
.
canWrite
(
bodyType
,
contentType
,
Collections
.
emptyMap
()))
.
findFirst
()
.
map
(
BodyInsert
o
rs:
:
cast
)
.
map
(
BodyInsert
e
rs:
:
cast
)
.
map
(
messageWriter
->
messageWriter
.
write
(
body
,
bodyType
,
contentType
,
response
,
Collections
.
emptyMap
()))
...
...
@@ -226,13 +226,13 @@ public abstract class BodyInsertors {
return
(
HttpMessageWriter
<
T
>)
messageWriter
;
}
static
class
DefaultBodyInsert
or
<
T
>
implements
BodyInserto
r
<
T
>
{
static
class
DefaultBodyInsert
er
<
T
>
implements
BodyInserte
r
<
T
>
{
private
final
BiFunction
<
ServerHttpResponse
,
Configuration
,
Mono
<
Void
>>
writer
;
private
final
Supplier
<
T
>
supplier
;
public
DefaultBodyInsert
o
r
(
public
DefaultBodyInsert
e
r
(
BiFunction
<
ServerHttpResponse
,
Configuration
,
Mono
<
Void
>>
writer
,
Supplier
<
T
>
supplier
)
{
this
.
writer
=
writer
;
...
...
spring-web-reactive/src/main/java/org/springframework/web/reactive/function/DefaultResponseBuilder.java
浏览文件 @
778ef026
...
...
@@ -141,7 +141,7 @@ class DefaultResponseBuilder implements Response.BodyBuilder {
@Override
public
Response
<
Void
>
build
()
{
return
body
(
BodyInsert
o
r
.
of
(
return
body
(
BodyInsert
e
r
.
of
(
(
response
,
configuration
)
->
response
.
setComplete
(),
()
->
null
));
}
...
...
@@ -149,7 +149,7 @@ class DefaultResponseBuilder implements Response.BodyBuilder {
@Override
public
<
T
extends
Publisher
<
Void
>>
Response
<
T
>
build
(
T
voidPublisher
)
{
Assert
.
notNull
(
voidPublisher
,
"'voidPublisher' must not be null"
);
return
body
(
BodyInsert
o
r
.
of
(
return
body
(
BodyInsert
e
r
.
of
(
(
response
,
configuration
)
->
Flux
.
from
(
voidPublisher
).
then
(
response
.
setComplete
()),
()
->
null
));
}
...
...
@@ -157,13 +157,13 @@ class DefaultResponseBuilder implements Response.BodyBuilder {
@Override
public
<
T
>
Response
<
T
>
body
(
BiFunction
<
ServerHttpResponse
,
Configuration
,
Mono
<
Void
>>
writer
,
Supplier
<
T
>
supplier
)
{
return
body
(
BodyInsert
o
r
.
of
(
writer
,
supplier
));
return
body
(
BodyInsert
e
r
.
of
(
writer
,
supplier
));
}
@Override
public
<
T
>
Response
<
T
>
body
(
BodyInsert
or
<
T
>
inserto
r
)
{
Assert
.
notNull
(
insert
or
,
"'inserto
r' must not be null"
);
return
new
BodyInsert
orResponse
<
T
>(
this
.
statusCode
,
this
.
headers
,
inserto
r
);
public
<
T
>
Response
<
T
>
body
(
BodyInsert
er
<
T
>
inserte
r
)
{
Assert
.
notNull
(
insert
er
,
"'inserte
r' must not be null"
);
return
new
BodyInsert
erResponse
<
T
>(
this
.
statusCode
,
this
.
headers
,
inserte
r
);
}
@Override
...
...
@@ -233,27 +233,27 @@ class DefaultResponseBuilder implements Response.BodyBuilder {
}
}
private
static
final
class
BodyInsert
o
rResponse
<
T
>
extends
AbstractResponse
<
T
>
{
private
static
final
class
BodyInsert
e
rResponse
<
T
>
extends
AbstractResponse
<
T
>
{
private
final
BodyInsert
or
<
T
>
inserto
r
;
private
final
BodyInsert
er
<
T
>
inserte
r
;
public
BodyInsert
o
rResponse
(
int
statusCode
,
HttpHeaders
headers
,
BodyInsert
or
<
T
>
inserto
r
)
{
public
BodyInsert
e
rResponse
(
int
statusCode
,
HttpHeaders
headers
,
BodyInsert
er
<
T
>
inserte
r
)
{
super
(
statusCode
,
headers
);
this
.
insert
or
=
inserto
r
;
this
.
insert
er
=
inserte
r
;
}
@Override
public
T
body
()
{
return
this
.
insert
o
r
.
t
();
return
this
.
insert
e
r
.
t
();
}
@Override
public
Mono
<
Void
>
writeTo
(
ServerWebExchange
exchange
,
Configuration
configuration
)
{
ServerHttpResponse
response
=
exchange
.
getResponse
();
writeStatusAndHeaders
(
response
);
return
this
.
insert
o
r
.
insert
(
response
,
configuration
);
return
this
.
insert
e
r
.
insert
(
response
,
configuration
);
}
}
...
...
spring-web-reactive/src/main/java/org/springframework/web/reactive/function/Response.java
浏览文件 @
778ef026
...
...
@@ -308,7 +308,8 @@ public interface Response<T> {
BodyBuilder
contentType
(
MediaType
contentType
);
/**
* Write the body to the given {@code BodyInsertor} and return it.
* Set the body with the given {@code supplier} function, and write it with the given
* {@code writer} function.
* @param writer a function that writes the body to the {@code ServerHttpResponse}
* @param supplier a function that returns the body instance
* @param <T> the type contained in the body
...
...
@@ -318,12 +319,12 @@ public interface Response<T> {
Supplier
<
T
>
supplier
);
/**
* Set the body of the response to the given {@code BodyInsert
o
r} and return it.
* @param insert
or the {@code BodyInserto
r} that writes to the response
* Set the body of the response to the given {@code BodyInsert
e
r} and return it.
* @param insert
er the {@code BodyInserte
r} that writes to the response
* @param <T> the type contained in the body
* @return the built response
*/
<
T
>
Response
<
T
>
body
(
BodyInsert
or
<
T
>
inserto
r
);
<
T
>
Response
<
T
>
body
(
BodyInsert
er
<
T
>
inserte
r
);
/**
* Render the template with the given {@code name} using the given {@code modelAttributes}.
...
...
spring-web-reactive/src/test/java/org/springframework/web/reactive/function/BodyInsert
o
rsTests.java
→
spring-web-reactive/src/test/java/org/springframework/web/reactive/function/BodyInsert
e
rsTests.java
浏览文件 @
778ef026
...
...
@@ -38,17 +38,17 @@ import static org.junit.Assert.assertEquals;
/**
* @author Arjen Poutsma
*/
public
class
BodyInsert
o
rsTests
{
public
class
BodyInsert
e
rsTests
{
@Test
public
void
ofObject
()
throws
Exception
{
String
body
=
"foo"
;
BodyInsert
or
<
String
>
insertor
=
BodyInserto
rs
.
fromObject
(
body
);
BodyInsert
er
<
String
>
inserter
=
BodyInserte
rs
.
fromObject
(
body
);
assertEquals
(
body
,
insert
o
r
.
t
());
assertEquals
(
body
,
insert
e
r
.
t
());
MockServerHttpResponse
response
=
new
MockServerHttpResponse
();
Mono
<
Void
>
result
=
insert
o
r
.
insert
(
response
,
Configuration
.
builder
().
build
());
Mono
<
Void
>
result
=
insert
e
r
.
insert
(
response
,
Configuration
.
builder
().
build
());
TestSubscriber
.
subscribe
(
result
)
.
assertComplete
();
...
...
@@ -62,12 +62,12 @@ public class BodyInsertorsTests {
@Test
public
void
ofPublisher
()
throws
Exception
{
Flux
<
String
>
body
=
Flux
.
just
(
"foo"
);
BodyInsert
or
<
Flux
<
String
>>
insertor
=
BodyInserto
rs
.
fromPublisher
(
body
,
String
.
class
);
BodyInsert
er
<
Flux
<
String
>>
inserter
=
BodyInserte
rs
.
fromPublisher
(
body
,
String
.
class
);
assertEquals
(
body
,
insert
o
r
.
t
());
assertEquals
(
body
,
insert
e
r
.
t
());
MockServerHttpResponse
response
=
new
MockServerHttpResponse
();
Mono
<
Void
>
result
=
insert
o
r
.
insert
(
response
,
Configuration
.
builder
().
build
());
Mono
<
Void
>
result
=
insert
e
r
.
insert
(
response
,
Configuration
.
builder
().
build
());
TestSubscriber
.
subscribe
(
result
)
.
assertComplete
();
...
...
@@ -81,12 +81,12 @@ public class BodyInsertorsTests {
@Test
public
void
ofResource
()
throws
Exception
{
Resource
body
=
new
ClassPathResource
(
"response.txt"
,
getClass
());
BodyInsert
or
<
Resource
>
insertor
=
BodyInserto
rs
.
fromResource
(
body
);
BodyInsert
er
<
Resource
>
inserter
=
BodyInserte
rs
.
fromResource
(
body
);
assertEquals
(
body
,
insert
o
r
.
t
());
assertEquals
(
body
,
insert
e
r
.
t
());
MockServerHttpResponse
response
=
new
MockServerHttpResponse
();
Mono
<
Void
>
result
=
insert
o
r
.
insert
(
response
,
Configuration
.
builder
().
build
());
Mono
<
Void
>
result
=
insert
e
r
.
insert
(
response
,
Configuration
.
builder
().
build
());
TestSubscriber
.
subscribe
(
result
)
.
assertComplete
();
...
...
@@ -105,13 +105,13 @@ public class BodyInsertorsTests {
public
void
ofServerSentEventFlux
()
throws
Exception
{
ServerSentEvent
<
String
>
event
=
ServerSentEvent
.
builder
(
"foo"
).
build
();
Flux
<
ServerSentEvent
<
String
>>
body
=
Flux
.
just
(
event
);
BodyInsert
or
<
Flux
<
ServerSentEvent
<
String
>>>
inserto
r
=
BodyInsert
o
rs
.
fromServerSentEvents
(
body
);
BodyInsert
er
<
Flux
<
ServerSentEvent
<
String
>>>
inserte
r
=
BodyInsert
e
rs
.
fromServerSentEvents
(
body
);
assertEquals
(
body
,
insert
o
r
.
t
());
assertEquals
(
body
,
insert
e
r
.
t
());
MockServerHttpResponse
response
=
new
MockServerHttpResponse
();
Mono
<
Void
>
result
=
insert
o
r
.
insert
(
response
,
Configuration
.
builder
().
build
());
Mono
<
Void
>
result
=
insert
e
r
.
insert
(
response
,
Configuration
.
builder
().
build
());
TestSubscriber
.
subscribe
(
result
)
.
assertComplete
();
...
...
@@ -120,13 +120,13 @@ public class BodyInsertorsTests {
@Test
public
void
ofServerSentEventClass
()
throws
Exception
{
Flux
<
String
>
body
=
Flux
.
just
(
"foo"
);
BodyInsert
or
<
Flux
<
String
>>
inserto
r
=
BodyInsert
o
rs
.
fromServerSentEvents
(
body
,
String
.
class
);
BodyInsert
er
<
Flux
<
String
>>
inserte
r
=
BodyInsert
e
rs
.
fromServerSentEvents
(
body
,
String
.
class
);
assertEquals
(
body
,
insert
o
r
.
t
());
assertEquals
(
body
,
insert
e
r
.
t
());
MockServerHttpResponse
response
=
new
MockServerHttpResponse
();
Mono
<
Void
>
result
=
insert
o
r
.
insert
(
response
,
Configuration
.
builder
().
build
());
Mono
<
Void
>
result
=
insert
e
r
.
insert
(
response
,
Configuration
.
builder
().
build
());
TestSubscriber
.
subscribe
(
result
)
.
assertComplete
();
...
...
spring-web-reactive/src/test/java/org/springframework/web/reactive/function/DefaultResponseBuilderTests.java
浏览文件 @
778ef026
...
...
@@ -214,7 +214,7 @@ public class DefaultResponseBuilderTests {
}
@Test
public
void
bodyInsert
o
r
()
throws
Exception
{
public
void
bodyInsert
e
r
()
throws
Exception
{
String
body
=
"foo"
;
Supplier
<
String
>
supplier
=
()
->
body
;
BiFunction
<
ServerHttpResponse
,
Configuration
,
Mono
<
Void
>>
writer
=
...
...
spring-web-reactive/src/test/java/org/springframework/web/reactive/function/DispatcherHandlerIntegrationTests.java
浏览文件 @
778ef026
...
...
@@ -155,14 +155,14 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
public
Response
<
Publisher
<
Person
>>
mono
(
Request
request
)
{
Person
person
=
new
Person
(
"John"
);
return
Response
.
ok
().
body
(
BodyInsert
o
rs
.
fromPublisher
(
Mono
.
just
(
person
),
Person
.
class
));
return
Response
.
ok
().
body
(
BodyInsert
e
rs
.
fromPublisher
(
Mono
.
just
(
person
),
Person
.
class
));
}
public
Response
<
Publisher
<
Person
>>
flux
(
Request
request
)
{
Person
person1
=
new
Person
(
"John"
);
Person
person2
=
new
Person
(
"Jane"
);
return
Response
.
ok
().
body
(
BodyInsert
o
rs
.
fromPublisher
(
Flux
.
just
(
person1
,
person2
),
Person
.
class
));
BodyInsert
e
rs
.
fromPublisher
(
Flux
.
just
(
person1
,
person2
),
Person
.
class
));
}
}
...
...
spring-web-reactive/src/test/java/org/springframework/web/reactive/function/PublisherHandlerFunctionIntegrationTests.java
浏览文件 @
778ef026
...
...
@@ -34,7 +34,7 @@ import org.springframework.web.client.RestTemplate;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
springframework
.
web
.
reactive
.
function
.
BodyExtractors
.
toMono
;
import
static
org
.
springframework
.
web
.
reactive
.
function
.
BodyInsert
o
rs
.
fromPublisher
;
import
static
org
.
springframework
.
web
.
reactive
.
function
.
BodyInsert
e
rs
.
fromPublisher
;
import
static
org
.
springframework
.
web
.
reactive
.
function
.
RequestPredicates
.
GET
;
import
static
org
.
springframework
.
web
.
reactive
.
function
.
RequestPredicates
.
POST
;
import
static
org
.
springframework
.
web
.
reactive
.
function
.
RouterFunctions
.
route
;
...
...
spring-web-reactive/src/test/java/org/springframework/web/reactive/function/RouterFunctionTests.java
浏览文件 @
778ef026
...
...
@@ -23,7 +23,7 @@ import org.junit.Test;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
web
.
reactive
.
function
.
BodyInsert
o
rs
.
fromObject
;
import
static
org
.
springframework
.
web
.
reactive
.
function
.
BodyInsert
e
rs
.
fromObject
;
/**
* @author Arjen Poutsma
...
...
spring-web-reactive/src/test/java/org/springframework/web/reactive/function/SseHandlerFunctionIntegrationTests.java
浏览文件 @
778ef026
...
...
@@ -111,13 +111,13 @@ public class SseHandlerFunctionIntegrationTests
public
Response
<
Publisher
<
String
>>
string
(
Request
request
)
{
Flux
<
String
>
flux
=
Flux
.
interval
(
Duration
.
ofMillis
(
100
)).
map
(
l
->
"foo "
+
l
).
take
(
2
);
return
Response
.
ok
().
body
(
BodyInsert
o
rs
.
fromServerSentEvents
(
flux
,
String
.
class
));
return
Response
.
ok
().
body
(
BodyInsert
e
rs
.
fromServerSentEvents
(
flux
,
String
.
class
));
}
public
Response
<
Publisher
<
Person
>>
person
(
Request
request
)
{
Flux
<
Person
>
flux
=
Flux
.
interval
(
Duration
.
ofMillis
(
100
))
.
map
(
l
->
new
Person
(
"foo "
+
l
)).
take
(
2
);
return
Response
.
ok
().
body
(
BodyInsert
o
rs
.
fromServerSentEvents
(
flux
,
Person
.
class
));
return
Response
.
ok
().
body
(
BodyInsert
e
rs
.
fromServerSentEvents
(
flux
,
Person
.
class
));
}
public
Response
<
Publisher
<
ServerSentEvent
<
String
>>>
sse
(
Request
request
)
{
...
...
@@ -127,7 +127,7 @@ public class SseHandlerFunctionIntegrationTests
.
comment
(
"bar"
)
.
build
()).
take
(
2
);
return
Response
.
ok
().
body
(
BodyInsert
o
rs
.
fromServerSentEvents
(
flux
));
return
Response
.
ok
().
body
(
BodyInsert
e
rs
.
fromServerSentEvents
(
flux
));
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录