类 MockClientHttpRequest
- java.lang.Object
- org.springframework.http.client.reactive.AbstractClientHttpRequest
- org.springframework.mock.http.client.reactive.MockClientHttpRequest
public class MockClientHttpRequest extends AbstractClientHttpRequest
Mock implementation ofClientHttpRequest.- 从以下版本开始:
- 5.0
- 作者:
- Brian Clozel, Rossen Stoyanchev
构造器概要
构造器 构造器 说明 MockClientHttpRequest(HttpMethod httpMethod, String urlTemplate, Object... vars)MockClientHttpRequest(HttpMethod httpMethod, URI url)
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected voidapplyCookies()Add cookies fromAbstractClientHttpRequest.getHeaders()to the underlying request.protected voidapplyHeaders()Apply header changes fromAbstractClientHttpRequest.getHeaders()to the underlying request.DataBufferFactorybufferFactory()Return aDataBufferFactorythat can be used to create the body.reactor.core.publisher.Flux<DataBuffer>getBody()Return the request body, or an error stream if the body was never set or whensetWriteHandler(java.util.function.Function<reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer>, reactor.core.publisher.Mono<java.lang.Void>>)is configured.reactor.core.publisher.Mono<String>getBodyAsString()Aggregate response data and convert to a String using the "Content-Type" charset or "UTF-8" by default.HttpMethodgetMethod()Return the HTTP method of the request.URIgetURI()Return the URI of the request.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).voidsetWriteHandler(Function<reactor.core.publisher.Flux<DataBuffer>,reactor.core.publisher.Mono<Void>> writeHandler)Configure a custom handler for writing the request body.reactor.core.publisher.Mono<Void>writeAndFlushWith(org.reactivestreams.Publisher<? extends org.reactivestreams.Publisher<? extends DataBuffer>> body)Use the givenPublisherofPublishersto write the body of the HttpOutputMessage to the underlying HTTP layer, flushing after eachPublisher<DataBuffer>.reactor.core.publisher.Mono<Void>writeWith(org.reactivestreams.Publisher<? extends DataBuffer> body)Use the givenPublisherto write the body of the message to the underlying HTTP layer.从类继承的方法 org.springframework.http.client.reactive.AbstractClientHttpRequest
beforeCommit, doCommit, doCommit, getCookies, getHeaders, isCommitted
构造器详细资料
MockClientHttpRequest
public MockClientHttpRequest(HttpMethod httpMethod, String urlTemplate, Object... vars)
MockClientHttpRequest
public MockClientHttpRequest(HttpMethod httpMethod, URI url)
方法详细资料
setWriteHandler
public void setWriteHandler(Function<reactor.core.publisher.Flux<DataBuffer>,reactor.core.publisher.Mono<Void>> writeHandler)
Configure a custom handler for writing the request body.The default write handler consumes and caches the request body so it may be accessed subsequently, e.g. in test assertions. Use this property when the request body is an infinite stream.
- 参数:
writeHandler- the write handler to use returningMono<Void>when the body has been "written" (i.e. consumed).
getMethod
public HttpMethod getMethod()
从接口复制的说明:ClientHttpRequestReturn the HTTP method of the request.
getURI
public URI getURI()
从接口复制的说明:ClientHttpRequestReturn the URI of the request.
bufferFactory
public DataBufferFactory bufferFactory()
从接口复制的说明:ReactiveHttpOutputMessageReturn aDataBufferFactorythat can be used to create the body.- 返回:
- a buffer factory
- 另请参阅:
ReactiveHttpOutputMessage.writeWith(Publisher)
applyHeaders
protected void applyHeaders()
从类复制的说明:AbstractClientHttpRequestApply header changes fromAbstractClientHttpRequest.getHeaders()to the underlying request. This method is called once only.
applyCookies
protected void applyCookies()
从类复制的说明:AbstractClientHttpRequestAdd cookies fromAbstractClientHttpRequest.getHeaders()to the underlying request. This method is called once only.
writeWith
public reactor.core.publisher.Mono<Void> writeWith(org.reactivestreams.Publisher<? extends DataBuffer> body)
从接口复制的说明:ReactiveHttpOutputMessageUse the givenPublisherto write the body of the message to the underlying HTTP layer.- 参数:
body- the body content publisher- 返回:
- a
Monothat indicates completion or error
writeAndFlushWith
public reactor.core.publisher.Mono<Void> writeAndFlushWith(org.reactivestreams.Publisher<? extends org.reactivestreams.Publisher<? extends DataBuffer>> body)
从接口复制的说明:ReactiveHttpOutputMessageUse the givenPublisherofPublishersto write the body of the HttpOutputMessage to the underlying HTTP layer, flushing after eachPublisher<DataBuffer>.- 参数:
body- the body content publisher- 返回:
- a
Monothat indicates completion or error
setComplete
public reactor.core.publisher.Mono<Void> setComplete()
从接口复制的说明:ReactiveHttpOutputMessageIndicate 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.
- 返回:
- a
Monothat indicates completion or error
getBody
public reactor.core.publisher.Flux<DataBuffer> getBody()
Return the request body, or an error stream if the body was never set or whensetWriteHandler(java.util.function.Function<reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer>, reactor.core.publisher.Mono<java.lang.Void>>)is configured.
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.