From 729d0d27968176e2d0b4ff00dfec334219210f61 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 23 Mar 2018 22:21:06 -0400 Subject: [PATCH] Property handling of Void.class in WebClient retrieve() Issue: SPR-16636 --- .../function/client/DefaultWebClient.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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 d59600eb84a..fe61b4eaee8 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 @@ -42,14 +42,12 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.client.reactive.ClientHttpRequest; -import org.springframework.http.client.reactive.ClientHttpResponse; import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MimeType; import org.springframework.util.MultiValueMap; -import org.springframework.web.reactive.function.BodyExtractor; import org.springframework.web.reactive.function.BodyExtractors; import org.springframework.web.reactive.function.BodyInserter; import org.springframework.web.reactive.function.BodyInserters; @@ -405,8 +403,9 @@ class DefaultWebClient implements WebClient { @Override @SuppressWarnings("unchecked") public Mono bodyToMono(Class bodyType) { + // Use bodyToMono (vs BodyExtractors) to ensure proper handling of Void.class... return this.responseMono.flatMap( - response -> bodyToPublisher(response, BodyExtractors.toMono(bodyType), + response -> bodyToPublisher(response, response.bodyToMono(bodyType), this::monoThrowableToMono)); } @@ -414,7 +413,7 @@ class DefaultWebClient implements WebClient { @SuppressWarnings("unchecked") public Mono bodyToMono(ParameterizedTypeReference typeReference) { return this.responseMono.flatMap( - response -> bodyToPublisher(response, BodyExtractors.toMono(typeReference), + response -> bodyToPublisher(response, response.bodyToMono(typeReference), this::monoThrowableToMono)); } @@ -425,14 +424,14 @@ class DefaultWebClient implements WebClient { @Override public Flux bodyToFlux(Class elementType) { return this.responseMono.flatMapMany( - response -> bodyToPublisher(response, BodyExtractors.toFlux(elementType), + response -> bodyToPublisher(response, response.bodyToFlux(elementType), this::monoThrowableToFlux)); } @Override public Flux bodyToFlux(ParameterizedTypeReference typeReference) { return this.responseMono.flatMapMany( - response -> bodyToPublisher(response, BodyExtractors.toFlux(typeReference), + response -> bodyToPublisher(response, response.bodyToFlux(typeReference), this::monoThrowableToFlux)); } @@ -441,15 +440,14 @@ class DefaultWebClient implements WebClient { } private > T bodyToPublisher(ClientResponse response, - BodyExtractor extractor, - Function, T> errorFunction) { + T bodyPublisher, Function, T> errorFunction) { return this.statusHandlers.stream() .filter(statusHandler -> statusHandler.test(response.statusCode())) .findFirst() .map(statusHandler -> statusHandler.apply(response)) .map(errorFunction::apply) - .orElse(response.body(extractor)); + .orElse(bodyPublisher); } private static Mono createResponseException(ClientResponse response) {