public interface ClientResponse
WebClient
and also
ExchangeFunction
. Provides access to the response status and
headers, and also methods to consume the response body.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> elementTypeRef)
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> elementTypeRef)
Extract the body to a
Mono . |
MultiValueMap<String,ResponseCookie> |
cookies()
Return the 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.
|
reactor.core.publisher.Mono<WebClientResponseException> |
createException()
Create a
WebClientResponseException that contains the response
status, headers, body, and the originating request. |
static ClientResponse.Builder |
from(ClientResponse other)
Deprecated.
as of 5.3 in favor of the instance based
mutate() . |
ClientResponse.Headers |
headers()
Return the headers of this response.
|
String |
logPrefix()
Return a log message prefix to use to correlate messages for this exchange.
|
default ClientResponse.Builder |
mutate()
Return a builder to mutate the this response, for example to change
the status, headers, cookies, and replace or transform the body.
|
int |
rawStatusCode()
Return the (potentially non-standard) status code of this response.
|
reactor.core.publisher.Mono<Void> |
releaseBody()
Release the body 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.
|
reactor.core.publisher.Mono<ResponseEntity<Void>> |
toBodilessEntity()
Return this response as a delayed
ResponseEntity containing
status and headers, but no body. |
<T> reactor.core.publisher.Mono<ResponseEntity<T>> |
toEntity(Class<T> bodyClass)
Return this response as a delayed
ResponseEntity . |
<T> reactor.core.publisher.Mono<ResponseEntity<T>> |
toEntity(ParameterizedTypeReference<T> bodyTypeReference)
Return this response as a delayed
ResponseEntity . |
<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>> |
toEntityList(Class<T> elementClass)
Return this response as a delayed list of
ResponseEntity s. |
<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>> |
toEntityList(ParameterizedTypeReference<T> elementTypeRef)
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> elementTypeRef)
Mono
.T
- the element typeelementTypeRef
- the type reference of element in the Mono
T
<T> reactor.core.publisher.Flux<T> bodyToFlux(Class<? extends T> elementClass)
Flux
.T
- the element typeelementClass
- the class of elements in the Flux
T
<T> reactor.core.publisher.Flux<T> bodyToFlux(ParameterizedTypeReference<T> elementTypeRef)
Flux
.T
- the element typeelementTypeRef
- the type reference of elements in the Flux
T
reactor.core.publisher.Mono<Void> releaseBody()
DataBufferUtils.release(DataBuffer)
<T> reactor.core.publisher.Mono<ResponseEntity<T>> toEntity(Class<T> bodyClass)
ResponseEntity
.T
- response body typebodyClass
- the expected response body typeMono
with the ResponseEntity
<T> reactor.core.publisher.Mono<ResponseEntity<T>> toEntity(ParameterizedTypeReference<T> bodyTypeReference)
ResponseEntity
.T
- response body typebodyTypeReference
- a type reference describing the expected response body typeMono
with the ResponseEntity
<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>> toEntityList(Class<T> elementClass)
ResponseEntity
s.T
- the type of elements in the listelementClass
- the expected response body list element classMono
with the list of ResponseEntity
s<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>> toEntityList(ParameterizedTypeReference<T> elementTypeRef)
ResponseEntity
s.T
- the type of elements in the listelementTypeRef
- the expected response body list element reference typeMono
with the list of ResponseEntity
sreactor.core.publisher.Mono<ResponseEntity<Void>> toBodilessEntity()
ResponseEntity
containing
status and headers, but no body. Calling this method will
release the body of the response.Mono
with the bodiless ResponseEntity
reactor.core.publisher.Mono<WebClientResponseException> createException()
WebClientResponseException
that contains the response
status, headers, body, and the originating request.Mono
with the created exceptionString logPrefix()
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 "]".
LOG_ID_ATTRIBUTE
is not setdefault ClientResponse.Builder mutate()
@Deprecated static ClientResponse.Builder from(ClientResponse other)
mutate()
.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.
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