summaryrefslogtreecommitdiffstats
path: root/http-client
diff options
context:
space:
mode:
authorJon Marius Venstad <jonmv@users.noreply.github.com>2022-05-02 21:08:17 +0200
committerGitHub <noreply@github.com>2022-05-02 21:08:17 +0200
commit6058f5f8d2ed19ca3c0461e7080680a093834823 (patch)
tree3e09032c623789406abfa2d42ea74b7064cb7087 /http-client
parent04898b34190a3e3bb9d3053e11eb892bc48ff842 (diff)
Revert "Jonmv/remove last controller jersey client [run-systemtest]"
Diffstat (limited to 'http-client')
-rw-r--r--http-client/src/main/java/ai/vespa/hosted/client/AbstractHttpClient.java15
-rw-r--r--http-client/src/main/java/ai/vespa/hosted/client/HttpClient.java8
2 files changed, 9 insertions, 14 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..68741d6d509 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
@@ -79,9 +79,9 @@ public abstract class AbstractHttpClient implements HttpClient {
.asURI())
.build();
builder.headers.forEach((name, values) -> values.forEach(value -> request.setHeader(name, value)));
+ request.setEntity(builder.entity);
- try (HttpEntity entity = builder.entity.get()) {
- request.setEntity(entity);
+ try {
try {
return handler.apply(execute(request, contextWithTimeout(builder)), request);
}
@@ -90,15 +90,16 @@ public abstract class AbstractHttpClient implements HttpClient {
throw RetryException.wrap(e, request);
}
}
- catch (IOException e) {
- throw new UncheckedIOException("failed closing request entity", e);
- }
catch (RetryException e) {
if (thrown == null)
thrown = e.getCause();
else
thrown.addSuppressed(e.getCause());
+ if (builder.entity != null && ! builder.entity.isRepeatable()) {
+ log.log(WARNING, "Cannot retry " + request + " as entity is not repeatable");
+ break;
+ }
log.log(FINE, e.getCause(), () -> request + " failed; will retry");
}
}
@@ -151,7 +152,7 @@ public abstract class AbstractHttpClient implements HttpClient {
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 HttpEntity entity;
private RequestConfig config = HttpClient.defaultRequestConfig;
private ResponseVerifier verifier = HttpClient.throwOnError;
private ExceptionHandler catcher = HttpClient.retryAll;
@@ -177,7 +178,7 @@ public abstract class AbstractHttpClient implements HttpClient {
}
@Override
- public RequestBuilder body(Supplier<HttpEntity> entity) {
+ public RequestBuilder body(HttpEntity entity) {
this.entity = requireNonNull(entity);
return this;
}
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..b41b16c25be 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
@@ -78,13 +78,7 @@ public interface HttpClient extends Closeable {
RequestBuilder body(byte[] json);
/** Sets the request body. */
- default RequestBuilder body(HttpEntity entity) {
- if (entity.isRepeatable()) return body(() -> entity);
- throw new IllegalArgumentException("entitiy must be repeatable, or a supplier must be used");
- }
-
- /** Sets the request body. */
- RequestBuilder body(Supplier<HttpEntity> entity);
+ RequestBuilder body(HttpEntity entity);
/** Sets query parameters without a value, like {@code ?debug&recursive}. */
default RequestBuilder emptyParameters(String... keys) {