private static class DefaultWebClient.DefaultResponseSpec extends java.lang.Object implements WebClient.ResponseSpec
Modifier and Type | Class and Description |
---|---|
private static class |
DefaultWebClient.DefaultResponseSpec.StatusHandler |
Modifier and Type | Field and Description |
---|---|
private static DefaultWebClient.DefaultResponseSpec.StatusHandler |
DEFAULT_STATUS_HANDLER |
private java.util.function.Supplier<HttpRequest> |
requestSupplier |
private <any> |
responseMono |
private static java.util.function.IntPredicate |
STATUS_CODE_ERROR |
private java.util.List<DefaultWebClient.DefaultResponseSpec.StatusHandler> |
statusHandlers |
Constructor and Description |
---|
DefaultResponseSpec(<any> responseMono,
java.util.function.Supplier<HttpRequest> requestSupplier) |
Modifier and Type | Method and Description |
---|---|
<T> <any> |
bodyToFlux(java.lang.Class<T> elementType)
Extract the body to a
Flux . |
<T> <any> |
bodyToFlux(ParameterizedTypeReference<T> elementType)
Extract the body to a
Flux . |
<T> <any> |
bodyToMono(java.lang.Class<T> bodyType)
Extract the body to a
Mono . |
<T> <any> |
bodyToMono(ParameterizedTypeReference<T> bodyType)
Extract the body to a
Mono . |
private static <any> |
createResponseException(ClientResponse response,
HttpRequest request) |
private <T> <any> |
drainBody(ClientResponse response,
java.lang.Throwable ex) |
private <T extends <any>> |
handleBody(ClientResponse response,
T bodyPublisher,
java.util.function.Function<<any>,T> errorFunction) |
WebClient.ResponseSpec |
onRawStatus(java.util.function.IntPredicate statusCodePredicate,
java.util.function.Function<ClientResponse,<any>> exceptionFunction)
Register a custom error function that gets invoked when the given raw status code
predicate applies.
|
WebClient.ResponseSpec |
onStatus(java.util.function.Predicate<HttpStatus> statusPredicate,
java.util.function.Function<ClientResponse,<any>> exceptionFunction)
Register a custom error function that gets invoked when the given
HttpStatus
predicate applies. |
private static java.util.function.IntPredicate |
toIntPredicate(java.util.function.Predicate<HttpStatus> predicate) |
private static final java.util.function.IntPredicate STATUS_CODE_ERROR
private static final DefaultWebClient.DefaultResponseSpec.StatusHandler DEFAULT_STATUS_HANDLER
private final <any> responseMono
private final java.util.function.Supplier<HttpRequest> requestSupplier
private final java.util.List<DefaultWebClient.DefaultResponseSpec.StatusHandler> statusHandlers
DefaultResponseSpec(<any> responseMono, java.util.function.Supplier<HttpRequest> requestSupplier)
public WebClient.ResponseSpec onStatus(java.util.function.Predicate<HttpStatus> statusPredicate, java.util.function.Function<ClientResponse,<any>> exceptionFunction)
WebClient.ResponseSpec
HttpStatus
predicate applies. The exception returned from the function will be returned from
WebClient.ResponseSpec.bodyToMono(Class)
and WebClient.ResponseSpec.bodyToFlux(Class)
.
By default, an error handler is registered that throws a
WebClientResponseException
when the response status code is 4xx or 5xx.
onStatus
in interface WebClient.ResponseSpec
statusPredicate
- a predicate that indicates whether exceptionFunction
applies
NOTE: if the response is expected to have content, the exceptionFunction should consume it. If not, the content will be automatically drained to ensure resources are released.
exceptionFunction
- the function that returns the exceptionprivate static java.util.function.IntPredicate toIntPredicate(java.util.function.Predicate<HttpStatus> predicate)
public WebClient.ResponseSpec onRawStatus(java.util.function.IntPredicate statusCodePredicate, java.util.function.Function<ClientResponse,<any>> exceptionFunction)
WebClient.ResponseSpec
WebClient.ResponseSpec.bodyToMono(Class)
and WebClient.ResponseSpec.bodyToFlux(Class)
.
By default, an error handler is registered that throws a
WebClientResponseException
when the response status code is 4xx or 5xx.
onRawStatus
in interface WebClient.ResponseSpec
statusCodePredicate
- a predicate of the raw status code that indicates
whether exceptionFunction
applies.
NOTE: if the response is expected to have content, the exceptionFunction should consume it. If not, the content will be automatically drained to ensure resources are released.
exceptionFunction
- the function that returns the exceptionpublic <T> <any> bodyToMono(java.lang.Class<T> bodyType)
WebClient.ResponseSpec
Mono
. By default, if the response has status code 4xx or
5xx, the Mono
will contain a WebClientException
. This can be overridden
with WebClient.ResponseSpec.onStatus(Predicate, Function)
.bodyToMono
in interface WebClient.ResponseSpec
T
- response body typebodyType
- the expected response body typeWebClientResponseException
if the
status code is 4xx or 5xxpublic <T> <any> bodyToMono(ParameterizedTypeReference<T> bodyType)
WebClient.ResponseSpec
Mono
. By default, if the response has status code 4xx or
5xx, the Mono
will contain a WebClientException
. This can be overridden
with WebClient.ResponseSpec.onStatus(Predicate, Function)
.bodyToMono
in interface WebClient.ResponseSpec
T
- response body typebodyType
- a type reference describing the expected response body typeWebClientResponseException
if the
status code is 4xx or 5xxpublic <T> <any> bodyToFlux(java.lang.Class<T> elementType)
WebClient.ResponseSpec
Flux
. By default, if the response has status code 4xx or
5xx, the Flux
will contain a WebClientException
. This can be overridden
with WebClient.ResponseSpec.onStatus(Predicate, Function)
.bodyToFlux
in interface WebClient.ResponseSpec
T
- the type of elements in the responseelementType
- the type of element in the responseWebClientResponseException
if the
status code is 4xx or 5xxpublic <T> <any> bodyToFlux(ParameterizedTypeReference<T> elementType)
WebClient.ResponseSpec
Flux
. By default, if the response has status code 4xx or
5xx, the Flux
will contain a WebClientException
. This can be overridden
with WebClient.ResponseSpec.onStatus(Predicate, Function)
.bodyToFlux
in interface WebClient.ResponseSpec
T
- the type of elements in the responseelementType
- a type reference describing the expected response body typeWebClientResponseException
if the
status code is 4xx or 5xxprivate <T extends <any>> T handleBody(ClientResponse response, T bodyPublisher, java.util.function.Function<<any>,T> errorFunction)
private <T> <any> drainBody(ClientResponse response, java.lang.Throwable ex)
private static <any> createResponseException(ClientResponse response, HttpRequest request)