From 56cc550460ab92f530bbfd37fd5f3bce228410c1 Mon Sep 17 00:00:00 2001 From: jpe7s Date: Fri, 30 Aug 2024 17:53:31 -0500 Subject: [PATCH] remove references to String http responses. --- .../sava/rpc/json/http/client/JsonHttpClient.java | 5 +++++ .../rpc/json/http/client/JsonResponseController.java | 11 ----------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/rpc/src/main/java/software/sava/rpc/json/http/client/JsonHttpClient.java b/rpc/src/main/java/software/sava/rpc/json/http/client/JsonHttpClient.java index d68b1a4..d9d4f8b 100644 --- a/rpc/src/main/java/software/sava/rpc/json/http/client/JsonHttpClient.java +++ b/rpc/src/main/java/software/sava/rpc/json/http/client/JsonHttpClient.java @@ -8,6 +8,7 @@ import java.net.http.HttpResponse; import java.time.Duration; import java.util.concurrent.CompletableFuture; +import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Predicate; @@ -49,6 +50,10 @@ protected static Function, R> applyResponse(final Funct return new JsonResponseController<>(adapter); } + protected static Function, R> applyResponse(final BiFunction adapter) { + return new KeepJsonResponseController<>(adapter); + } + protected Function, R> wrapParser(final Function, R> parser) { return applyResponse == null ? parser : response -> applyResponse.test(response) ? parser.apply(response) : null; } diff --git a/rpc/src/main/java/software/sava/rpc/json/http/client/JsonResponseController.java b/rpc/src/main/java/software/sava/rpc/json/http/client/JsonResponseController.java index f320c9f..b220013 100644 --- a/rpc/src/main/java/software/sava/rpc/json/http/client/JsonResponseController.java +++ b/rpc/src/main/java/software/sava/rpc/json/http/client/JsonResponseController.java @@ -17,10 +17,6 @@ static void logBody(final HttpResponse httpResponse, final RuntimeExcept logBody(httpResponse, new String(httpResponse.body()), ex); } - static void logStringBody(final HttpResponse httpResponse, final RuntimeException ex) { - logBody(httpResponse, httpResponse.body(), ex); - } - static void logBody(final HttpResponse httpResponse, final String body, final RuntimeException ex) { log.log(ERROR, String.format("Failed to parse [httpCode:%d], [body=%s]", httpResponse.statusCode(), body), @@ -32,13 +28,6 @@ static RuntimeException throwUncheckedIOException(final HttpResponse httpResp "HTTP request failed with [httpCode:%d], [body=%s]", httpResponse.statusCode(), body))); } - public static void checkStringResponseCode(final HttpResponse httpResponse) { - final int responseCode = httpResponse.statusCode(); - if (responseCode < 200 || responseCode >= 300) { - throw throwUncheckedIOException(httpResponse, httpResponse.body()); - } - } - public static void checkResponseCode(final HttpResponse httpResponse) { final int responseCode = httpResponse.statusCode(); if (responseCode < 200 || responseCode >= 300) {