public interface ClientResponse
WebClient
and also
ExchangeFunction
. Provides access to the response status and headers,
and also methods to consume the response body.
NOTE: When given access to a ClientResponse
,
through the WebClient
exchange()
method,
you must always use one of the body or toEntity methods to ensure resources
are released and avoid potential issues with HTTP connection pooling.
You can use bodyToMono(Void.class)
if no response content is
expected. However keep in mind that if the response does have content, the
connection will be closed and will not be placed back in the pool.
Modifier and Type | Interface and Description |
---|---|
static interface |
ClientResponse.Builder
Defines a builder for a response.
|
static interface |
ClientResponse.Headers
Represents the headers of the HTTP response.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
body(BodyExtractor<T,? super ClientHttpResponse> extractor)
Extract the body with the given
BodyExtractor . |
<T> reactor.core.publisher.Flux<T> |
bodyToFlux(Class<? extends T> elementClass)
Extract the body to a
Flux . |
<T> reactor.core.publisher.Flux<T> |
bodyToFlux(ParameterizedTypeReference<T> typeReference)
Extract the body to a
Flux . |
<T> reactor.core.publisher.Mono<T> |
bodyToMono(Class<? extends T> elementClass)
Extract the body to a
Mono . |
<T> reactor.core.publisher.Mono<T> |
bodyToMono(ParameterizedTypeReference<T> typeReference)
Extract the body to a
Mono . |
MultiValueMap<String,ResponseCookie> |
cookies()
Return cookies of this response.
|
static ClientResponse.Builder |
create(HttpStatus statusCode)
Create a response builder with the given status code and using default strategies for
reading the body.
|
static ClientResponse.Builder |
create(HttpStatus statusCode,
ExchangeStrategies strategies)
Create a response builder with the given status code and strategies for reading the body.
|
static ClientResponse.Builder |
create(HttpStatus statusCode,
List<HttpMessageReader<?>> messageReaders)
Create a response builder with the given status code and message body readers.
|
static ClientResponse.Builder |
create(int statusCode,
ExchangeStrategies strategies)
Create a response builder with the given raw status code and strategies for reading the body.
|
static ClientResponse.Builder |
from(ClientResponse other)
Create a builder with the status, headers, and cookies of the given response.
|
ClientResponse.Headers |
headers()
Return the headers of this response.
|
int |
rawStatusCode()
Return the (potentially non-standard) status code of this response.
|
HttpStatus |
statusCode()
Return the HTTP status code as an
HttpStatus enum value. |
ExchangeStrategies |
strategies()
Return the strategies used to convert the body of this response.
|
<T> reactor.core.publisher.Mono<ResponseEntity<T>> |
toEntity(Class<T> bodyType)
Return this response as a delayed
ResponseEntity . |
<T> reactor.core.publisher.Mono<ResponseEntity<T>> |
toEntity(ParameterizedTypeReference<T> typeReference)
Return this response as a delayed
ResponseEntity . |
<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>> |
toEntityList(Class<T> elementType)
Return this response as a delayed list of
ResponseEntity s. |
<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>> |
toEntityList(ParameterizedTypeReference<T> typeReference)
Return this response as a delayed list of
ResponseEntity s. |
HttpStatus statusCode()
HttpStatus
enum value.null
)IllegalArgumentException
- in case of an unknown HTTP status codeHttpStatus.valueOf(int)
int rawStatusCode()
statusCode()
,
HttpStatus.resolve(int)
ClientResponse.Headers headers()
MultiValueMap<String,ResponseCookie> cookies()
ExchangeStrategies strategies()
<T> T body(BodyExtractor<T,? super ClientHttpResponse> extractor)
BodyExtractor
.T
- the type of the body returnedextractor
- the BodyExtractor
that reads from the response<T> reactor.core.publisher.Mono<T> bodyToMono(Class<? extends T> elementClass)
Mono
.T
- the element typeelementClass
- the class of element in the Mono
T
<T> reactor.core.publisher.Mono<T> bodyToMono(ParameterizedTypeReference<T> typeReference)
Mono
.T
- the element typetypeReference
- a type reference describing the expected response body typeT
<T> reactor.core.publisher.Flux<T> bodyToFlux(Class<? extends T> elementClass)
Flux
.T
- the element typeelementClass
- the class of element in the Flux
T
<T> reactor.core.publisher.Flux<T> bodyToFlux(ParameterizedTypeReference<T> typeReference)
Flux
.T
- the element typetypeReference
- a type reference describing the expected response body typeT
<T> reactor.core.publisher.Mono<ResponseEntity<T>> toEntity(Class<T> bodyType)
ResponseEntity
.T
- response body typebodyType
- the expected response body typeMono
with the ResponseEntity
<T> reactor.core.publisher.Mono<ResponseEntity<T>> toEntity(ParameterizedTypeReference<T> typeReference)
ResponseEntity
.T
- response body typetypeReference
- a type reference describing the expected response body typeMono
with the ResponseEntity
<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>> toEntityList(Class<T> elementType)
ResponseEntity
s.T
- the type of elements in the listelementType
- the expected response body list element typeMono
with the list of ResponseEntity
s<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>> toEntityList(ParameterizedTypeReference<T> typeReference)
ResponseEntity
s.T
- the type of elements in the listtypeReference
- a type reference describing the expected response body typeMono
with the list of ResponseEntity
sstatic ClientResponse.Builder from(ClientResponse other)
other
- the response to copy the status, headers, and cookies fromstatic ClientResponse.Builder create(HttpStatus statusCode)
statusCode
- the status codestatic ClientResponse.Builder create(HttpStatus statusCode, ExchangeStrategies strategies)
statusCode
- the status codestrategies
- the strategiesstatic ClientResponse.Builder create(int statusCode, ExchangeStrategies strategies)
statusCode
- the status codestrategies
- the strategiesstatic ClientResponse.Builder create(HttpStatus statusCode, List<HttpMessageReader<?>> messageReaders)
statusCode
- the status codemessageReaders
- the message readers