summaryrefslogtreecommitdiffstats
path: root/tenant-cd
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2019-08-21 14:01:01 +0200
committerJon Marius Venstad <venstad@gmail.com>2019-08-21 14:01:01 +0200
commit2b3e7d2cdf3869bb765ee64013e6721164bcdef5 (patch)
tree2a9ad9f616bdd989e1e2e4fda3cde8806544ea25 /tenant-cd
parent6a06c69162529273a386cd2a9c4cbac87eacce03 (diff)
Expand Endpoint with a request builder method
Diffstat (limited to 'tenant-cd')
-rw-r--r--tenant-cd/src/main/java/ai/vespa/hosted/cd/Endpoint.java11
-rw-r--r--tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java9
2 files changed, 20 insertions, 0 deletions
diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/Endpoint.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/Endpoint.java
index fa6422d80e6..5d3644e3358 100644
--- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/Endpoint.java
+++ b/tenant-cd/src/main/java/ai/vespa/hosted/cd/Endpoint.java
@@ -7,7 +7,12 @@ import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.Map;
+import java.util.stream.Collectors;
+import static java.net.URLEncoder.encode;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
@@ -28,6 +33,12 @@ public interface Endpoint {
return send(request, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
}
+ /** Creates a request against the endpoint, with the given path and properties. */
+ HttpRequest.Builder request(String path, Map<String, String> properties);
+ /** Creates a request against the endpoint, with the given path. */
+ default HttpRequest.Builder request(String path) {
+ return request(path, Collections.emptyMap());
+ }
}
diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java
index a3f1b90f5d4..43ef179174b 100644
--- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java
+++ b/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java
@@ -9,7 +9,10 @@ import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
+import java.util.Map;
+import java.util.stream.Collectors;
+import static java.net.URLEncoder.encode;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
@@ -50,5 +53,11 @@ public class HttpEndpoint implements Endpoint {
}
@Override
+ public HttpRequest.Builder request(String path, Map<String, String> properties) {
+ return HttpRequest.newBuilder(endpoint.resolve(path +
+ properties.entrySet().stream()
+ .map(entry -> encode(entry.getKey(), UTF_8) + "=" + encode(entry.getValue(), UTF_8))
+ .collect(Collectors.joining("&", "?", ""))));
+ }
}