From 904813dd6f8362f2d7aae87bad164108b3a42004 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Thu, 21 Nov 2019 15:31:39 +0100 Subject: [PATCH] WIP: WebClient --- .../de/juplo/facebook/errors/GraphApiException.java | 12 +++++------- .../errors/GraphApiExchangeFilterFunction.java | 2 +- ...raphApiExchangeFilterFunctionIntegrationTest.java | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/juplo/facebook/errors/GraphApiException.java b/src/main/java/de/juplo/facebook/errors/GraphApiException.java index 3ebc64f..a696f6e 100644 --- a/src/main/java/de/juplo/facebook/errors/GraphApiException.java +++ b/src/main/java/de/juplo/facebook/errors/GraphApiException.java @@ -8,15 +8,12 @@ import com.fasterxml.jackson.databind.SerializationFeature; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.function.Supplier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; -import org.springframework.http.ReactiveHttpInputMessage; -import org.springframework.web.reactive.function.BodyExtractor; -import org.springframework.web.reactive.function.BodyExtractor.Context; import org.springframework.web.reactive.function.client.ClientResponse; -import reactor.core.publisher.Mono; @@ -48,14 +45,15 @@ public class GraphApiException extends RuntimeException - public static Mono create(ClientResponse response) + public static Supplier create(ClientResponse response) { HttpStatus status = response.statusCode(); HttpHeaders headers = response.headers().asHttpHeaders(); return - response + () -> response .bodyToMono(InputStream.class) - .map(is -> create(status , headers, is)); + .map(is -> create(status , headers, is)) + .block(); } public static GraphApiException create( diff --git a/src/main/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunction.java b/src/main/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunction.java index 6642e38..53bdd0b 100644 --- a/src/main/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunction.java +++ b/src/main/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunction.java @@ -35,7 +35,7 @@ public class GraphApiExchangeFilterFunction implements ExchangeFilterFunction { return HttpStatus.Series.CLIENT_ERROR.equals(response.statusCode().series()) - ? Mono.error(GraphApiException.create(response).block()) + ? Mono.error(GraphApiException.create(response)) : Mono.just(response); }); } diff --git a/src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java b/src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java index b90e057..c468590 100644 --- a/src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java +++ b/src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java @@ -103,7 +103,7 @@ public class GraphApiExchangeFilterFunctionIntegrationTest .filter((request, next) -> next.exchange(request).flatMap(response -> { List headerValues = response.headers().header("Foo"); - return headerValues.isEmpty() ? Mono.error(GraphApiException.create(response).block()) : + return headerValues.isEmpty() ? Mono.error(GraphApiException.create(response)) : Mono.just(response); })) .build(); -- 2.20.1