|
|
@ -17,6 +17,7 @@ |
|
|
|
package org.springframework.web.reactive.function.client; |
|
|
|
package org.springframework.web.reactive.function.client; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.function.Predicate; |
|
|
|
|
|
|
|
|
|
|
|
import org.reactivestreams.Publisher; |
|
|
|
import org.reactivestreams.Publisher; |
|
|
|
import reactor.core.publisher.Flux; |
|
|
|
import reactor.core.publisher.Flux; |
|
|
@ -26,7 +27,8 @@ import org.springframework.core.codec.CodecException; |
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
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 |
|
|
|
* @author Arjen Poutsma |
|
|
|
* @since 5.2 |
|
|
|
* @since 5.2 |
|
|
@ -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"; |
|
|
|
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>}. |
|
|
|
* Map the given response to a single value {@code ResponseEntity<T>}. |
|
|
@ -42,9 +50,10 @@ abstract class WebClientUtils { |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
public static <T> Mono<ResponseEntity<T>> mapToEntity(ClientResponse response, Mono<T> bodyMono) { |
|
|
|
public static <T> Mono<ResponseEntity<T>> mapToEntity(ClientResponse response, Mono<T> bodyMono) { |
|
|
|
return ((Mono<Object>) bodyMono).defaultIfEmpty(VALUE_NONE).map(body -> |
|
|
|
return ((Mono<Object>) bodyMono).defaultIfEmpty(VALUE_NONE).map(body -> |
|
|
|
ResponseEntity.status(response.rawStatusCode()) |
|
|
|
new ResponseEntity<>( |
|
|
|
.headers(response.headers().asHttpHeaders()) |
|
|
|
body != VALUE_NONE ? (T) body : null, |
|
|
|
.body(body != VALUE_NONE ? (T) body : null)); |
|
|
|
response.headers().asHttpHeaders(), |
|
|
|
|
|
|
|
response.rawStatusCode())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -52,15 +61,7 @@ abstract class WebClientUtils { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static <T> Mono<ResponseEntity<List<T>>> mapToEntityList(ClientResponse response, Publisher<T> body) { |
|
|
|
public static <T> Mono<ResponseEntity<List<T>>> mapToEntityList(ClientResponse response, Publisher<T> body) { |
|
|
|
return Flux.from(body).collectList().map(list -> |
|
|
|
return Flux.from(body).collectList().map(list -> |
|
|
|
ResponseEntity.status(response.rawStatusCode()) |
|
|
|
new ResponseEntity<>(list, response.headers().asHttpHeaders(), response.rawStatusCode())); |
|
|
|
.headers(response.headers().asHttpHeaders()) |
|
|
|
|
|
|
|
.body(list)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Indicates whether the given exception should be wrapped. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static boolean shouldWrapException(Throwable t) { |
|
|
|
|
|
|
|
return !(t instanceof WebClientException) && !(t instanceof CodecException); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|