Add ResponseSpec#toEntityFlux overload with BodyExtractor

See gh-26114
This commit is contained in:
Spindler, Justin
2020-11-18 10:50:57 -05:00
committed by Rossen Stoyanchev
parent 05e3f271b6
commit 922d5d271a
4 changed files with 56 additions and 1 deletions

View File

@@ -43,11 +43,13 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
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.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.BodyInserter;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.util.UriBuilder;
@@ -599,6 +601,12 @@ class DefaultWebClient implements WebClient {
handlerEntityFlux(response, response.bodyToFlux(elementTypeRef)));
}
@Override
public <T> Mono<ResponseEntity<Flux<T>>> toEntityFlux(BodyExtractor<Flux<T>, ? super ClientHttpResponse> bodyExtractor) {
return this.responseMono.flatMap(response ->
handlerEntityFlux(response, response.body(bodyExtractor)));
}
@Override
public Mono<ResponseEntity<Void>> toBodilessEntity() {
return this.responseMono.flatMap(response ->

View File

@@ -40,8 +40,10 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.reactive.ClientHttpConnector;
import org.springframework.http.client.reactive.ClientHttpRequest;
import org.springframework.http.client.reactive.ClientHttpResponse;
import org.springframework.http.codec.ClientCodecConfigurer;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.BodyInserter;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.util.DefaultUriBuilderFactory;
@@ -889,7 +891,7 @@ public interface WebClient {
<T> Mono<ResponseEntity<Flux<T>>> toEntityFlux(Class<T> elementType);
/**
* Variant of {@link #toEntity(Class)} with a {@link ParameterizedTypeReference}.
* Variant of {@link #toEntityFlux(Class)} with a {@link ParameterizedTypeReference}.
* @param elementTypeReference the type of element to decode the target Flux to
* @param <T> the body element type
* @return the {@code ResponseEntity}
@@ -897,6 +899,15 @@ public interface WebClient {
*/
<T> Mono<ResponseEntity<Flux<T>>> toEntityFlux(ParameterizedTypeReference<T> elementTypeReference);
/**
* Variant of {@link #toEntityFlux(Class)} with a {@link BodyExtractor}.
* @param bodyExtractor the {@code BodyExtractor} that reads from the response
* @param <T> the body element type
* @return the {@code ResponseEntity}
* @since 5.3.2
*/
<T> Mono<ResponseEntity<Flux<T>>> toEntityFlux(BodyExtractor<Flux<T>, ? super ClientHttpResponse> bodyExtractor);
/**
* Return a {@code ResponseEntity} without a body. For an error response
* (status code of 4xx or 5xx), the {@code Mono} emits a