class DefaultServerResponseBuilder extends java.lang.Object implements ServerResponse.BodyBuilder
ServerResponse.BodyBuilder
implementation.Modifier and Type | Class and Description |
---|---|
(package private) static class |
DefaultServerResponseBuilder.AbstractServerResponse
Abstract base class for
ServerResponse implementations. |
private static class |
DefaultServerResponseBuilder.BodyInserterResponse<T> |
private static class |
DefaultServerResponseBuilder.WriterFunctionResponse |
Modifier and Type | Field and Description |
---|---|
private MultiValueMap<java.lang.String,ResponseCookie> |
cookies |
private HttpHeaders |
headers |
private java.util.Map<java.lang.String,java.lang.Object> |
hints |
private int |
statusCode |
Constructor and Description |
---|
DefaultServerResponseBuilder(HttpStatus status) |
DefaultServerResponseBuilder(int statusCode) |
DefaultServerResponseBuilder(ServerResponse other) |
Modifier and Type | Method and Description |
---|---|
ServerResponse.BodyBuilder |
allow(HttpMethod... allowedMethods)
Set the set of allowed
HTTP methods , as specified
by the Allow header. |
ServerResponse.BodyBuilder |
allow(java.util.Set<HttpMethod> allowedMethods)
Set the set of allowed
HTTP methods , as specified
by the Allow header. |
<any> |
body(BodyInserter<?,? super ServerHttpResponse> inserter)
Set the body of the response to the given
BodyInserter and return it. |
<T,P extends <any>> |
body(P publisher,
java.lang.Class<T> elementClass)
Set the body of the response to the given asynchronous
Publisher and return it. |
<T,P extends <any>> |
body(P publisher,
ParameterizedTypeReference<T> typeReference)
Set the body of the response to the given asynchronous
Publisher and return it. |
<any> |
build()
Build the response entity with no body.
|
<any> |
build(<any> voidPublisher)
Build the response entity with no body.
|
<any> |
build(java.util.function.BiFunction<ServerWebExchange,ServerResponse.Context,<any>> writeFunction)
Build the response entity with no body.
|
ServerResponse.BodyBuilder |
cacheControl(CacheControl cacheControl)
Set the caching directives for the resource, as specified by the HTTP 1.1
Cache-Control header. |
ServerResponse.BodyBuilder |
contentLength(long contentLength)
Set the length of the body in bytes, as specified by the
Content-Length header. |
ServerResponse.BodyBuilder |
contentType(MediaType contentType)
Set the media type of the body, as specified by the
Content-Type header. |
ServerResponse.BodyBuilder |
cookie(ResponseCookie cookie)
Add the given cookie to the response.
|
ServerResponse.BodyBuilder |
cookies(java.util.function.Consumer<MultiValueMap<java.lang.String,ResponseCookie>> cookiesConsumer)
Manipulate this response's cookies with the given consumer.
|
ServerResponse.BodyBuilder |
eTag(java.lang.String etag)
Set the entity tag of the body, as specified by the
ETag header. |
ServerResponse.BodyBuilder |
header(java.lang.String headerName,
java.lang.String... headerValues)
Add the given header value(s) under the given name.
|
ServerResponse.BodyBuilder |
headers(java.util.function.Consumer<HttpHeaders> headersConsumer)
Manipulate this response's headers with the given consumer.
|
ServerResponse.BodyBuilder |
hint(java.lang.String key,
java.lang.Object value)
Add a serialization hint like
Jackson2CodecSupport.JSON_VIEW_HINT
to customize how the body will be serialized. |
ServerResponse.BodyBuilder |
hints(java.util.function.Consumer<java.util.Map<java.lang.String,java.lang.Object>> hintsConsumer)
Customize the serialization hints with the given consumer.
|
ServerResponse.BodyBuilder |
lastModified(java.time.Instant lastModified)
Set the time the resource was last changed, as specified by the
Last-Modified header. |
ServerResponse.BodyBuilder |
lastModified(java.time.ZonedDateTime lastModified)
Set the time the resource was last changed, as specified by the
Last-Modified header. |
ServerResponse.BodyBuilder |
location(java.net.URI location)
Set the location of a resource, as specified by the
Location header. |
<any> |
render(java.lang.String name,
java.util.Map<java.lang.String,?> model)
Render the template with the given
name using the given model . |
<any> |
render(java.lang.String name,
java.lang.Object... modelAttributes)
Render the template with the given
name using the given modelAttributes . |
<any> |
syncBody(java.lang.Object body)
Set the body of the response to the given synchronous
Object and return it. |
ServerResponse.BodyBuilder |
varyBy(java.lang.String... requestHeaders)
Configure one or more request header names (e.g.
|
private final int statusCode
private final HttpHeaders headers
private final MultiValueMap<java.lang.String,ResponseCookie> cookies
private final java.util.Map<java.lang.String,java.lang.Object> hints
public DefaultServerResponseBuilder(ServerResponse other)
public DefaultServerResponseBuilder(HttpStatus status)
public DefaultServerResponseBuilder(int statusCode)
public ServerResponse.BodyBuilder header(java.lang.String headerName, java.lang.String... headerValues)
ServerResponse.HeadersBuilder
header
in interface ServerResponse.HeadersBuilder<ServerResponse.BodyBuilder>
headerName
- the header nameheaderValues
- the header value(s)HttpHeaders.add(String, String)
public ServerResponse.BodyBuilder headers(java.util.function.Consumer<HttpHeaders> headersConsumer)
ServerResponse.HeadersBuilder
HttpHeaders
methods.headers
in interface ServerResponse.HeadersBuilder<ServerResponse.BodyBuilder>
headersConsumer
- a function that consumes the HttpHeaders
public ServerResponse.BodyBuilder cookie(ResponseCookie cookie)
ServerResponse.HeadersBuilder
cookie
in interface ServerResponse.HeadersBuilder<ServerResponse.BodyBuilder>
cookie
- the cookie to addpublic ServerResponse.BodyBuilder cookies(java.util.function.Consumer<MultiValueMap<java.lang.String,ResponseCookie>> cookiesConsumer)
ServerResponse.HeadersBuilder
MultiValueMap
methods.cookies
in interface ServerResponse.HeadersBuilder<ServerResponse.BodyBuilder>
cookiesConsumer
- a function that consumes the cookiespublic ServerResponse.BodyBuilder allow(HttpMethod... allowedMethods)
ServerResponse.HeadersBuilder
HTTP methods
, as specified
by the Allow
header.allow
in interface ServerResponse.HeadersBuilder<ServerResponse.BodyBuilder>
allowedMethods
- the allowed methodsHttpHeaders.setAllow(Set)
public ServerResponse.BodyBuilder allow(java.util.Set<HttpMethod> allowedMethods)
ServerResponse.HeadersBuilder
HTTP methods
, as specified
by the Allow
header.allow
in interface ServerResponse.HeadersBuilder<ServerResponse.BodyBuilder>
allowedMethods
- the allowed methodsHttpHeaders.setAllow(Set)
public ServerResponse.BodyBuilder contentLength(long contentLength)
ServerResponse.BodyBuilder
Content-Length
header.contentLength
in interface ServerResponse.BodyBuilder
contentLength
- the content lengthHttpHeaders.setContentLength(long)
public ServerResponse.BodyBuilder contentType(MediaType contentType)
ServerResponse.BodyBuilder
Content-Type
header.contentType
in interface ServerResponse.BodyBuilder
contentType
- the content typeHttpHeaders.setContentType(MediaType)
public ServerResponse.BodyBuilder eTag(java.lang.String etag)
ServerResponse.HeadersBuilder
ETag
header.eTag
in interface ServerResponse.HeadersBuilder<ServerResponse.BodyBuilder>
etag
- the new entity tagHttpHeaders.setETag(String)
public ServerResponse.BodyBuilder hint(java.lang.String key, java.lang.Object value)
ServerResponse.BodyBuilder
Jackson2CodecSupport.JSON_VIEW_HINT
to customize how the body will be serialized.hint
in interface ServerResponse.BodyBuilder
key
- the hint keyvalue
- the hint valuepublic ServerResponse.BodyBuilder hints(java.util.function.Consumer<java.util.Map<java.lang.String,java.lang.Object>> hintsConsumer)
ServerResponse.BodyBuilder
hints
in interface ServerResponse.BodyBuilder
hintsConsumer
- a function that consumes the hintspublic ServerResponse.BodyBuilder lastModified(java.time.ZonedDateTime lastModified)
ServerResponse.HeadersBuilder
Last-Modified
header.lastModified
in interface ServerResponse.HeadersBuilder<ServerResponse.BodyBuilder>
lastModified
- the last modified dateHttpHeaders.setLastModified(long)
public ServerResponse.BodyBuilder lastModified(java.time.Instant lastModified)
ServerResponse.HeadersBuilder
Last-Modified
header.lastModified
in interface ServerResponse.HeadersBuilder<ServerResponse.BodyBuilder>
lastModified
- the last modified dateHttpHeaders.setLastModified(long)
public ServerResponse.BodyBuilder location(java.net.URI location)
ServerResponse.HeadersBuilder
Location
header.location
in interface ServerResponse.HeadersBuilder<ServerResponse.BodyBuilder>
location
- the locationHttpHeaders.setLocation(URI)
public ServerResponse.BodyBuilder cacheControl(CacheControl cacheControl)
ServerResponse.HeadersBuilder
Cache-Control
header.
A CacheControl
instance can be built like
CacheControl.maxAge(3600).cachePublic().noTransform()
.
cacheControl
in interface ServerResponse.HeadersBuilder<ServerResponse.BodyBuilder>
cacheControl
- a builder for cache-related HTTP response headerspublic ServerResponse.BodyBuilder varyBy(java.lang.String... requestHeaders)
ServerResponse.HeadersBuilder
varyBy
in interface ServerResponse.HeadersBuilder<ServerResponse.BodyBuilder>
requestHeaders
- request header namespublic <any> build()
ServerResponse.HeadersBuilder
build
in interface ServerResponse.HeadersBuilder<ServerResponse.BodyBuilder>
public <any> build(<any> voidPublisher)
ServerResponse.HeadersBuilder
voidPublisher
completes.build
in interface ServerResponse.HeadersBuilder<ServerResponse.BodyBuilder>
voidPublisher
- publisher publisher to indicate when the response should be committedpublic <any> build(java.util.function.BiFunction<ServerWebExchange,ServerResponse.Context,<any>> writeFunction)
ServerResponse.HeadersBuilder
voidPublisher
completes.build
in interface ServerResponse.HeadersBuilder<ServerResponse.BodyBuilder>
writeFunction
- publisher publisher to indicate when the response should be committedpublic <T,P extends <any>> <any> body(P publisher, java.lang.Class<T> elementClass)
ServerResponse.BodyBuilder
Publisher
and return it.
This convenience method combines ServerResponse.BodyBuilder.body(BodyInserter)
and
BodyInserters#fromPublisher(Publisher, Class)
.body
in interface ServerResponse.BodyBuilder
T
- the type of the elements contained in the publisherP
- the type of the Publisher
publisher
- the Publisher
to write to the responseelementClass
- the class of elements contained in the publisherpublic <T,P extends <any>> <any> body(P publisher, ParameterizedTypeReference<T> typeReference)
ServerResponse.BodyBuilder
Publisher
and return it.
This convenience method combines ServerResponse.BodyBuilder.body(BodyInserter)
and
BodyInserters#fromPublisher(Publisher, Class)
.body
in interface ServerResponse.BodyBuilder
T
- the type of the elements contained in the publisherP
- the type of the Publisher
publisher
- the Publisher
to write to the responsetypeReference
- a type reference describing the elements contained in the publisherpublic <any> syncBody(java.lang.Object body)
ServerResponse.BodyBuilder
Object
and return it.
This convenience method combines ServerResponse.BodyBuilder.body(BodyInserter)
and
BodyInserters.fromObject(Object)
.syncBody
in interface ServerResponse.BodyBuilder
body
- the body of the responsepublic <any> body(BodyInserter<?,? super ServerHttpResponse> inserter)
ServerResponse.BodyBuilder
BodyInserter
and return it.body
in interface ServerResponse.BodyBuilder
inserter
- the BodyInserter
that writes to the responsepublic <any> render(java.lang.String name, java.lang.Object... modelAttributes)
ServerResponse.BodyBuilder
name
using the given modelAttributes
.
The model attributes are mapped under a
generated name.
Note: Empty Collections
are not added to
the model when using this method because we cannot correctly determine
the true convention name.
render
in interface ServerResponse.BodyBuilder
name
- the name of the template to be renderedmodelAttributes
- the modelAttributes used to render the templatepublic <any> render(java.lang.String name, java.util.Map<java.lang.String,?> model)
ServerResponse.BodyBuilder
name
using the given model
.render
in interface ServerResponse.BodyBuilder
name
- the name of the template to be renderedmodel
- the model used to render the template