diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientResponse.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientResponse.java index a8359f607f2..7e98dc52bb5 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientResponse.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientResponse.java @@ -166,7 +166,6 @@ public interface ClientResponse { /** * Creates a {@link WebClientResponseException} based on the status code, * headers, and body of this response as well as the corresponding request. - * * @return a {@code Mono} with a {@code WebClientResponseException} based on this response * @since 5.2 */ diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponse.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponse.java index c15406bd2bf..395f785be88 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponse.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponse.java @@ -190,10 +190,12 @@ class DefaultClientResponse implements ClientResponse { Charset charset = headers().contentType() .map(MimeType::getCharset) .orElse(StandardCharsets.ISO_8859_1); - if (HttpStatus.resolve(rawStatusCode()) != null) { + int statusCode = rawStatusCode(); + HttpStatus httpStatus = HttpStatus.resolve(statusCode); + if (httpStatus != null) { return WebClientResponseException.create( - statusCode().value(), - statusCode().getReasonPhrase(), + statusCode, + httpStatus.getReasonPhrase(), headers().asHttpHeaders(), bodyBytes, charset, @@ -201,7 +203,7 @@ class DefaultClientResponse implements ClientResponse { } else { return new UnknownHttpStatusCodeException( - rawStatusCode(), + statusCode, headers().asHttpHeaders(), bodyBytes, charset, diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponseBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponseBuilder.java index 352c98b56cc..d1938b40c63 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponseBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponseBuilder.java @@ -64,6 +64,7 @@ final class DefaultClientResponseBuilder implements ClientResponse.Builder { } }; + private ExchangeStrategies strategies; private HttpStatus statusCode = HttpStatus.OK; @@ -167,13 +168,11 @@ final class DefaultClientResponseBuilder implements ClientResponse.Builder { @Override public ClientResponse build() { - ClientHttpResponse httpResponse = new BuiltClientHttpResponse(this.statusCode, this.headers, this.cookies, this.body); // When building ClientResponse manually, the ClientRequest.logPrefix() has to be passed, // e.g. via ClientResponse.Builder, but this (builder) is not used currently. - return new DefaultClientResponse(httpResponse, this.strategies, "", "", () -> this.request); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java index de2aeb899e8..a4dbf26fa59 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java @@ -440,7 +440,7 @@ class DefaultWebClient implements WebClient { private static IntPredicate toIntPredicate(Predicate predicate) { return value -> { HttpStatus status = HttpStatus.resolve(value); - return (status != null) && predicate.test(status); + return (status != null && predicate.test(status)); }; } @@ -448,9 +448,8 @@ class DefaultWebClient implements WebClient { public ResponseSpec onRawStatus(IntPredicate statusCodePredicate, Function> exceptionFunction) { - Assert.notNull(statusCodePredicate, "StatusCodePredicate must not be null"); + Assert.notNull(statusCodePredicate, "IntPredicate must not be null"); Assert.notNull(exceptionFunction, "Function must not be null"); - this.statusHandlers.add(0, new StatusHandler(statusCodePredicate, exceptionFunction)); return this; } @@ -563,6 +562,7 @@ class DefaultWebClient implements WebClient { handleBodyFlux(response, response.bodyToFlux(elementTypeRef)))); } + private static class StatusHandler { private final IntPredicate predicate; @@ -583,7 +583,6 @@ class DefaultWebClient implements WebClient { public Mono apply(ClientResponse response) { return this.exceptionFunction.apply(response); } - } } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java index 16e08df70a5..67b594df221 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java @@ -666,6 +666,7 @@ public interface WebClient { RequestHeadersSpec syncBody(Object body); } + /** * Contract for specifying response operations following the exchange. */ @@ -799,19 +800,18 @@ public interface WebClient { * @since 5.2 */ Mono>> toEntityList(ParameterizedTypeReference elementTypeRef); - } /** * Contract for specifying request headers and URI for a request. - * * @param a self reference to the spec type */ interface RequestHeadersUriSpec> extends UriSpec, RequestHeadersSpec { } + /** * Contract for specifying request headers, body and URI for a request. */