Top Description Inners Methods
org.springframework.web.reactive.function.server

public Interface EntityResponse<T>

extends ServerResponse
Known Direct Implementers
org.springframework.web.reactive.function.server.DefaultEntityResponseBuilder.DefaultEntityResponse
Type Parameters
<T>
the entity type
Imports
java.net.URI, java.time.Instant, .ZonedDateTime, java.util.Map, .Set, java.util.function.Consumer, org.reactivestreams.Publisher, reactor.core.publisher.Mono, org.springframework.core.ParameterizedTypeReference, org.springframework.http.CacheControl, .HttpHeaders, .HttpMethod, .HttpStatusCode, .MediaType, .ResponseCookie, org.springframework.http.codec.json.Jackson2CodecSupport, org.springframework.http.server.reactive.ServerHttpResponse, org.springframework.util.MultiValueMap, org.springframework.web.reactive.function.BodyInserter, .BodyInserters

Entity-specific subtype of ServerResponse that exposes entity data.
Authors
Arjen Poutsma, Juergen Hoeller
Since
5.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
EntityResponse.Builder<
a self reference to the builder type
T
>

Defines a builder for EntityResponse.

Method Summary

Modifier and TypeMethod and Description
public T
entity()

Return the entity that makes up this response.

public static <
the type of the body
T
>
EntityResponse.Builder<T>

Returns:

the created builder
fromObject
(T
the object that represents the body of the response
body
)

Create a builder with the given object.

public static <T> EntityResponse.Builder<T>

Returns:

the created builder
fromProducer
(T
the producer that represents the body of the response
producer
,
Class<?>
the class of elements contained in the publisher
elementClass
)

Create a builder with the given producer.

public static <T> EntityResponse.Builder<T>

Returns:

the created builder
fromProducer
(T
the producer that represents the body of the response
producer
,
ParameterizedTypeReference<?>
the type of elements contained in the producer
typeReference
)

Create a builder with the given producer.

public static <
the type of the elements contained in the publisher
T
,
the type of the Publisher
P extends Publisher<T>
>
EntityResponse.Builder<P>

Returns:

the created builder
fromPublisher
(P
the publisher that represents the body of the response
publisher
,
Class<T>
the class of elements contained in the publisher
elementClass
)

Create a builder with the given publisher.

public static <
the type of the elements contained in the publisher
T
,
the type of the Publisher
P extends Publisher<T>
>
EntityResponse.Builder<P>

Returns:

the created builder
fromPublisher
(P
the publisher that represents the body of the response
publisher
,
ParameterizedTypeReference<T>
the type of elements contained in the publisher
typeReference
)

Create a builder with the given publisher.

public BodyInserter<T, ? super ServerHttpResponse>
inserter()

Return the BodyInserter that writes the entity to the output stream.

Inherited from org.springframework.web.reactive.function.server.ServerResponse:
acceptedbadRequestcookiescreatedfromfromheadersnoContentnotFoundokpermanentRedirectrawStatusCodeseeOtherstatusstatusstatusCodetemporaryRedirectunprocessableEntitywriteTo

Method Detail

entityback to summary
public T entity()

Return the entity that makes up this response.

fromObjectback to summary
public static <T> EntityResponse.Builder<T> fromObject(T body)

Create a builder with the given object.

Parameters
<T>
the type of the body
body:T

the object that represents the body of the response

Returns:EntityResponse.Builder<T>

the created builder

fromProducerback to summary
public static <T> EntityResponse.Builder<T> fromProducer(T producer, Class<?> elementClass)

Create a builder with the given producer.

Parameters
producer:T

the producer that represents the body of the response

elementClass:Class<?>

the class of elements contained in the publisher

Returns:EntityResponse.Builder<T>

the created builder

Since
5.2
fromProducerback to summary
public static <T> EntityResponse.Builder<T> fromProducer(T producer, ParameterizedTypeReference<?> typeReference)

Create a builder with the given producer.

Parameters
producer:T

the producer that represents the body of the response

typeReference:ParameterizedTypeReference<?>

the type of elements contained in the producer

Returns:EntityResponse.Builder<T>

the created builder

Since
5.2
fromPublisherback to summary
public static <T, P extends Publisher<T>> EntityResponse.Builder<P> fromPublisher(P publisher, Class<T> elementClass)

Create a builder with the given publisher.

Parameters
<T>
the type of the elements contained in the publisher
<P>
the type of the Publisher
publisher:P

the publisher that represents the body of the response

elementClass:Class<T>

the class of elements contained in the publisher

Returns:EntityResponse.Builder<P>

the created builder

fromPublisherback to summary
public static <T, P extends Publisher<T>> EntityResponse.Builder<P> fromPublisher(P publisher, ParameterizedTypeReference<T> typeReference)

Create a builder with the given publisher.

Parameters
<T>
the type of the elements contained in the publisher
<P>
the type of the Publisher
publisher:P

the publisher that represents the body of the response

typeReference:ParameterizedTypeReference<T>

the type of elements contained in the publisher

Returns:EntityResponse.Builder<P>

the created builder

inserterback to summary
public BodyInserter<T, ? super ServerHttpResponse> inserter()

Return the BodyInserter that writes the entity to the output stream.

org.springframework.web.reactive.function.server back to summary

public Interface EntityResponse.Builder<T>

Known Direct Implementers
org.springframework.web.reactive.function.server.DefaultEntityResponseBuilder
Type Parameters
<T>
a self reference to the builder type

Defines a builder for EntityResponse.

Method Summary

Modifier and TypeMethod and Description
public EntityResponse.Builder<T>

Returns:

this builder
allow
(HttpMethod...
the allowed methods
allowedMethods
)

Set the set of allowed HTTP methods, as specified by the Allow header.

public EntityResponse.Builder<T>

Returns:

this builder
allow
(Set<HttpMethod>
the allowed methods
allowedMethods
)

Set the set of allowed HTTP methods, as specified by the Allow header.

public Mono<EntityResponse<T>>

Returns:

the built response
build
()

Build the response.

public EntityResponse.Builder<T>

Returns:

this builder
cacheControl
(CacheControl
a builder for cache-related HTTP response headers
cacheControl
)

Set the caching directives for the resource, as specified by the HTTP 1.1 Cache-Control header.

public EntityResponse.Builder<T>

Returns:

this builder
contentLength
(long
the content length
contentLength
)

Set the length of the body in bytes, as specified by the Content-Length header.

public EntityResponse.Builder<T>

Returns:

this builder
contentType
(MediaType
the content type
contentType
)

Set the media type of the body, as specified by the Content-Type header.

public EntityResponse.Builder<T>

Returns:

this builder
cookie
(ResponseCookie
the cookie to add
cookie
)

Add the given cookie to the response.

public EntityResponse.Builder<T>

Returns:

this builder
cookies
(Consumer<MultiValueMap<String, ResponseCookie>>
a function that consumes the cookies
cookiesConsumer
)

Manipulate this response's cookies with the given consumer.

public EntityResponse.Builder<T>

Returns:

this builder
eTag
(String
the new entity tag
etag
)

Set the entity tag of the body, as specified by the ETag header.

public EntityResponse.Builder<T>

Returns:

this builder
header
(String
the header name
headerName
,
String...
the header value(s)
headerValues
)

Add the given header value(s) under the given name.

public EntityResponse.Builder<T>

Returns:

this builder
headers
(HttpHeaders
the existing HttpHeaders to copy from
headers
)

Copy the given headers into the entity's headers map.

public EntityResponse.Builder<T>

Returns:

this builder
headers
(Consumer<HttpHeaders>
a function that consumes the HttpHeaders
headersConsumer
)

Manipulate this entity's headers with the given consumer.

public EntityResponse.Builder<T>
hint(String
the hint key
key
,
Object
the hint value
value
)

Add a serialization hint like Jackson2CodecSupport#JSON_VIEW_HINT to customize how the body will be serialized.

public EntityResponse.Builder<T>

Returns:

this builder
hints
(Consumer<Map<String, Object>>
a function that consumes the hints
hintsConsumer
)

Customize the serialization hints with the given consumer.

public EntityResponse.Builder<T>

Returns:

this builder
lastModified
(ZonedDateTime
the last modified date
lastModified
)

Set the time the resource was last changed, as specified by the Last-Modified header.

public EntityResponse.Builder<T>

Returns:

this builder
lastModified
(Instant
the last modified date
lastModified
)

Set the time the resource was last changed, as specified by the Last-Modified header.

public EntityResponse.Builder<T>

Returns:

this builder
location
(URI
the location
location
)

Set the location of a resource, as specified by the Location header.

public EntityResponse.Builder<T>

Returns:

this builder
status
(HttpStatusCode
the response status
status
)

Set the HTTP status.

public EntityResponse.Builder<T>

Returns:

this builder
status
(int
the response status
status
)

Set the HTTP status.

public EntityResponse.Builder<T>

Returns:

this builder
varyBy
(String...
request header names
requestHeaders
)

Configure one or more request header names (e.g. "Accept-Language") to add to the "Vary" response header to inform clients that the response is subject to content negotiation and variances based on the value of the given request headers.

Method Detail

allowback to summary
public EntityResponse.Builder<T> allow(HttpMethod... allowedMethods)

Set the set of allowed HTTP methods, as specified by the Allow header.

Parameters
allowedMethods:HttpMethod[]

the allowed methods

Returns:EntityResponse.Builder<T>

this builder

See Also
HttpHeaders#setAllow(Set)
allowback to summary
public EntityResponse.Builder<T> allow(Set<HttpMethod> allowedMethods)

Set the set of allowed HTTP methods, as specified by the Allow header.

Parameters
allowedMethods:Set<HttpMethod>

the allowed methods

Returns:EntityResponse.Builder<T>

this builder

See Also
HttpHeaders#setAllow(Set)
buildback to summary
public Mono<EntityResponse<T>> build()

Build the response.

Returns:Mono<EntityResponse<T>>

the built response

cacheControlback to summary
public EntityResponse.Builder<T> cacheControl(CacheControl cacheControl)

Set the caching directives for the resource, as specified by the HTTP 1.1 Cache-Control header.

A CacheControl instance can be built like CacheControl.maxAge(3600).cachePublic().noTransform().

Parameters
cacheControl:CacheControl

a builder for cache-related HTTP response headers

Returns:EntityResponse.Builder<T>

this builder

See Also
RFC-7234 Section 5.2
contentLengthback to summary
public EntityResponse.Builder<T> contentLength(long contentLength)

Set the length of the body in bytes, as specified by the Content-Length header.

Parameters
contentLength:long

the content length

Returns:EntityResponse.Builder<T>

this builder

See Also
HttpHeaders#setContentLength(long)
contentTypeback to summary
public EntityResponse.Builder<T> contentType(MediaType contentType)

Set the media type of the body, as specified by the Content-Type header.

Parameters
contentType:MediaType

the content type

Returns:EntityResponse.Builder<T>

this builder

See Also
HttpHeaders#setContentType(MediaType)
cookieback to summary
public EntityResponse.Builder<T> cookie(ResponseCookie cookie)

Add the given cookie to the response.

Parameters
cookie:ResponseCookie

the cookie to add

Returns:EntityResponse.Builder<T>

this builder

cookiesback to summary
public EntityResponse.Builder<T> cookies(Consumer<MultiValueMap<String, ResponseCookie>> cookiesConsumer)

Manipulate this response's cookies with the given consumer. The cookies provided to the consumer are "live", so that the consumer can be used to overwrite existing cookies, remove cookies, or use any of the other MultiValueMap methods.

Parameters
cookiesConsumer:Consumer<MultiValueMap<String, ResponseCookie>>

a function that consumes the cookies

Returns:EntityResponse.Builder<T>

this builder

eTagback to summary
public EntityResponse.Builder<T> eTag(String etag)

Set the entity tag of the body, as specified by the ETag header.

Parameters
etag:String

the new entity tag

Returns:EntityResponse.Builder<T>

this builder

See Also
HttpHeaders#setETag(String)
headerback to summary
public EntityResponse.Builder<T> header(String headerName, String... headerValues)

Add the given header value(s) under the given name.

Parameters
headerName:String

the header name

headerValues:String[]

the header value(s)

Returns:EntityResponse.Builder<T>

this builder

See Also
HttpHeaders#add(String, String)
headersback to summary
public EntityResponse.Builder<T> headers(HttpHeaders headers)

Copy the given headers into the entity's headers map.

Parameters
headers:HttpHeaders

the existing HttpHeaders to copy from

Returns:EntityResponse.Builder<T>

this builder

See Also
HttpHeaders#add(String, String)
headersback to summary
public EntityResponse.Builder<T> headers(Consumer<HttpHeaders> headersConsumer)

Manipulate this entity's headers with the given consumer. The headers provided to the consumer are "live", so that the consumer can be used to overwrite existing header values, remove values, or use any of the other HttpHeaders methods.

Parameters
headersConsumer:Consumer<HttpHeaders>

a function that consumes the HttpHeaders

Returns:EntityResponse.Builder<T>

this builder

Since
6.1
hintback to summary
public EntityResponse.Builder<T> hint(String key, Object value)

Add a serialization hint like Jackson2CodecSupport#JSON_VIEW_HINT to customize how the body will be serialized.

Parameters
key:String

the hint key

value:Object

the hint value

hintsback to summary
public EntityResponse.Builder<T> hints(Consumer<Map<String, Object>> hintsConsumer)

Customize the serialization hints with the given consumer.

Parameters
hintsConsumer:Consumer<Map<String, Object>>

a function that consumes the hints

Returns:EntityResponse.Builder<T>

this builder

Since
5.1.6
lastModifiedback to summary
public EntityResponse.Builder<T> lastModified(ZonedDateTime lastModified)

Set the time the resource was last changed, as specified by the Last-Modified header.

The date should be specified as the number of milliseconds since January 1, 1970 GMT.

Parameters
lastModified:ZonedDateTime

the last modified date

Returns:EntityResponse.Builder<T>

this builder

See Also
HttpHeaders#setLastModified(long)
lastModifiedback to summary
public EntityResponse.Builder<T> lastModified(Instant lastModified)

Set the time the resource was last changed, as specified by the Last-Modified header.

The date should be specified as the number of milliseconds since January 1, 1970 GMT.

Parameters
lastModified:Instant

the last modified date

Returns:EntityResponse.Builder<T>

this builder

Since
5.1.4
See Also
HttpHeaders#setLastModified(long)
locationback to summary
public EntityResponse.Builder<T> location(URI location)

Set the location of a resource, as specified by the Location header.

Parameters
location:URI

the location

Returns:EntityResponse.Builder<T>

this builder

See Also
HttpHeaders#setLocation(URI)
statusback to summary
public EntityResponse.Builder<T> status(HttpStatusCode status)

Set the HTTP status.

Parameters
status:HttpStatusCode

the response status

Returns:EntityResponse.Builder<T>

this builder

statusback to summary
public EntityResponse.Builder<T> status(int status)

Set the HTTP status.

Parameters
status:int

the response status

Returns:EntityResponse.Builder<T>

this builder

Since
5.0.3
varyByback to summary
public EntityResponse.Builder<T> varyBy(String... requestHeaders)

Configure one or more request header names (e.g. "Accept-Language") to add to the "Vary" response header to inform clients that the response is subject to content negotiation and variances based on the value of the given request headers. The configured request header names are added only if not already present in the response "Vary" header.

Parameters
requestHeaders:String[]

request header names

Returns:EntityResponse.Builder<T>

this builder