Interface ClientResponse
- All Known Implementing Classes:
- ClientResponseWrapper
public interface ClientResponse
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.- Since:
- 5.0
- Author:
- Brian Clozel, Arjen Poutsma
- 
Nested Class SummaryNested ClassesModifier and TypeInterfaceDescriptionstatic interfaceDefines a builder for a response.static interfaceRepresents the headers of the HTTP response.
- 
Method SummaryModifier and TypeMethodDescription<T> Tbody(BodyExtractor<T, ? super ClientHttpResponse> extractor) Extract the body with the givenBodyExtractor.<T> reactor.core.publisher.Flux<T>bodyToFlux(Class<? extends T> elementClass) Extract the body to aFlux.<T> reactor.core.publisher.Flux<T>bodyToFlux(ParameterizedTypeReference<T> elementTypeRef) Extract the body to aFlux.<T> reactor.core.publisher.Mono<T>bodyToMono(Class<? extends T> elementClass) Extract the body to aMono.<T> reactor.core.publisher.Mono<T>bodyToMono(ParameterizedTypeReference<T> elementTypeRef) Extract the body to aMono.cookies()Return the cookies of this response.static ClientResponse.Buildercreate(int statusCode, ExchangeStrategies strategies) Create a response builder with the given raw status code and strategies for reading the body.static ClientResponse.Buildercreate(HttpStatusCode statusCode) Create a response builder with the given status code and using default strategies for reading the body.static ClientResponse.Buildercreate(HttpStatusCode statusCode, List<HttpMessageReader<?>> messageReaders) Create a response builder with the given status code and message body readers.static ClientResponse.Buildercreate(HttpStatusCode statusCode, ExchangeStrategies strategies) Create a response builder with the given status code and strategies for reading the body.<T> reactor.core.publisher.Mono<T>Create aMonothat terminates with aWebClientResponseException, containing the response status, headers, body, and the originating request.reactor.core.publisher.Mono<WebClientResponseException>Create aWebClientResponseExceptionthat contains the response status, headers, body, and the originating request.headers()Return the headers of this response.Return a log message prefix to use to correlate messages for this exchange.default ClientResponse.Buildermutate()Return a builder to mutate this response, for example to change the status, headers, cookies, and replace or transform the body.reactor.core.publisher.Mono<Void>Release the body of this response.request()Return the request associated with the response.Return the HTTP status code as anHttpStatusCodevalue.Return the strategies used to convert the body of this response.reactor.core.publisher.Mono<ResponseEntity<Void>>Return this response as a delayedResponseEntitycontaining status and headers, but no body.<T> reactor.core.publisher.Mono<ResponseEntity<T>>Return this response as a delayedResponseEntity.<T> reactor.core.publisher.Mono<ResponseEntity<T>>toEntity(ParameterizedTypeReference<T> bodyTypeReference) Return this response as a delayedResponseEntity.<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>>toEntityList(Class<T> elementClass) Return this response as a delayed list ofResponseEntitys.<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>>toEntityList(ParameterizedTypeReference<T> elementTypeRef) Return this response as a delayed list ofResponseEntitys.
- 
Method Details- 
statusCodeHttpStatusCode statusCode()Return the HTTP status code as anHttpStatusCodevalue.- Returns:
- the HTTP status as an HttpStatusCode value (never null)
 
- 
headersClientResponse.Headers headers()Return the headers of this response.
- 
cookiesMultiValueMap<String,ResponseCookie> cookies()Return the cookies of this response.
- 
strategiesExchangeStrategies strategies()Return the strategies used to convert the body of this response.
- 
requestHttpRequest request()Return the request associated with the response.- Since:
- 6.1
 
- 
bodyExtract the body with the givenBodyExtractor.- Type Parameters:
- T- the type of the body returned
- Parameters:
- extractor- the- BodyExtractorthat reads from the response
- Returns:
- the extracted body
 
- 
bodyToMonoExtract the body to aMono.- Type Parameters:
- T- the element type
- Parameters:
- elementClass- the class of element in the- Mono
- Returns:
- a mono containing the body of the given type T
 
- 
bodyToMonoExtract the body to aMono.- Type Parameters:
- T- the element type
- Parameters:
- elementTypeRef- the type reference of element in the- Mono
- Returns:
- a mono containing the body of the given type T
 
- 
bodyToFluxExtract the body to aFlux.- Type Parameters:
- T- the element type
- Parameters:
- elementClass- the class of elements in the- Flux
- Returns:
- a flux containing the body of the given type T
 
- 
bodyToFluxExtract the body to aFlux.- Type Parameters:
- T- the element type
- Parameters:
- elementTypeRef- the type reference of elements in the- Flux
- Returns:
- a flux containing the body of the given type T
 
- 
releaseBodyreactor.core.publisher.Mono<Void> releaseBody()Release the body of this response.- Returns:
- a completion signal
- Since:
- 5.2
- See Also:
 
- 
toEntityReturn this response as a delayedResponseEntity.- Type Parameters:
- T- response body type
- Parameters:
- bodyClass- the expected response body type
- Returns:
- Monowith the- ResponseEntity
 
- 
toEntity<T> reactor.core.publisher.Mono<ResponseEntity<T>> toEntity(ParameterizedTypeReference<T> bodyTypeReference) Return this response as a delayedResponseEntity.- Type Parameters:
- T- response body type
- Parameters:
- bodyTypeReference- a type reference describing the expected response body type
- Returns:
- Monowith the- ResponseEntity
 
- 
toEntityListReturn this response as a delayed list ofResponseEntitys.- Type Parameters:
- T- the type of elements in the list
- Parameters:
- elementClass- the expected response body list element class
- Returns:
- Monowith the list of- ResponseEntitys
 
- 
toEntityList<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>> toEntityList(ParameterizedTypeReference<T> elementTypeRef) Return this response as a delayed list ofResponseEntitys.- Type Parameters:
- T- the type of elements in the list
- Parameters:
- elementTypeRef- the expected response body list element reference type
- Returns:
- Monowith the list of- ResponseEntitys
 
- 
toBodilessEntityreactor.core.publisher.Mono<ResponseEntity<Void>> toBodilessEntity()Return this response as a delayedResponseEntitycontaining status and headers, but no body. Calling this method will release the body of the response.- Returns:
- Monowith the bodiless- ResponseEntity
- Since:
- 5.2
 
- 
createExceptionreactor.core.publisher.Mono<WebClientResponseException> createException()Create aWebClientResponseExceptionthat contains the response status, headers, body, and the originating request.- Returns:
- a Monowith the created exception
- Since:
- 5.2
 
- 
createError<T> reactor.core.publisher.Mono<T> createError()Create aMonothat terminates with aWebClientResponseException, containing the response status, headers, body, and the originating request.- Type Parameters:
- T- the reified type
- Returns:
- a Monothat fails with aWebClientResponseException.
- Since:
- 6.0
- See Also:
 
- 
logPrefixString 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_ATTRIBUTErequest attribute, further surrounded with "[" and "]".- Returns:
- the log message prefix or an empty String if the
 LOG_ID_ATTRIBUTEis not set
- Since:
- 5.2.3
 
- 
mutateReturn a builder to mutate this response, for example to change the status, headers, cookies, and replace or transform the body.- Returns:
- a builder to mutate the response with
- Since:
- 5.3
 
- 
createCreate a response builder with the given status code and using default strategies for reading the body.- Parameters:
- statusCode- the status code
- Returns:
- the created builder
 
- 
createCreate a response builder with the given status code and strategies for reading the body.- Parameters:
- statusCode- the status code
- strategies- the strategies
- Returns:
- the created builder
 
- 
createCreate a response builder with the given raw status code and strategies for reading the body.- Parameters:
- statusCode- the status code
- strategies- the strategies
- Returns:
- the created builder
- Since:
- 5.1.9
 
- 
createstatic ClientResponse.Builder create(HttpStatusCode statusCode, List<HttpMessageReader<?>> messageReaders) Create a response builder with the given status code and message body readers.- Parameters:
- statusCode- the status code
- messageReaders- the message readers
- Returns:
- the created builder
 
 
-