T
- the entity typefinal class DefaultEntityResponseBuilder<T> extends java.lang.Object implements EntityResponse.Builder<T>
EntityResponse.Builder
implementation.Modifier and Type | Class and Description |
---|---|
private static class |
DefaultEntityResponseBuilder.CompletionStageEntityResponse<T>
EntityResponse implementation for asynchronous CompletionStage bodies. |
private static class |
DefaultEntityResponseBuilder.DefaultEntityResponse<T>
Default
EntityResponse implementation for synchronous bodies. |
private static class |
DefaultEntityResponseBuilder.PublisherEntityResponse<T> |
Modifier and Type | Field and Description |
---|---|
private MultiValueMap<java.lang.String,Cookie> |
cookies |
private T |
entity |
private java.lang.reflect.Type |
entityType |
private HttpHeaders |
headers |
private static boolean |
reactiveStreamsPresent |
private int |
status |
Modifier | Constructor and Description |
---|---|
private |
DefaultEntityResponseBuilder(T entity,
java.lang.reflect.Type entityType) |
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. |
EntityResponse<T> |
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(Cookie cookie)
Add the given cookie to the response.
|
EntityResponse.Builder<T> |
cookies(java.util.function.Consumer<MultiValueMap<java.lang.String,Cookie>> 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. |
static <T> EntityResponse.Builder<T> |
fromObject(T t)
Return a new
EntityResponse.Builder from the given object. |
static <T> EntityResponse.Builder<T> |
fromObject(T t,
ParameterizedTypeReference<?> bodyType)
Return a new
EntityResponse.Builder from the given object and type reference. |
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(java.util.function.Consumer<HttpHeaders> headersConsumer)
Manipulate this response's headers 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 static final boolean reactiveStreamsPresent
private final T entity
private final java.lang.reflect.Type entityType
private int status
private final HttpHeaders headers
private final MultiValueMap<java.lang.String,Cookie> cookies
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(Cookie 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,Cookie>> 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(java.util.function.Consumer<HttpHeaders> headersConsumer)
EntityResponse.Builder
HttpHeaders
methods.headers
in interface EntityResponse.Builder<T>
headersConsumer
- a function that consumes the HttpHeaders
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> 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 EntityResponse<T> build()
EntityResponse.Builder
build
in interface EntityResponse.Builder<T>
public static <T> EntityResponse.Builder<T> fromObject(T t)
EntityResponse.Builder
from the given object.public static <T> EntityResponse.Builder<T> fromObject(T t, ParameterizedTypeReference<?> bodyType)
EntityResponse.Builder
from the given object and type reference.