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

public Interface ClientResponse

Known Direct Implementers
org.springframework.web.reactive.function.client.DefaultClientResponse, org.springframework.web.reactive.function.client.support.ClientResponseWrapper
Imports
java.util.Collections, .List, .Optional, .OptionalLong, java.util.function.Consumer, .Function, reactor.core.publisher.Flux, .Mono, org.springframework.core.ParameterizedTypeReference, org.springframework.core.io.buffer.DataBuffer, org.springframework.http.HttpHeaders, .HttpRequest, .HttpStatusCode, .MediaType, .ResponseCookie, .ResponseEntity, org.springframework.http.client.reactive.ClientHttpResponse, org.springframework.http.codec.HttpMessageReader, .HttpMessageWriter, org.springframework.util.MultiValueMap, org.springframework.web.reactive.function.BodyExtractor

Represents an HTTP response, as returned by WebClient and also ExchangeFunction. Provides access to the response status and headers, and also methods to consume the response body.
Authors
Brian Clozel, Arjen Poutsma
Since
5.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ClientResponse.Builder

Defines a builder for a response.

public static interface
ClientResponse.Headers

Represents the headers of the HTTP response.

Method Summary

Modifier and TypeMethod and Description
public <
the type of the body returned
T
>
T

Returns:

the extracted body
body
(BodyExtractor<T, ? super ClientHttpResponse>
the BodyExtractor that reads from the response
extractor
)

Extract the body with the given BodyExtractor.

public <
the element type
T
>
Flux<T>

Returns:

a flux containing the body of the given type T
bodyToFlux
(Class<? extends T>
the class of elements in the Flux
elementClass
)

Extract the body to a Flux.

public <
the element type
T
>
Flux<T>

Returns:

a flux containing the body of the given type T
bodyToFlux
(ParameterizedTypeReference<T>
the type reference of elements in the Flux
elementTypeRef
)

Extract the body to a Flux.

public <
the element type
T
>
Mono<T>

Returns:

a mono containing the body of the given type T
bodyToMono
(Class<? extends T>
the class of element in the Mono
elementClass
)

Extract the body to a Mono.

public <
the element type
T
>
Mono<T>

Returns:

a mono containing the body of the given type T
bodyToMono
(ParameterizedTypeReference<T>
the type reference of element in the Mono
elementTypeRef
)

Extract the body to a Mono.

public MultiValueMap<String, ResponseCookie>
cookies()

Return the cookies of this response.

public static ClientResponse.Builder

Returns:

the created builder
create
(HttpStatusCode
the status code
statusCode
)

Create a response builder with the given status code and using default strategies for reading the body.

public static ClientResponse.Builder

Returns:

the created builder
create
(HttpStatusCode
the status code
statusCode
,
ExchangeStrategies
the strategies
strategies
)

Create a response builder with the given status code and strategies for reading the body.

public static ClientResponse.Builder

Returns:

the created builder
create
(int
the status code
statusCode
,
ExchangeStrategies
the strategies
strategies
)

Create a response builder with the given raw status code and strategies for reading the body.

public static ClientResponse.Builder

Returns:

the created builder
create
(HttpStatusCode
the status code
statusCode
,
List<HttpMessageReader<?>>
the message readers
messageReaders
)

Create a response builder with the given status code and message body readers.

public <
the reified type
T
>
Mono<T>

Returns:

a Mono that fails with a WebClientResponseException.
createError
()

Create a Mono that terminates with a WebClientResponseException, containing the response status, headers, body, and the originating request.

public Mono<WebClientResponseException>

Returns:

a Mono with the created exception
createException
()

Create a WebClientResponseException that contains the response status, headers, body, and the originating request.

public static ClientResponse.Builder

Returns:

the created builder
from
(ClientResponse
the response to copy the status, headers, and cookies from
other
)
Deprecated as of 5.3 in favor of the instance based mutate().

Create a builder with the status, headers, and cookies of the given response.

public ClientResponse.Headers
headers()

Return the headers of this response.

public String

Returns:

the log message prefix or an empty String if the LOG_ID_ATTRIBUTE is not set
logPrefix
()

Return a log message prefix to use to correlate messages for this exchange.

public default ClientResponse.Builder

Returns:

a builder to mutate the response with
mutate
()

Return a builder to mutate this response, for example to change the status, headers, cookies, and replace or transform the body.

public Mono<Void>

Returns:

a completion signal
releaseBody
()

Release the body of this response.

public HttpRequest
request()

Return the request associated with the response.

public HttpStatusCode

Returns:

the HTTP status as an HttpStatusCode value (never null)
statusCode
()

Return the HTTP status code as an HttpStatusCode value.

public ExchangeStrategies
strategies()

Return the strategies used to convert the body of this response.

public Mono<ResponseEntity<Void>>

Returns:

Mono with the bodiless ResponseEntity
toBodilessEntity
()

Return this response as a delayed ResponseEntity containing status and headers, but no body.

public <
response body type
T
>
Mono<ResponseEntity<T>>

Returns:

Mono with the ResponseEntity
toEntity
(Class<T>
the expected response body type
bodyClass
)

Return this response as a delayed ResponseEntity.

public <
response body type
T
>
Mono<ResponseEntity<T>>

Returns:

Mono with the ResponseEntity
toEntity
(ParameterizedTypeReference<T>
a type reference describing the expected response body type
bodyTypeReference
)

Return this response as a delayed ResponseEntity.

public <
the type of elements in the list
T
>
Mono<ResponseEntity<List<T>>>

Returns:

Mono with the list of ResponseEntitys
toEntityList
(Class<T>
the expected response body list element class
elementClass
)

Return this response as a delayed list of ResponseEntitys.

public <
the type of elements in the list
T
>
Mono<ResponseEntity<List<T>>>

Returns:

Mono with the list of ResponseEntitys
toEntityList
(ParameterizedTypeReference<T>
the expected response body list element reference type
elementTypeRef
)

Return this response as a delayed list of ResponseEntitys.

Method Detail

bodyback to summary
public <T> T body(BodyExtractor<T, ? super ClientHttpResponse> extractor)

Extract the body with the given BodyExtractor.

Parameters
<T>
the type of the body returned
extractor:BodyExtractor<T, ? super ClientHttpResponse>

the BodyExtractor that reads from the response

Returns:T

the extracted body

bodyToFluxback to summary
public <T> Flux<T> bodyToFlux(Class<? extends T> elementClass)

Extract the body to a Flux.

Parameters
<T>
the element type
elementClass:Class<? extends T>

the class of elements in the Flux

Returns:Flux<T>

a flux containing the body of the given type T

bodyToFluxback to summary
public <T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> elementTypeRef)

Extract the body to a Flux.

Parameters
<T>
the element type
elementTypeRef:ParameterizedTypeReference<T>

the type reference of elements in the Flux

Returns:Flux<T>

a flux containing the body of the given type T

bodyToMonoback to summary
public <T> Mono<T> bodyToMono(Class<? extends T> elementClass)

Extract the body to a Mono.

Parameters
<T>
the element type
elementClass:Class<? extends T>

the class of element in the Mono

Returns:Mono<T>

a mono containing the body of the given type T

bodyToMonoback to summary
public <T> Mono<T> bodyToMono(ParameterizedTypeReference<T> elementTypeRef)

Extract the body to a Mono.

Parameters
<T>
the element type
elementTypeRef:ParameterizedTypeReference<T>

the type reference of element in the Mono

Returns:Mono<T>

a mono containing the body of the given type T

cookiesback to summary
public MultiValueMap<String, ResponseCookie> cookies()

Return the cookies of this response.

createback to summary
public static ClientResponse.Builder create(HttpStatusCode statusCode)

Create a response builder with the given status code and using default strategies for reading the body.

Parameters
statusCode:HttpStatusCode

the status code

Returns:ClientResponse.Builder

the created builder

createback to summary
public static ClientResponse.Builder create(HttpStatusCode statusCode, ExchangeStrategies strategies)

Create a response builder with the given status code and strategies for reading the body.

Parameters
statusCode:HttpStatusCode

the status code

strategies:ExchangeStrategies

the strategies

Returns:ClientResponse.Builder

the created builder

createback to summary
public static ClientResponse.Builder create(int statusCode, ExchangeStrategies strategies)

Create a response builder with the given raw status code and strategies for reading the body.

Parameters
statusCode:int

the status code

strategies:ExchangeStrategies

the strategies

Returns:ClientResponse.Builder

the created builder

Since
5.1.9
createback to summary
public static ClientResponse.Builder create(HttpStatusCode statusCode, List<HttpMessageReader<?>> messageReaders)

Create a response builder with the given status code and message body readers.

Parameters
statusCode:HttpStatusCode

the status code

messageReaders:List<HttpMessageReader<?>>

the message readers

Returns:ClientResponse.Builder

the created builder

createErrorback to summary
public <T> Mono<T> createError()

Create a Mono that terminates with a WebClientResponseException, containing the response status, headers, body, and the originating request.

Parameters
<T>
the reified type
Returns:Mono<T>

a Mono that fails with a WebClientResponseException.

Since
6.0
See Also
createException()
createExceptionback to summary
public Mono<WebClientResponseException> createException()

Create a WebClientResponseException that contains the response status, headers, body, and the originating request.

Returns:Mono<WebClientResponseException>

a Mono with the created exception

Since
5.2
fromback to summary
public static ClientResponse.Builder from(ClientResponse other)

Deprecated

as of 5.3 in favor of the instance based mutate().

Create a builder with the status, headers, and cookies of the given response.

Note

Note that the body in the returned builder is Flux#empty() by default. To carry over the one from the original response, use otherResponse.bodyToFlux(DataBuffer.class) or simply use the instance based mutate() method.

Parameters
other:ClientResponse

the response to copy the status, headers, and cookies from

Returns:ClientResponse.Builder

the created builder

Annotations
@Deprecated
headersback to summary
public ClientResponse.Headers headers()

Return the headers of this response.

logPrefixback to summary
public String logPrefix()

Return a log message prefix to use to correlate messages for this exchange.

The prefix is based on ClientRequest#logPrefix(), which itself is based on the value of the LOG_ID_ATTRIBUTE request attribute, further surrounded with "[" and "]".

Returns:String

the log message prefix or an empty String if the LOG_ID_ATTRIBUTE is not set

Since
5.2.3
mutateback to summary
public default ClientResponse.Builder mutate()

Return a builder to mutate this response, for example to change the status, headers, cookies, and replace or transform the body.

Returns:ClientResponse.Builder

a builder to mutate the response with

Since
5.3
releaseBodyback to summary
public Mono<Void> releaseBody()

Release the body of this response.

Returns:Mono<Void>

a completion signal

Since
5.2
See Also
org.springframework.core.io.buffer.DataBufferUtils#release(DataBuffer)
requestback to summary
public HttpRequest request()

Return the request associated with the response.

Since
6.1
statusCodeback to summary
public HttpStatusCode statusCode()

Return the HTTP status code as an HttpStatusCode value.

Returns:HttpStatusCode

the HTTP status as an HttpStatusCode value (never null)

strategiesback to summary
public ExchangeStrategies strategies()

Return the strategies used to convert the body of this response.

toBodilessEntityback to summary
public Mono<ResponseEntity<Void>> toBodilessEntity()

Return this response as a delayed ResponseEntity containing status and headers, but no body. Calling this method will release the body of the response.

Returns:Mono<ResponseEntity<Void>>

Mono with the bodiless ResponseEntity

Since
5.2
toEntityback to summary
public <T> Mono<ResponseEntity<T>> toEntity(Class<T> bodyClass)

Return this response as a delayed ResponseEntity.

Parameters
<T>
response body type
bodyClass:Class<T>

the expected response body type

Returns:Mono<ResponseEntity<T>>

Mono with the ResponseEntity

toEntityback to summary
public <T> Mono<ResponseEntity<T>> toEntity(ParameterizedTypeReference<T> bodyTypeReference)

Return this response as a delayed ResponseEntity.

Parameters
<T>
response body type
bodyTypeReference:ParameterizedTypeReference<T>

a type reference describing the expected response body type

Returns:Mono<ResponseEntity<T>>

Mono with the ResponseEntity

toEntityListback to summary
public <T> Mono<ResponseEntity<List<T>>> toEntityList(Class<T> elementClass)

Return this response as a delayed list of ResponseEntitys.

Parameters
<T>
the type of elements in the list
elementClass:Class<T>

the expected response body list element class

Returns:Mono<ResponseEntity<List<T>>>

Mono with the list of ResponseEntitys

toEntityListback to summary
public <T> Mono<ResponseEntity<List<T>>> toEntityList(ParameterizedTypeReference<T> elementTypeRef)

Return this response as a delayed list of ResponseEntitys.

Parameters
<T>
the type of elements in the list
elementTypeRef:ParameterizedTypeReference<T>

the expected response body list element reference type

Returns:Mono<ResponseEntity<List<T>>>

Mono with the list of ResponseEntitys

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

public Interface ClientResponse.Builder

Known Direct Implementers
org.springframework.web.reactive.function.client.DefaultClientResponseBuilder

Defines a builder for a response.

Method Summary

Modifier and TypeMethod and Description
public ClientResponse.Builder

Returns:

this builder
body
(Function<Flux<DataBuffer>, Flux<DataBuffer>>
the transformation function to use
transformer
)

Transform the response body, if set in the builder.

public ClientResponse.Builder

Returns:

this builder
body
(Flux<DataBuffer>
the new body to use
body
)

Set the body of the response.

public ClientResponse.Builder

Returns:

this builder
body
(String
the new body.
body
)

Set the body of the response to the UTF-8 encoded bytes of the given string.

public ClientResponse
build()

Build the response.

public ClientResponse.Builder

Returns:

this builder
cookie
(String
the cookie name
name
,
String...
the cookie value(s)
values
)

Add a cookie with the given name and value(s).

public ClientResponse.Builder

Returns:

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

Manipulate this response's cookies with the given consumer.

public ClientResponse.Builder

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 ClientResponse.Builder

Returns:

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

Manipulate this response's headers with the given consumer.

public ClientResponse.Builder

Returns:

this builder
rawStatusCode
(int
the new status code
statusCode
)

Set the raw status code of the response.

public ClientResponse.Builder

Returns:

this builder
request
(HttpRequest
the request
request
)

Set the request associated with the response.

public ClientResponse.Builder

Returns:

this builder
statusCode
(HttpStatusCode
the new status code
statusCode
)

Set the status code of the response.

Method Detail

bodyback to summary
public ClientResponse.Builder body(Function<Flux<DataBuffer>, Flux<DataBuffer>> transformer)

Transform the response body, if set in the builder.

Parameters
transformer:Function<Flux<DataBuffer>, Flux<DataBuffer>>

the transformation function to use

Returns:ClientResponse.Builder

this builder

Since
5.3
bodyback to summary
public ClientResponse.Builder body(Flux<DataBuffer> body)

Set the body of the response.

Note

This method will drain the existing body, if set in the builder.

Parameters
body:Flux<DataBuffer>

the new body to use

Returns:ClientResponse.Builder

this builder

bodyback to summary
public ClientResponse.Builder body(String body)

Set the body of the response to the UTF-8 encoded bytes of the given string.

Note

This method will drain the existing body, if set in the builder.

Parameters
body:String

the new body.

Returns:ClientResponse.Builder

this builder

buildback to summary
public ClientResponse build()

Build the response.

cookieback to summary
public ClientResponse.Builder cookie(String name, String... values)

Add a cookie with the given name and value(s).

Parameters
name:String

the cookie name

values:String[]

the cookie value(s)

Returns:ClientResponse.Builder

this builder

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

Manipulate this response's cookies with the given consumer.

The map provided to the consumer is "live", so that the consumer can be used to overwrite existing cookie values, remove values, or use any of the other MultiValueMap methods.

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

a function that consumes the cookies map

Returns:ClientResponse.Builder

this builder

headerback to summary
public ClientResponse.Builder 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:ClientResponse.Builder

this builder

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

Manipulate this response'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:ClientResponse.Builder

this builder

rawStatusCodeback to summary
public ClientResponse.Builder rawStatusCode(int statusCode)

Set the raw status code of the response.

Parameters
statusCode:int

the new status code

Returns:ClientResponse.Builder

this builder

Since
5.1.9
requestback to summary
public ClientResponse.Builder request(HttpRequest request)

Set the request associated with the response.

Parameters
request:HttpRequest

the request

Returns:ClientResponse.Builder

this builder

Since
5.2
statusCodeback to summary
public ClientResponse.Builder statusCode(HttpStatusCode statusCode)

Set the status code of the response.

Parameters
statusCode:HttpStatusCode

the new status code

Returns:ClientResponse.Builder

this builder

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

public Interface ClientResponse.Headers

Known Direct Implementers
org.springframework.web.reactive.function.client.DefaultClientResponse.DefaultHeaders, org.springframework.web.reactive.function.client.support.ClientResponseWrapper.HeadersWrapper

Represents the headers of the HTTP response.
See Also
ClientResponse#headers()

Method Summary

Modifier and TypeMethod and Description
public HttpHeaders
asHttpHeaders()

Return the headers as an HttpHeaders instance.

public OptionalLong
contentLength()

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

public Optional<MediaType>
contentType()

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

public List<String>
header(String
the header name
headerName
)

Return the header value(s), if any, for the header of the given name.

Method Detail

asHttpHeadersback to summary
public HttpHeaders asHttpHeaders()

Return the headers as an HttpHeaders instance.

contentLengthback to summary
public OptionalLong contentLength()

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

contentTypeback to summary
public Optional<MediaType> contentType()

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

headerback to summary
public List<String> header(String headerName)

Return the header value(s), if any, for the header of the given name.

Return an empty list if no header values are found.

Parameters
headerName:String

the header name