接口 ClientResponse
- 所有已知实现类:
ClientResponseWrapper
public interface ClientResponse
Represents an HTTP response, as returned byWebClientand alsoExchangeFunction. Provides access to the response status and headers, and also methods to consume the response body.NOTE: When using a
ClientResponsethrough theWebClientexchange()method, you have to make sure that the body is consumed or released by using one of the following methods:body(BodyExtractor)bodyToMono(Class)orbodyToMono(ParameterizedTypeReference)bodyToFlux(Class)orbodyToFlux(ParameterizedTypeReference)toEntity(Class)ortoEntity(ParameterizedTypeReference)toEntityList(Class)ortoEntityList(ParameterizedTypeReference)toBodilessEntity()releaseBody()
bodyToMono(Void.class)if no response content is expected. However keep in mind the connection will be closed, instead of being placed back in the pool, if any content does arrive. This is in contrast toreleaseBody()which does consume the full body and releases any content received.- 从以下版本开始:
- 5.0
- 作者:
- Brian Clozel, Arjen Poutsma
嵌套类概要
嵌套类 修饰符和类型 接口 说明 static interfaceClientResponse.BuilderDefines a builder for a response.static interfaceClientResponse.HeadersRepresents the headers of the HTTP response.
方法概要
所有方法 静态方法 实例方法 抽象方法 修饰符和类型 方法 说明 <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.MultiValueMap<String,ResponseCookie>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(HttpStatus statusCode)Create a response builder with the given status code and using default strategies for reading the body.static ClientResponse.Buildercreate(HttpStatus statusCode, List<HttpMessageReader<?>> messageReaders)Create a response builder with the given status code and message body readers.static ClientResponse.Buildercreate(HttpStatus statusCode, ExchangeStrategies strategies)Create a response builder with the given status code and strategies for reading the body.reactor.core.publisher.Mono<WebClientResponseException>createException()Create aWebClientResponseExceptionthat contains the response status, headers, body, and the originating request.static ClientResponse.Builderfrom(ClientResponse other)Create a builder with the status, headers, and cookies of the given response.ClientResponse.Headersheaders()Return the headers of this response.StringlogPrefix()Return a log message prefix to use to correlate messages for this exchange.intrawStatusCode()Return the (potentially non-standard) status code of this response.reactor.core.publisher.Mono<Void>releaseBody()Release the body of this response.HttpStatusstatusCode()Return the HTTP status code as anHttpStatusenum value.ExchangeStrategiesstrategies()Return the strategies used to convert the body of this response.reactor.core.publisher.Mono<ResponseEntity<Void>>toBodilessEntity()Return this response as a delayedResponseEntitycontaining status and headers, but no body.<T> reactor.core.publisher.Mono<ResponseEntity<T>>toEntity(Class<T> bodyClass)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.
方法详细资料
statusCode
HttpStatus statusCode()
Return the HTTP status code as anHttpStatusenum value.- 返回:
- the HTTP status as an HttpStatus enum value (never
null) - 抛出:
IllegalArgumentException- in case of an unknown HTTP status code- 从以下版本开始:
- #getRawStatusCode()
- 另请参阅:
HttpStatus.valueOf(int)
rawStatusCode
int rawStatusCode()
Return the (potentially non-standard) status code of this response.- 返回:
- the HTTP status as an integer value
- 从以下版本开始:
- 5.1
- 另请参阅:
statusCode(),HttpStatus.resolve(int)
headers
ClientResponse.Headers headers()
Return the headers of this response.
cookies
MultiValueMap<String,ResponseCookie> cookies()
Return the cookies of this response.
strategies
ExchangeStrategies strategies()
Return the strategies used to convert the body of this response.
body
<T> T body(BodyExtractor<T,? super ClientHttpResponse> extractor)
Extract the body with the givenBodyExtractor.- 类型参数:
T- the type of the body returned- 参数:
extractor- theBodyExtractorthat reads from the response- 返回:
- the extracted body
bodyToMono
<T> reactor.core.publisher.Mono<T> bodyToMono(Class<? extends T> elementClass)
Extract the body to aMono.- 类型参数:
T- the element type- 参数:
elementClass- the class of element in theMono- 返回:
- a mono containing the body of the given type
T
bodyToMono
<T> reactor.core.publisher.Mono<T> bodyToMono(ParameterizedTypeReference<T> elementTypeRef)
Extract the body to aMono.- 类型参数:
T- the element type- 参数:
elementTypeRef- the type reference of element in theMono- 返回:
- a mono containing the body of the given type
T
bodyToFlux
<T> reactor.core.publisher.Flux<T> bodyToFlux(Class<? extends T> elementClass)
Extract the body to aFlux.- 类型参数:
T- the element type- 参数:
elementClass- the class of elements in theFlux- 返回:
- a flux containing the body of the given type
T
bodyToFlux
<T> reactor.core.publisher.Flux<T> bodyToFlux(ParameterizedTypeReference<T> elementTypeRef)
Extract the body to aFlux.- 类型参数:
T- the element type- 参数:
elementTypeRef- the type reference of elements in theFlux- 返回:
- a flux containing the body of the given type
T
releaseBody
reactor.core.publisher.Mono<Void> releaseBody()
Release the body of this response.- 返回:
- a completion signal
- 从以下版本开始:
- 5.2
- 另请参阅:
DataBufferUtils.release(DataBuffer)
toEntity
<T> reactor.core.publisher.Mono<ResponseEntity<T>> toEntity(Class<T> bodyClass)
Return this response as a delayedResponseEntity.- 类型参数:
T- response body type- 参数:
bodyClass- the expected response body type- 返回:
Monowith theResponseEntity
toEntity
<T> reactor.core.publisher.Mono<ResponseEntity<T>> toEntity(ParameterizedTypeReference<T> bodyTypeReference)
Return this response as a delayedResponseEntity.- 类型参数:
T- response body type- 参数:
bodyTypeReference- a type reference describing the expected response body type- 返回:
Monowith theResponseEntity
toEntityList
<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>> toEntityList(Class<T> elementClass)
Return this response as a delayed list ofResponseEntitys.- 类型参数:
T- the type of elements in the list- 参数:
elementClass- the expected response body list element class- 返回:
Monowith the list ofResponseEntitys
toEntityList
<T> reactor.core.publisher.Mono<ResponseEntity<List<T>>> toEntityList(ParameterizedTypeReference<T> elementTypeRef)
Return this response as a delayed list ofResponseEntitys.- 类型参数:
T- the type of elements in the list- 参数:
elementTypeRef- the expected response body list element reference type- 返回:
Monowith the list ofResponseEntitys
toBodilessEntity
reactor.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.- 返回:
Monowith the bodilessResponseEntity- 从以下版本开始:
- 5.2
createException
reactor.core.publisher.Mono<WebClientResponseException> createException()
Create aWebClientResponseExceptionthat contains the response status, headers, body, and the originating request.- 返回:
- a
Monowith the created exception - 从以下版本开始:
- 5.2
logPrefix
String 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 "]".- 返回:
- the log message prefix or an empty String if the
LOG_ID_ATTRIBUTEis not set - 从以下版本开始:
- 5.2.3
from
static ClientResponse.Builder from(ClientResponse other)
Create a builder with the status, headers, and cookies of the given response.- 参数:
other- the response to copy the status, headers, and cookies from- 返回:
- the created builder
create
static ClientResponse.Builder create(HttpStatus statusCode)
Create a response builder with the given status code and using default strategies for reading the body.- 参数:
statusCode- the status code- 返回:
- the created builder
create
static ClientResponse.Builder create(HttpStatus statusCode, ExchangeStrategies strategies)
Create a response builder with the given status code and strategies for reading the body.- 参数:
statusCode- the status codestrategies- the strategies- 返回:
- the created builder
create
static ClientResponse.Builder create(int statusCode, ExchangeStrategies strategies)
Create a response builder with the given raw status code and strategies for reading the body.- 参数:
statusCode- the status codestrategies- the strategies- 返回:
- the created builder
- 从以下版本开始:
- 5.1.9
create
static ClientResponse.Builder create(HttpStatus statusCode, List<HttpMessageReader<?>> messageReaders)
Create a response builder with the given status code and message body readers.- 参数:
statusCode- the status codemessageReaders- the message readers- 返回:
- the created builder