Skip to content

Commit 22e87ac

Browse files
committed
Polishing
1 parent cc57506 commit 22e87ac

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientResponse.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ public interface ClientResponse {
166166
/**
167167
* Creates a {@link WebClientResponseException} based on the status code,
168168
* headers, and body of this response as well as the corresponding request.
169-
*
170169
* @return a {@code Mono} with a {@code WebClientResponseException} based on this response
171170
* @since 5.2
172171
*/

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponse.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,20 @@ public Mono<WebClientResponseException> createException() {
190190
Charset charset = headers().contentType()
191191
.map(MimeType::getCharset)
192192
.orElse(StandardCharsets.ISO_8859_1);
193-
if (HttpStatus.resolve(rawStatusCode()) != null) {
193+
int statusCode = rawStatusCode();
194+
HttpStatus httpStatus = HttpStatus.resolve(statusCode);
195+
if (httpStatus != null) {
194196
return WebClientResponseException.create(
195-
statusCode().value(),
196-
statusCode().getReasonPhrase(),
197+
statusCode,
198+
httpStatus.getReasonPhrase(),
197199
headers().asHttpHeaders(),
198200
bodyBytes,
199201
charset,
200202
request);
201203
}
202204
else {
203205
return new UnknownHttpStatusCodeException(
204-
rawStatusCode(),
206+
statusCode,
205207
headers().asHttpHeaders(),
206208
bodyBytes,
207209
charset,

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponseBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public HttpHeaders getHeaders() {
6464
}
6565
};
6666

67+
6768
private ExchangeStrategies strategies;
6869

6970
private HttpStatus statusCode = HttpStatus.OK;
@@ -167,13 +168,11 @@ public ClientResponse.Builder request(HttpRequest request) {
167168

168169
@Override
169170
public ClientResponse build() {
170-
171171
ClientHttpResponse httpResponse =
172172
new BuiltClientHttpResponse(this.statusCode, this.headers, this.cookies, this.body);
173173

174174
// When building ClientResponse manually, the ClientRequest.logPrefix() has to be passed,
175175
// e.g. via ClientResponse.Builder, but this (builder) is not used currently.
176-
177176
return new DefaultClientResponse(httpResponse, this.strategies, "", "", () -> this.request);
178177
}
179178

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,17 +440,16 @@ public ResponseSpec onStatus(Predicate<HttpStatus> statusPredicate,
440440
private static IntPredicate toIntPredicate(Predicate<HttpStatus> predicate) {
441441
return value -> {
442442
HttpStatus status = HttpStatus.resolve(value);
443-
return (status != null) && predicate.test(status);
443+
return (status != null && predicate.test(status));
444444
};
445445
}
446446

447447
@Override
448448
public ResponseSpec onRawStatus(IntPredicate statusCodePredicate,
449449
Function<ClientResponse, Mono<? extends Throwable>> exceptionFunction) {
450450

451-
Assert.notNull(statusCodePredicate, "StatusCodePredicate must not be null");
451+
Assert.notNull(statusCodePredicate, "IntPredicate must not be null");
452452
Assert.notNull(exceptionFunction, "Function must not be null");
453-
454453
this.statusHandlers.add(0, new StatusHandler(statusCodePredicate, exceptionFunction));
455454
return this;
456455
}
@@ -563,6 +562,7 @@ public <T> Mono<ResponseEntity<List<T>>> toEntityList(ParameterizedTypeReference
563562
handleBodyFlux(response, response.bodyToFlux(elementTypeRef))));
564563
}
565564

565+
566566
private static class StatusHandler {
567567

568568
private final IntPredicate predicate;
@@ -583,7 +583,6 @@ public boolean test(int status) {
583583
public Mono<? extends Throwable> apply(ClientResponse response) {
584584
return this.exceptionFunction.apply(response);
585585
}
586-
587586
}
588587
}
589588

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ <T, P extends Publisher<T>> RequestHeadersSpec<?> body(P publisher,
666666
RequestHeadersSpec<?> syncBody(Object body);
667667
}
668668

669+
669670
/**
670671
* Contract for specifying response operations following the exchange.
671672
*/
@@ -799,19 +800,18 @@ ResponseSpec onRawStatus(IntPredicate statusCodePredicate,
799800
* @since 5.2
800801
*/
801802
<T> Mono<ResponseEntity<List<T>>> toEntityList(ParameterizedTypeReference<T> elementTypeRef);
802-
803803
}
804804

805805

806806
/**
807807
* Contract for specifying request headers and URI for a request.
808-
*
809808
* @param <S> a self reference to the spec type
810809
*/
811810
interface RequestHeadersUriSpec<S extends RequestHeadersSpec<S>>
812811
extends UriSpec<S>, RequestHeadersSpec<S> {
813812
}
814813

814+
815815
/**
816816
* Contract for specifying request headers, body and URI for a request.
817817
*/

0 commit comments

Comments
 (0)