类 MockServerHttpResponse
- java.lang.Object
- org.springframework.http.server.reactive.AbstractServerHttpResponse
- org.springframework.mock.http.server.reactive.MockServerHttpResponse
public class MockServerHttpResponse extends AbstractServerHttpResponse
Mock extension ofAbstractServerHttpResponse
for use in tests without an actual server.By default response content is consumed in full upon writing and cached for subsequent access, however it is also possible to set a custom
writeHandler
.- 从以下版本开始:
- 5.0
- 作者:
- Rossen Stoyanchev
字段概要
从类继承的字段 org.springframework.http.server.reactive.AbstractServerHttpResponse
logger
构造器概要
构造器 构造器 说明 MockServerHttpResponse()
MockServerHttpResponse(DataBufferFactory dataBufferFactory)
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected void
applyCookies()
Add cookies fromAbstractServerHttpResponse.getHeaders()
to the underlying response.protected void
applyHeaders()
Invoked when the response is getting committed allowing sub-classes to make apply header values to the underlying response.protected void
applyStatusCode()
Write the status code to the underlying response.reactor.core.publisher.Flux<DataBuffer>
getBody()
Return the response body or an error stream if the body was not set.reactor.core.publisher.Mono<String>
getBodyAsString()
Aggregate response data and convert to a String using the "Content-Type" charset or "UTF-8" by default.<T> T
getNativeResponse()
Return the underlying server response.reactor.core.publisher.Mono<Void>
setComplete()
Indicate that message handling is complete, allowing for any cleanup or end-of-processing tasks to be performed such as applying header changes made viaHttpMessage.getHeaders()
to the underlying HTTP message (if not applied already).void
setWriteHandler(Function<reactor.core.publisher.Flux<DataBuffer>,reactor.core.publisher.Mono<Void>> writeHandler)
Configure a custom handler to consume the response body.protected reactor.core.publisher.Mono<Void>
writeAndFlushWithInternal(org.reactivestreams.Publisher<? extends org.reactivestreams.Publisher<? extends DataBuffer>> body)
Write to the underlying the response, and flush after eachPublisher<DataBuffer>
.protected reactor.core.publisher.Mono<Void>
writeWithInternal(org.reactivestreams.Publisher<? extends DataBuffer> body)
Write to the underlying the response.从类继承的方法 org.springframework.http.server.reactive.AbstractServerHttpResponse
addCookie, beforeCommit, bufferFactory, doCommit, doCommit, getCookies, getHeaders, getRawStatusCode, getStatusCode, getStatusCodeValue, isCommitted, setRawStatusCode, setStatusCode, setStatusCodeValue, writeAndFlushWith, writeWith
构造器详细资料
MockServerHttpResponse
public MockServerHttpResponse()
MockServerHttpResponse
public MockServerHttpResponse(DataBufferFactory dataBufferFactory)
方法详细资料
setWriteHandler
public void setWriteHandler(Function<reactor.core.publisher.Flux<DataBuffer>,reactor.core.publisher.Mono<Void>> writeHandler)
Configure a custom handler to consume the response body.By default, response body content is consumed in full and cached for subsequent access in tests. Use this option to take control over how the response body is consumed.
- 参数:
writeHandler
- the write handler to use returningMono<Void>
when the body has been "written" (i.e. consumed).
getNativeResponse
public <T> T getNativeResponse()
从类复制的说明:AbstractServerHttpResponse
Return the underlying server response.Note: This is exposed mainly for internal framework use such as WebSocket upgrades in the spring-webflux module.
applyStatusCode
protected void applyStatusCode()
从类复制的说明:AbstractServerHttpResponse
Write the status code to the underlying response. This method is called once only.
applyHeaders
protected void applyHeaders()
从类复制的说明:AbstractServerHttpResponse
Invoked when the response is getting committed allowing sub-classes to make apply header values to the underlying response.Note that most sub-classes use an
HttpHeaders
instance that wraps an adapter to the native response headers such that changes are propagated to the underlying response on the go. That means this callback is typically not used other than for specialized updates such as setting the contentType or characterEncoding fields in a Servlet response.
applyCookies
protected void applyCookies()
从类复制的说明:AbstractServerHttpResponse
Add cookies fromAbstractServerHttpResponse.getHeaders()
to the underlying response. This method is called once only.
writeWithInternal
protected reactor.core.publisher.Mono<Void> writeWithInternal(org.reactivestreams.Publisher<? extends DataBuffer> body)
从类复制的说明:AbstractServerHttpResponse
Write to the underlying the response.- 指定者:
writeWithInternal
在类中AbstractServerHttpResponse
- 参数:
body
- the publisher to write with
writeAndFlushWithInternal
protected reactor.core.publisher.Mono<Void> writeAndFlushWithInternal(org.reactivestreams.Publisher<? extends org.reactivestreams.Publisher<? extends DataBuffer>> body)
从类复制的说明:AbstractServerHttpResponse
Write to the underlying the response, and flush after eachPublisher<DataBuffer>
.- 指定者:
writeAndFlushWithInternal
在类中AbstractServerHttpResponse
- 参数:
body
- the publisher to write and flush with
setComplete
public reactor.core.publisher.Mono<Void> setComplete()
从接口复制的说明:ReactiveHttpOutputMessage
Indicate that message handling is complete, allowing for any cleanup or end-of-processing tasks to be performed such as applying header changes made viaHttpMessage.getHeaders()
to the underlying HTTP message (if not applied already).This method should be automatically invoked at the end of message processing so typically applications should not have to invoke it. If invoked multiple times it should have no side effects.
- 指定者:
setComplete
在接口中ReactiveHttpOutputMessage
- 覆盖:
setComplete
在类中AbstractServerHttpResponse
- 返回:
- a
Mono
that indicates completion or error
getBody
public reactor.core.publisher.Flux<DataBuffer> getBody()
Return the response body or an error stream if the body was not set.
getBodyAsString
public reactor.core.publisher.Mono<String> getBodyAsString()
Aggregate response data and convert to a String using the "Content-Type" charset or "UTF-8" by default.