|
|
|
@ -17,6 +17,7 @@
@@ -17,6 +17,7 @@
|
|
|
|
|
package org.springframework.web.reactive.function.client; |
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.function.Predicate; |
|
|
|
|
|
|
|
|
|
import org.reactivestreams.Publisher; |
|
|
|
|
import reactor.core.publisher.Flux; |
|
|
|
@ -26,7 +27,8 @@ import org.springframework.core.codec.CodecException;
@@ -26,7 +27,8 @@ import org.springframework.core.codec.CodecException;
|
|
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Internal methods shared between {@link DefaultWebClient} and {@link DefaultClientResponse}. |
|
|
|
|
* Internal methods shared between {@link DefaultWebClient} and |
|
|
|
|
* {@link DefaultClientResponse}. |
|
|
|
|
* |
|
|
|
|
* @author Arjen Poutsma |
|
|
|
|
* @since 5.2 |
|
|
|
@ -35,6 +37,12 @@ abstract class WebClientUtils {
@@ -35,6 +37,12 @@ abstract class WebClientUtils {
|
|
|
|
|
|
|
|
|
|
private static final String VALUE_NONE = "\n\t\t\n\t\t\n\uE000\uE001\uE002\n\t\t\t\t\n"; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Predicate that returns true if an exception should be wrapped. |
|
|
|
|
*/ |
|
|
|
|
public final static Predicate<? super Throwable> WRAP_EXCEPTION_PREDICATE = |
|
|
|
|
t -> !(t instanceof WebClientException) && !(t instanceof CodecException); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Map the given response to a single value {@code ResponseEntity<T>}. |
|
|
|
@ -42,9 +50,10 @@ abstract class WebClientUtils {
@@ -42,9 +50,10 @@ abstract class WebClientUtils {
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
public static <T> Mono<ResponseEntity<T>> mapToEntity(ClientResponse response, Mono<T> bodyMono) { |
|
|
|
|
return ((Mono<Object>) bodyMono).defaultIfEmpty(VALUE_NONE).map(body -> |
|
|
|
|
ResponseEntity.status(response.rawStatusCode()) |
|
|
|
|
.headers(response.headers().asHttpHeaders()) |
|
|
|
|
.body(body != VALUE_NONE ? (T) body : null)); |
|
|
|
|
new ResponseEntity<>( |
|
|
|
|
body != VALUE_NONE ? (T) body : null, |
|
|
|
|
response.headers().asHttpHeaders(), |
|
|
|
|
response.rawStatusCode())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -52,15 +61,7 @@ abstract class WebClientUtils {
@@ -52,15 +61,7 @@ abstract class WebClientUtils {
|
|
|
|
|
*/ |
|
|
|
|
public static <T> Mono<ResponseEntity<List<T>>> mapToEntityList(ClientResponse response, Publisher<T> body) { |
|
|
|
|
return Flux.from(body).collectList().map(list -> |
|
|
|
|
ResponseEntity.status(response.rawStatusCode()) |
|
|
|
|
.headers(response.headers().asHttpHeaders()) |
|
|
|
|
.body(list)); |
|
|
|
|
new ResponseEntity<>(list, response.headers().asHttpHeaders(), response.rawStatusCode())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Indicates whether the given exception should be wrapped. |
|
|
|
|
*/ |
|
|
|
|
public static boolean shouldWrapException(Throwable t) { |
|
|
|
|
return !(t instanceof WebClientException) && !(t instanceof CodecException); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|