From 1b73b599b23921b3412d60ed231de1ef8ac90dbb Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Sat, 8 Feb 2020 14:16:15 -0500 Subject: Add headers to asynchronous get in HttpClient Issue-ID: POLICY-1625 Signed-off-by: Jim Hahn Change-Id: I61ef2fcfde5eb361652d2d6e3f55324af7ca7b4e --- .../endpoints/http/client/internal/JerseyClient.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/internal/JerseyClient.java') diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/internal/JerseyClient.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/internal/JerseyClient.java index 1a822ff2..38ec6829 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/internal/JerseyClient.java +++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/internal/JerseyClient.java @@ -26,6 +26,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; +import java.util.Collections; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.Future; @@ -171,17 +172,23 @@ public class JerseyClient implements HttpClient { } @Override - public Future get(InvocationCallback callback, String path) { + public Future get(InvocationCallback callback, String path, Map headers) { + Map headers2 = (headers != null ? headers : Collections.emptyMap()); + if (!StringUtils.isBlank(path)) { - return this.client.target(this.baseUrl).path(path).request().async().get(callback); + return getBuilder(path, headers2).async().get(callback); } else { - return this.client.target(this.baseUrl).request().async().get(callback); + return get(callback, headers2); } } @Override - public Future get(InvocationCallback callback) { - return this.client.target(this.baseUrl).request().async().get(callback); + public Future get(InvocationCallback callback, Map headers) { + Builder builder = this.client.target(this.baseUrl).request(); + if (headers != null) { + headers.forEach(builder::header); + } + return builder.async().get(callback); } @Override -- cgit 1.2.3-korg