diff options
author | jonmv <venstad@gmail.com> | 2022-05-03 07:32:02 +0200 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2022-05-03 07:32:02 +0200 |
commit | 6872505203d96295c1cdfe0c108daab554d64928 (patch) | |
tree | 089155348b1b69f606ef1681e380402db119b090 /http-client | |
parent | 3592e408848787f75e721bf2d6f99f3f010f6610 (diff) |
Revert "Merge pull request #22393 from vespa-engine/revert-22386-jonmv/remove-last-controller-jersey-client"
This reverts commit 04898b34190a3e3bb9d3053e11eb892bc48ff842, reversing
changes made to 3a757528a0a978d44cb1bd9aae28b567c477d139.
Diffstat (limited to 'http-client')
-rw-r--r-- | http-client/src/main/java/ai/vespa/hosted/client/AbstractHttpClient.java | 4 | ||||
-rw-r--r-- | http-client/src/main/java/ai/vespa/hosted/client/HttpClient.java | 15 |
2 files changed, 15 insertions, 4 deletions
diff --git a/http-client/src/main/java/ai/vespa/hosted/client/AbstractHttpClient.java b/http-client/src/main/java/ai/vespa/hosted/client/AbstractHttpClient.java index 6a76ef65082..ed3fee101ed 100644 --- a/http-client/src/main/java/ai/vespa/hosted/client/AbstractHttpClient.java +++ b/http-client/src/main/java/ai/vespa/hosted/client/AbstractHttpClient.java @@ -147,10 +147,10 @@ public abstract class AbstractHttpClient implements HttpClient { private final Method method; private final HostStrategy hosts; + private final List<Supplier<Query>> dynamicQuery = new ArrayList<>(); + private final Map<String, List<String>> headers = new LinkedHashMap<>(); private HttpURL.Path path = Path.empty(); private HttpURL.Query query = Query.empty(); - private List<Supplier<Query>> dynamicQuery = new ArrayList<>(); - private Map<String, List<String>> headers = new LinkedHashMap<>(); private Supplier<HttpEntity> entity = () -> null; private RequestConfig config = HttpClient.defaultRequestConfig; private ResponseVerifier verifier = HttpClient.throwOnError; diff --git a/http-client/src/main/java/ai/vespa/hosted/client/HttpClient.java b/http-client/src/main/java/ai/vespa/hosted/client/HttpClient.java index 16a419bf324..ea8328ed793 100644 --- a/http-client/src/main/java/ai/vespa/hosted/client/HttpClient.java +++ b/http-client/src/main/java/ai/vespa/hosted/client/HttpClient.java @@ -226,7 +226,8 @@ public interface HttpClient extends Closeable { @Override default RuntimeException toException(int statusCode, byte[] body, ClassicHttpRequest request) { - return new ResponseException(request + " failed with status " + statusCode + " and body '" + new String(body, UTF_8) + "'"); + return new ResponseException(statusCode, + request + " failed with status " + statusCode + " and body '" + new String(body, UTF_8) + "'"); } } @@ -249,6 +250,11 @@ public interface HttpClient extends Closeable { @FunctionalInterface interface HostStrategy extends Iterable<URI> { + /** Attempts the given host once. */ + static HostStrategy of(URI host) { + return repeating(host, 1); + } + /** Attempts each request once against each listed host. */ static HostStrategy ordered(List<URI> hosts) { return List.copyOf(hosts)::iterator; @@ -292,10 +298,15 @@ public interface HttpClient extends Closeable { /** An exception due to server error, a bad request, or similar, which resulted in a non-OK HTTP response. */ class ResponseException extends RuntimeException { - public ResponseException(String message) { + private final int statusCode; + + public ResponseException(int statusCode, String message) { super(message); + this.statusCode = statusCode; } + public int statusCode() { return statusCode; } + } }
\ No newline at end of file |