接口 WebClient.ResponseSpec
- 封闭接口:
- WebClient
public static interface WebClient.ResponseSpec
Contract for specifying response operations following the exchange.
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 <T> reactor.core.publisher.Flux<T>
bodyToFlux(Class<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<T> elementClass)
Extract the body to aMono
.<T> reactor.core.publisher.Mono<T>
bodyToMono(ParameterizedTypeReference<T> elementTypeRef)
Extract the body to aMono
.WebClient.ResponseSpec
onRawStatus(IntPredicate statusCodePredicate, Function<ClientResponse,reactor.core.publisher.Mono<? extends Throwable>> exceptionFunction)
Variant ofonStatus(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 the response as a delayedResponseEntity
containing status and headers, but no body.<T> reactor.core.publisher.Mono<ResponseEntity<T>>
toEntity(Class<T> bodyClass)
Return the response as a delayedResponseEntity
.<T> reactor.core.publisher.Mono<ResponseEntity<T>>
toEntity(ParameterizedTypeReference<T> bodyTypeReference)
Return the response as a delayedResponseEntity
.<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>>
toEntityList(Class<T> elementClass)
Return the response as a delayed list ofResponseEntity
s.<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>>
toEntityList(ParameterizedTypeReference<T> elementTypeRef)
Return the response as a delayed list ofResponseEntity
s.
方法详细资料
onStatus
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.By default, if there are no matching status handlers, responses with status codes >= 400 are mapped to
WebClientResponseException
which is created withClientResponse.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 addonErrorResume
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 signal- 返回:
- this builder
- 另请参阅:
ClientResponse.createException()
onRawStatus
WebClient.ResponseSpec onRawStatus(IntPredicate statusCodePredicate, Function<ClientResponse,reactor.core.publisher.Mono<? extends Throwable>> exceptionFunction)
Variant ofonStatus(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- 返回:
- this builder
- 从以下版本开始:
- 5.1.9
bodyToMono
<T> reactor.core.publisher.Mono<T> bodyToMono(Class<T> elementClass)
Extract the body to aMono
. By default, if the response has status code 4xx or 5xx, theMono
will contain aWebClientException
. This can be overridden withonStatus(Predicate, Function)
.- 类型参数:
T
- response body type- 参数:
elementClass
- the expected response body element class- 返回:
- a mono containing the body, or a
WebClientResponseException
if the status code is 4xx or 5xx
bodyToMono
<T> reactor.core.publisher.Mono<T> bodyToMono(ParameterizedTypeReference<T> elementTypeRef)
Extract the body to aMono
. By default, if the response has status code 4xx or 5xx, theMono
will contain aWebClientException
. This can be overridden withonStatus(Predicate, Function)
.- 类型参数:
T
- response body type- 参数:
elementTypeRef
- a type reference describing the expected response body element type- 返回:
- a mono containing the body, or a
WebClientResponseException
if the status code is 4xx or 5xx
bodyToFlux
<T> reactor.core.publisher.Flux<T> bodyToFlux(Class<T> elementClass)
Extract the body to aFlux
. By default, if the response has status code 4xx or 5xx, theFlux
will contain aWebClientException
. This can be overridden withonStatus(Predicate, Function)
.- 类型参数:
T
- the type of elements in the response- 参数:
elementClass
- the class of elements in the response- 返回:
- a flux containing the body, or a
WebClientResponseException
if the status code is 4xx or 5xx
bodyToFlux
<T> reactor.core.publisher.Flux<T> bodyToFlux(ParameterizedTypeReference<T> elementTypeRef)
Extract the body to aFlux
. By default, if the response has status code 4xx or 5xx, theFlux
will contain aWebClientException
. This can be overridden withonStatus(Predicate, Function)
.- 类型参数:
T
- the type of elements in the response- 参数:
elementTypeRef
- a type reference describing the expected response body element type- 返回:
- a flux containing the body, or a
WebClientResponseException
if the status code is 4xx or 5xx
toEntity
<T> reactor.core.publisher.Mono<ResponseEntity<T>> toEntity(Class<T> bodyClass)
Return the response as a delayedResponseEntity
. By default, if the response has status code 4xx or 5xx, theMono
will contain aWebClientException
. This can be overridden withonStatus(Predicate, Function)
.- 类型参数:
T
- response body type- 参数:
bodyClass
- the expected response body type- 返回:
Mono
with theResponseEntity
- 从以下版本开始:
- 5.2
toEntity
<T> reactor.core.publisher.Mono<ResponseEntity<T>> toEntity(ParameterizedTypeReference<T> bodyTypeReference)
Return the response as a delayedResponseEntity
. By default, if the response has status code 4xx or 5xx, theMono
will contain aWebClientException
. This can be overridden withonStatus(Predicate, Function)
.- 类型参数:
T
- response body type- 参数:
bodyTypeReference
- a type reference describing the expected response body type- 返回:
Mono
with theResponseEntity
- 从以下版本开始:
- 5.2
toEntityList
<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>> toEntityList(Class<T> elementClass)
Return the response as a delayed list ofResponseEntity
s. By default, if the response has status code 4xx or 5xx, theMono
will contain aWebClientException
. This can be overridden withonStatus(Predicate, Function)
.- 类型参数:
T
- the type of elements in the list- 参数:
elementClass
- the expected response body list element class- 返回:
Mono
with the list ofResponseEntity
s- 从以下版本开始:
- 5.2
toEntityList
<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>> toEntityList(ParameterizedTypeReference<T> elementTypeRef)
Return the response as a delayed list ofResponseEntity
s. By default, if the response has status code 4xx or 5xx, theMono
will contain aWebClientException
. This can be overridden withonStatus(Predicate, Function)
.- 类型参数:
T
- the type of elements in the list- 参数:
elementTypeRef
- the expected response body list element reference type- 返回:
Mono
with the list ofResponseEntity
s- 从以下版本开始:
- 5.2
toBodilessEntity
reactor.core.publisher.Mono<ResponseEntity<Void>> toBodilessEntity()
Return the response as a delayedResponseEntity
containing status and headers, but no body. By default, if the response has status code 4xx or 5xx, theMono
will contain aWebClientException
. This can be overridden withonStatus(Predicate, Function)
. Calling this method will release the body of the response.- 返回:
Mono
with the bodilessResponseEntity
- 从以下版本开始:
- 5.2