Class MockServerHttpResponse
- All Implemented Interfaces:
- HttpMessage,- ReactiveHttpOutputMessage,- ServerHttpResponse
AbstractServerHttpResponse 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.
- Since:
- 5.0
- Author:
- Rossen Stoyanchev
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidAdd cookies fromAbstractServerHttpResponse.getHeaders()to the underlying response.protected voidInvoked when the response is getting committed allowing sub-classes to make apply header values to the underlying response.protected voidWrite 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>Aggregate response data and convert to a String using the "Content-Type" charset or "UTF-8" by default.<T> TReturn the underlying server response.reactor.core.publisher.Mono<Void>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 to consume the response body.protected reactor.core.publisher.Mono<Void>writeAndFlushWithInternal(Publisher<? extends Publisher<? extends DataBuffer>> body) Write to the underlying the response, and flush after eachPublisher<DataBuffer>.protected reactor.core.publisher.Mono<Void>writeWithInternal(Publisher<? extends DataBuffer> body) Write to the underlying the response.Methods inherited from class org.springframework.http.server.reactive.AbstractServerHttpResponseaddCookie, beforeCommit, bufferFactory, doCommit, doCommit, getCookies, getHeaders, getRawStatusCode, getStatusCode, isCommitted, setRawStatusCode, setStatusCode, touchDataBuffer, writeAndFlushWith, writeWith
- 
Constructor Details- 
MockServerHttpResponsepublic MockServerHttpResponse()
- 
MockServerHttpResponse
 
- 
- 
Method Details- 
setWriteHandlerpublic 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. - Parameters:
- writeHandler- the write handler to use returning- Mono<Void>when the body has been "written" (i.e. consumed).
 
- 
getNativeResponsepublic <T> T getNativeResponse()Description copied from class:AbstractServerHttpResponseReturn the underlying server response.Note: This is exposed mainly for internal framework use such as WebSocket upgrades in the spring-webflux module. - Specified by:
- getNativeResponsein class- AbstractServerHttpResponse
 
- 
applyStatusCodeprotected void applyStatusCode()Description copied from class:AbstractServerHttpResponseWrite the status code to the underlying response. This method is called once only.- Specified by:
- applyStatusCodein class- AbstractServerHttpResponse
 
- 
applyHeadersprotected void applyHeaders()Description copied from class:AbstractServerHttpResponseInvoked 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 HttpHeadersinstance 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.- Specified by:
- applyHeadersin class- AbstractServerHttpResponse
 
- 
applyCookiesprotected void applyCookies()Description copied from class:AbstractServerHttpResponseAdd cookies fromAbstractServerHttpResponse.getHeaders()to the underlying response. This method is called once only.- Specified by:
- applyCookiesin class- AbstractServerHttpResponse
 
- 
writeWithInternalDescription copied from class:AbstractServerHttpResponseWrite to the underlying the response.- Specified by:
- writeWithInternalin class- AbstractServerHttpResponse
- Parameters:
- body- the publisher to write with
 
- 
writeAndFlushWithInternalprotected reactor.core.publisher.Mono<Void> writeAndFlushWithInternal(Publisher<? extends Publisher<? extends DataBuffer>> body) Description copied from class:AbstractServerHttpResponseWrite to the underlying the response, and flush after eachPublisher<DataBuffer>.- Specified by:
- writeAndFlushWithInternalin class- AbstractServerHttpResponse
- Parameters:
- body- the publisher to write and flush with
 
- 
setCompleteDescription copied from interface: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. - Specified by:
- setCompletein interface- ReactiveHttpOutputMessage
- Overrides:
- setCompletein class- AbstractServerHttpResponse
- Returns:
- a Monothat indicates completion or error
 
- 
getBodyReturn the response body or an error stream if the body was not set.
- 
getBodyAsStringAggregate response data and convert to a String using the "Content-Type" charset or "UTF-8" by default.
 
-