From 2ee955aa31aac3dff18457f032fce4ed15049cd2 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Fri, 22 Nov 2019 07:25:03 +0100 Subject: [PATCH] WIP: WebClient --- .../GraphApiExchangeFilterFunction.java | 11 +++++ ...ExchangeFilterFunctionIntegrationTest.java | 42 +++++++++++-------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/main/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunction.java b/src/main/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunction.java index 6ab18b6..34ca5a7 100644 --- a/src/main/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunction.java +++ b/src/main/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunction.java @@ -6,6 +6,7 @@ import org.springframework.web.reactive.function.client.ClientRequest; import org.springframework.web.reactive.function.client.ClientResponse; import org.springframework.web.reactive.function.client.ExchangeFilterFunction; import org.springframework.web.reactive.function.client.ExchangeFunction; +import org.springframework.web.reactive.function.client.WebClientResponseException; import reactor.core.publisher.Mono; @@ -31,6 +32,16 @@ public class GraphApiExchangeFilterFunction implements ExchangeFilterFunction response.statusCode(), response.headers().asHttpHeaders(), errorBody.getBytes())) + .map(e -> + e.getClass().equals(ErrorResponseParsingErrorException.class) + ? WebClientResponseException + .create( + e.getStatus().value(), + e.getStatus().getReasonPhrase(), + e.getHeaders(), + null, + null) + : e) .flatMap(e -> Mono.error(e)) : 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 9faae0f..53b2e6a 100644 --- a/src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java +++ b/src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java @@ -59,24 +59,24 @@ public class GraphApiExchangeFilterFunctionIntegrationTest Mono result; - server - .enqueue(new MockResponse() - .setResponseCode(HttpStatus.CONTINUE.value()) - .setHeader("Content-Type", "application/json") - .setBody("Hallo Welt!")); - - result = - webClient - .get() - .uri("/egal") - .retrieve() - .bodyToMono(String.class); - - StepVerifier - .create(result) - .expectNext("Hallo Welt!") - .expectComplete() - .verify(); + //server + // .enqueue(new MockResponse() + // .setResponseCode(HttpStatus.CONTINUE.value()) + // .setHeader("Content-Type", "application/json") + // .setBody("Hallo Welt!")); + // + //result = + // webClient + // .get() + // .uri("/egal") + // .retrieve() + // .bodyToMono(String.class); + // + //StepVerifier + // .create(result) + // .expectNext("Hallo Welt!") + // .expectComplete() + // .verify(); server @@ -102,6 +102,12 @@ public class GraphApiExchangeFilterFunctionIntegrationTest server .enqueue(new MockResponse() .setResponseCode(HttpStatus.TEMPORARY_REDIRECT.value()) + .setHeader("Location", server.url("/woanders")) + .setHeader("Content-Type", "text/plain") + .setBody("Jetzt doch woanders...")); + server + .enqueue(new MockResponse() + .setResponseCode(HttpStatus.OK.value()) .setHeader("Content-Type", "text/plain") .setBody("Hallo Welt!")); -- 2.20.1