T
- a self reference to the builder typeclass DefaultEntityResponseBuilder<T> extends java.lang.Object implements EntityResponse.Builder<T>
EntityResponse.Builder
implementation.Modifier and Type | Class and Description |
---|---|
private static class |
DefaultEntityResponseBuilder.DefaultEntityResponse<T> |
Modifier and Type | Field and Description |
---|---|
private MultiValueMap<java.lang.String,ResponseCookie> |
cookies |
private T |
entity |
private HttpHeaders |
headers |
private java.util.Map<java.lang.String,java.lang.Object> |
hints |
private BodyInserter<T,? super ServerHttpResponse> |
inserter |
private int |
status |
Constructor and Description |
---|
DefaultEntityResponseBuilder(T entity,
BodyInserter<T,? super ServerHttpResponse> inserter) |
Modifier and Type | Method and Description |
---|---|
EntityResponse.Builder<T> |
allow(HttpMethod... allowedMethods)
Set the set of allowed
HTTP methods , as specified
by the Allow header. |
EntityResponse.Builder<T> |
allow(java.util.Set<HttpMethod> allowedMethods)
Set the set of allowed
HTTP methods , as specified
by the Allow header. |
<any> |
build()
Build the response.
|
EntityResponse.Builder<T> |
cacheControl(CacheControl cacheControl)
Set the caching directives for the resource, as specified by the HTTP 1.1
Cache-Control header. |
EntityResponse.Builder<T> |
contentLength(long contentLength)
Set the length of the body in bytes, as specified by the
Content-Length header. |
EntityResponse.Builder<T> |
contentType(MediaType contentType)
Set the media type of the body, as specified by the
Content-Type header. |
EntityResponse.Builder<T> |
cookie(ResponseCookie cookie)
Add the given cookie to the response.
|
EntityResponse.Builder<T> |
cookies(java.util.function.Consumer<MultiValueMap<java.lang.String,ResponseCookie>> cookiesConsumer)
Manipulate this response's cookies with the given consumer.
|
EntityResponse.Builder<T> |
eTag(java.lang.String etag)
Set the entity tag of the body, as specified by the
ETag header. |
EntityResponse.Builder<T> |
header(java.lang.String headerName,
java.lang.String... headerValues)
Add the given header value(s) under the given name.
|
EntityResponse.Builder<T> |
headers(HttpHeaders headers)
Copy the given headers into the entity's headers map.
|
EntityResponse.Builder<T> |
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. |
EntityResponse.Builder<T> |
hints(java.util.function.Consumer<java.util.Map<java.lang.String,java.lang.Object>> hintsConsumer)
Manipulate serialization hint with the given consumer.
|
EntityResponse.Builder<T> |
lastModified(java.time.Instant lastModified)
Set the time the resource was last changed, as specified by the
Last-Modified header. |
EntityResponse.Builder<T> |
lastModified(java.time.ZonedDateTime lastModified)
Set the time the resource was last changed, as specified by the
Last-Modified header. |
EntityResponse.Builder<T> |
location(java.net.URI location)
Set the location of a resource, as specified by the
Location header. |
EntityResponse.Builder<T> |
status(HttpStatus status)
Set the HTTP status.
|
EntityResponse.Builder<T> |
status(int status)
Set the HTTP status.
|
EntityResponse.Builder<T> |
varyBy(java.lang.String... requestHeaders)
Configure one or more request header names (e.g.
|
private final T entity
private final BodyInserter<T,? super ServerHttpResponse> inserter
private int status
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 DefaultEntityResponseBuilder(T entity, BodyInserter<T,? super ServerHttpResponse> inserter)
public EntityResponse.Builder<T> status(HttpStatus status)
EntityResponse.Builder
status
in interface EntityResponse.Builder<T>
status
- the response statuspublic EntityResponse.Builder<T> status(int status)
EntityResponse.Builder
status
in interface EntityResponse.Builder<T>
status
- the response statuspublic EntityResponse.Builder<T> cookie(ResponseCookie cookie)
EntityResponse.Builder
cookie
in interface EntityResponse.Builder<T>
cookie
- the cookie to addpublic EntityResponse.Builder<T> cookies(java.util.function.Consumer<MultiValueMap<java.lang.String,ResponseCookie>> cookiesConsumer)
EntityResponse.Builder
MultiValueMap
methods.cookies
in interface EntityResponse.Builder<T>
cookiesConsumer
- a function that consumes the cookiespublic EntityResponse.Builder<T> header(java.lang.String headerName, java.lang.String... headerValues)
EntityResponse.Builder
header
in interface EntityResponse.Builder<T>
headerName
- the header nameheaderValues
- the header value(s)HttpHeaders.add(String, String)
public EntityResponse.Builder<T> headers(HttpHeaders headers)
EntityResponse.Builder
headers
in interface EntityResponse.Builder<T>
headers
- the existing HttpHeaders to copy fromHttpHeaders.add(String, String)
public EntityResponse.Builder<T> allow(HttpMethod... allowedMethods)
EntityResponse.Builder
HTTP methods
, as specified
by the Allow
header.allow
in interface EntityResponse.Builder<T>
allowedMethods
- the allowed methodsHttpHeaders.setAllow(Set)
public EntityResponse.Builder<T> allow(java.util.Set<HttpMethod> allowedMethods)
EntityResponse.Builder
HTTP methods
, as specified
by the Allow
header.allow
in interface EntityResponse.Builder<T>
allowedMethods
- the allowed methodsHttpHeaders.setAllow(Set)
public EntityResponse.Builder<T> contentLength(long contentLength)
EntityResponse.Builder
Content-Length
header.contentLength
in interface EntityResponse.Builder<T>
contentLength
- the content lengthHttpHeaders.setContentLength(long)
public EntityResponse.Builder<T> contentType(MediaType contentType)
EntityResponse.Builder
Content-Type
header.contentType
in interface EntityResponse.Builder<T>
contentType
- the content typeHttpHeaders.setContentType(MediaType)
public EntityResponse.Builder<T> eTag(java.lang.String etag)
EntityResponse.Builder
ETag
header.eTag
in interface EntityResponse.Builder<T>
etag
- the new entity tagHttpHeaders.setETag(String)
public EntityResponse.Builder<T> hint(java.lang.String key, java.lang.Object value)
EntityResponse.Builder
Jackson2CodecSupport.JSON_VIEW_HINT
to
customize how the body will be serialized.hint
in interface EntityResponse.Builder<T>
key
- the hint keyvalue
- the hint valuepublic EntityResponse.Builder<T> hints(java.util.function.Consumer<java.util.Map<java.lang.String,java.lang.Object>> hintsConsumer)
EntityResponse.Builder
hints
in interface EntityResponse.Builder<T>
hintsConsumer
- a function that consumes the hintspublic EntityResponse.Builder<T> lastModified(java.time.ZonedDateTime lastModified)
EntityResponse.Builder
Last-Modified
header.
The date should be specified as the number of milliseconds since January 1, 1970 GMT.
lastModified
in interface EntityResponse.Builder<T>
lastModified
- the last modified dateHttpHeaders.setLastModified(long)
public EntityResponse.Builder<T> lastModified(java.time.Instant lastModified)
EntityResponse.Builder
Last-Modified
header.
The date should be specified as the number of milliseconds since January 1, 1970 GMT.
lastModified
in interface EntityResponse.Builder<T>
lastModified
- the last modified dateHttpHeaders.setLastModified(long)
public EntityResponse.Builder<T> location(java.net.URI location)
EntityResponse.Builder
Location
header.location
in interface EntityResponse.Builder<T>
location
- the locationHttpHeaders.setLocation(URI)
public EntityResponse.Builder<T> cacheControl(CacheControl cacheControl)
EntityResponse.Builder
Cache-Control
header.
A CacheControl
instance can be built like
CacheControl.maxAge(3600).cachePublic().noTransform()
.
cacheControl
in interface EntityResponse.Builder<T>
cacheControl
- a builder for cache-related HTTP response headerspublic EntityResponse.Builder<T> varyBy(java.lang.String... requestHeaders)
EntityResponse.Builder
varyBy
in interface EntityResponse.Builder<T>
requestHeaders
- request header namespublic <any> build()
EntityResponse.Builder
build
in interface EntityResponse.Builder<T>