public static interface WebClient.ResponseSpec
| Modifier and Type | Method and Description |
|---|---|
<T> reactor.core.publisher.Flux<T> |
bodyToFlux(Class<T> elementClass)
Decode the body to a
Flux with elements of the given type. |
<T> reactor.core.publisher.Flux<T> |
bodyToFlux(ParameterizedTypeReference<T> elementTypeRef)
Variant of
bodyToMono(Class) with a ParameterizedTypeReference. |
<T> reactor.core.publisher.Mono<T> |
bodyToMono(Class<T> elementClass)
Decode the body to the given target type.
|
<T> reactor.core.publisher.Mono<T> |
bodyToMono(ParameterizedTypeReference<T> elementTypeRef)
Variant of
bodyToMono(Class) with a ParameterizedTypeReference. |
WebClient.ResponseSpec |
onRawStatus(IntPredicate statusCodePredicate,
Function<ClientResponse,reactor.core.publisher.Mono<? extends Throwable>> exceptionFunction)
Variant of
onStatus(Predicate, Function) that works with
raw status code values. |
WebClient.ResponseSpec |
onStatus(Predicate<HttpStatus> statusPredicate,
Function<ClientResponse,reactor.core.publisher.Mono<? extends Throwable>> exceptionFunction)
Provide a function to map specific error status codes to an error
signal to be propagated downstream instead of the response.
|
reactor.core.publisher.Mono<ResponseEntity<Void>> |
toBodilessEntity()
Return a
ResponseEntity without a body. |
<T> reactor.core.publisher.Mono<ResponseEntity<T>> |
toEntity(Class<T> bodyClass)
Return a
ResponseEntity with the body decoded to an Object of
the given type. |
<T> reactor.core.publisher.Mono<ResponseEntity<T>> |
toEntity(ParameterizedTypeReference<T> bodyTypeReference)
Variant of
bodyToMono(Class) with a ParameterizedTypeReference. |
<T> reactor.core.publisher.Mono<ResponseEntity<reactor.core.publisher.Flux<T>>> |
toEntityFlux(BodyExtractor<reactor.core.publisher.Flux<T>,? super ClientHttpResponse> bodyExtractor)
Variant of
toEntityFlux(Class) with a BodyExtractor. |
<T> reactor.core.publisher.Mono<ResponseEntity<reactor.core.publisher.Flux<T>>> |
toEntityFlux(Class<T> elementType)
Return a
ResponseEntity with the body decoded to a Flux
of elements of the given type. |
<T> reactor.core.publisher.Mono<ResponseEntity<reactor.core.publisher.Flux<T>>> |
toEntityFlux(ParameterizedTypeReference<T> elementTypeReference)
Variant of
toEntityFlux(Class) with a ParameterizedTypeReference. |
<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>> |
toEntityList(Class<T> elementClass)
Return a
ResponseEntity with the body decoded to a List
of elements of the given type. |
<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>> |
toEntityList(ParameterizedTypeReference<T> elementTypeRef)
Variant of
toEntity(Class) with a ParameterizedTypeReference. |
WebClient.ResponseSpec onStatus(Predicate<HttpStatus> statusPredicate, Function<ClientResponse,reactor.core.publisher.Mono<? extends Throwable>> exceptionFunction)
By default, if there are no matching status handlers, responses
with status codes >= 400 are mapped to
WebClientResponseException which is created with
ClientResponse.createException().
To suppress the treatment of a status code as an error and process
it as a normal response, return Mono.empty() from the function.
The response will then propagate downstream to be processed.
To ignore an error response completely, and propagate neither
response nor error, use a filter, or
add onErrorResume downstream, for example:
webClient.get()
.uri("https://abc.com/account/123")
.retrieve()
.bodyToMono(Account.class)
.onErrorResume(WebClientResponseException.class,
ex -> ex.getRawStatusCode() == 404 ? Mono.empty() : Mono.error(ex));
statusPredicate - to match responses withexceptionFunction - to map the response to an error signalClientResponse.createException()WebClient.ResponseSpec onRawStatus(IntPredicate statusCodePredicate, Function<ClientResponse,reactor.core.publisher.Mono<? extends Throwable>> exceptionFunction)
onStatus(Predicate, Function) that works with
raw status code values. This is useful for custom status codes.statusCodePredicate - to match responses withexceptionFunction - to map the response to an error signal<T> reactor.core.publisher.Mono<T> bodyToMono(Class<T> elementClass)
Mono emits a WebClientException.
Use onStatus(Predicate, Function) to customize error response
handling.T - the target body typeelementClass - the type to decode to<T> reactor.core.publisher.Mono<T> bodyToMono(ParameterizedTypeReference<T> elementTypeRef)
bodyToMono(Class) with a ParameterizedTypeReference.T - the target body typeelementTypeRef - the type to decode to<T> reactor.core.publisher.Flux<T> bodyToFlux(Class<T> elementClass)
Flux with elements of the given type.
For an error response (status code of 4xx or 5xx), the Mono
emits a WebClientException. Use onStatus(Predicate, Function)
to customize error response handling.T - the body element typeelementClass - the type of element to decode to<T> reactor.core.publisher.Flux<T> bodyToFlux(ParameterizedTypeReference<T> elementTypeRef)
bodyToMono(Class) with a ParameterizedTypeReference.T - the body element typeelementTypeRef - the type of element to decode to<T> reactor.core.publisher.Mono<ResponseEntity<T>> toEntity(Class<T> bodyClass)
ResponseEntity with the body decoded to an Object of
the given type. For an error response (status code of 4xx or 5xx), the
Mono emits a WebClientException. Use
onStatus(Predicate, Function) to customize error response handling.T - response body typebodyClass - the expected response body typeResponseEntity with the decoded body<T> reactor.core.publisher.Mono<ResponseEntity<T>> toEntity(ParameterizedTypeReference<T> bodyTypeReference)
bodyToMono(Class) with a ParameterizedTypeReference.T - the response body typebodyTypeReference - the expected response body typeResponseEntity with the decoded body<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>> toEntityList(Class<T> elementClass)
ResponseEntity with the body decoded to a List
of elements of the given type. For an error response (status code of
4xx or 5xx), the Mono emits a WebClientException.
Use onStatus(Predicate, Function) to customize error response
handling.T - the body element typeelementClass - the type of element to decode the target Flux toResponseEntity<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>> toEntityList(ParameterizedTypeReference<T> elementTypeRef)
toEntity(Class) with a ParameterizedTypeReference.T - the body element typeelementTypeRef - the type of element to decode the target Flux toResponseEntity<T> reactor.core.publisher.Mono<ResponseEntity<reactor.core.publisher.Flux<T>>> toEntityFlux(Class<T> elementType)
ResponseEntity with the body decoded to a Flux
of elements of the given type. For an error response (status code of
4xx or 5xx), the Mono emits a WebClientException.
Use onStatus(Predicate, Function) to customize error response
handling.
Note: The Flux representing the body must
be subscribed to or else associated resources will not be released.
T - the body element typeelementType - the type of element to decode the target Flux toResponseEntity<T> reactor.core.publisher.Mono<ResponseEntity<reactor.core.publisher.Flux<T>>> toEntityFlux(ParameterizedTypeReference<T> elementTypeReference)
toEntityFlux(Class) with a ParameterizedTypeReference.T - the body element typeelementTypeReference - the type of element to decode the target Flux toResponseEntity<T> reactor.core.publisher.Mono<ResponseEntity<reactor.core.publisher.Flux<T>>> toEntityFlux(BodyExtractor<reactor.core.publisher.Flux<T>,? super ClientHttpResponse> bodyExtractor)
toEntityFlux(Class) with a BodyExtractor.T - the body element typebodyExtractor - the BodyExtractor that reads from the responseResponseEntityreactor.core.publisher.Mono<ResponseEntity<Void>> toBodilessEntity()
ResponseEntity without a body. For an error response
(status code of 4xx or 5xx), the Mono emits a
WebClientException. Use onStatus(Predicate, Function)
to customize error response handling.ResponseEntity