public class MockServerHttpResponse extends AbstractServerHttpResponse
ServerHttpResponse
.Modifier and Type | Field and Description |
---|---|
private <any> |
body |
private java.util.function.Function<<any>,<any>> |
writeHandler |
Constructor and Description |
---|
MockServerHttpResponse() |
Modifier and Type | Method and Description |
---|---|
protected void |
applyCookies()
Implement this method to add cookies from
AbstractServerHttpResponse.getHeaders() to the
underlying response. |
protected void |
applyHeaders()
Implement this method to apply header changes from
AbstractServerHttpResponse.getHeaders()
to the underlying response. |
protected void |
applyStatusCode()
Implement this method to write the status code to the underlying response.
|
private static java.lang.String |
bufferToString(DataBuffer buffer,
java.nio.charset.Charset charset) |
<any> |
getBody()
Return the request body, or an error stream if the body was never set
or when
setWriteHandler(java.util.function.Function<<any>, <any>>) is configured. |
<any> |
getBodyAsString()
Shortcut method that delegates to
getBody() and then aggregates
the data buffers and converts to a String using the charset of the
Content-Type header or falling back on "UTF-8" by default. |
private java.nio.charset.Charset |
getCharset() |
private java.util.function.Function<<any>,<any>> |
initDefaultWriteHandler() |
<any> |
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 via
HttpMessage.getHeaders() to the underlying HTTP message (if not
applied already). |
void |
setWriteHandler(java.util.function.Function<<any>,<any>> writeHandler)
Configure a custom handler for writing the request body.
|
protected <any> |
writeAndFlushWithInternal(<any> body)
Implement this method to write to the underlying the response, and flush after
each
Publisher<DataBuffer> . |
protected <any> |
writeWithInternal(<any> body)
Implement this method to write to the underlying the response.
|
beforeCommit, bufferFactory, doCommit, doCommit, encodeUrl, getCookies, getHeaders, getStatusCode, isCommitted, registerUrlEncoder, setStatusCode, writeAndFlushWith, writeWith
private <any> body
private java.util.function.Function<<any>,<any>> writeHandler
private java.util.function.Function<<any>,<any>> initDefaultWriteHandler()
public <any> getBody()
setWriteHandler(java.util.function.Function<<any>, <any>>)
is configured.public <any> getBodyAsString()
getBody()
and then aggregates
the data buffers and converts to a String using the charset of the
Content-Type header or falling back on "UTF-8" by default.private static java.lang.String bufferToString(DataBuffer buffer, java.nio.charset.Charset charset)
private java.nio.charset.Charset getCharset()
public void setWriteHandler(java.util.function.Function<<any>,<any>> writeHandler)
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 returning Mono<Void>
when the body has been "written" (i.e. consumed).protected void applyStatusCode()
AbstractServerHttpResponse
applyStatusCode
in class AbstractServerHttpResponse
protected void applyHeaders()
AbstractServerHttpResponse
AbstractServerHttpResponse.getHeaders()
to the underlying response. This method is called once only.applyHeaders
in class AbstractServerHttpResponse
protected void applyCookies()
AbstractServerHttpResponse
AbstractServerHttpResponse.getHeaders()
to the
underlying response. This method is called once only.applyCookies
in class AbstractServerHttpResponse
protected <any> writeWithInternal(<any> body)
AbstractServerHttpResponse
writeWithInternal
in class AbstractServerHttpResponse
body
- the publisher to write withprotected <any> writeAndFlushWithInternal(<any> body)
AbstractServerHttpResponse
Publisher<DataBuffer>
.writeAndFlushWithInternal
in class AbstractServerHttpResponse
body
- the publisher to write and flush withpublic <any> setComplete()
ReactiveHttpOutputMessage
HttpMessage.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
in interface ReactiveHttpOutputMessage
setComplete
in class AbstractServerHttpResponse
Mono
that indicates completion or error