diff options
author | Jim Hahn <jrh3@att.com> | 2020-03-02 19:13:16 -0500 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-03-02 19:36:36 -0500 |
commit | 2cc42ed9c8172a1ffeffb6cb25e1d5c5c36668af (patch) | |
tree | d6904cf38e55ef0729bd4fdee64689f0dbd527be /policy-endpoints/src/main/java | |
parent | d59c619324f5813127e5150e2b3fd5d446cf3a48 (diff) |
Provide access to HttpClient's WebTarget
Issue-ID: POLICY-2349
Signed-off-by: Jim Hahn <jrh3@att.com>
Change-Id: Iad10c3b6d77f859235c9e63f3fc0693bd9ba3c27
Diffstat (limited to 'policy-endpoints/src/main/java')
2 files changed, 18 insertions, 5 deletions
diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClient.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClient.java index 9e4e412f..49874843 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClient.java +++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClient.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.concurrent.Future; import javax.ws.rs.client.Entity; import javax.ws.rs.client.InvocationCallback; +import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Response; import org.onap.policy.common.capabilities.Startable; @@ -213,4 +214,10 @@ public interface HttpClient extends Startable { */ String getBaseUrl(); + /** + * Gets a web target associated with the base URL. + * + * @return a webtarget + */ + WebTarget getWebTarget(); } 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 38ec6829..c6a4fa41 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 @@ -36,6 +36,7 @@ import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Entity; import javax.ws.rs.client.Invocation.Builder; import javax.ws.rs.client.InvocationCallback; +import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Response; import org.apache.commons.lang3.StringUtils; import org.glassfish.jersey.client.ClientProperties; @@ -158,17 +159,22 @@ public class JerseyClient implements HttpClient { } @Override + public WebTarget getWebTarget() { + return this.client.target(this.baseUrl); + } + + @Override public Response get(String path) { if (!StringUtils.isBlank(path)) { - return this.client.target(this.baseUrl).path(path).request().get(); + return getWebTarget().path(path).request().get(); } else { - return this.client.target(this.baseUrl).request().get(); + return getWebTarget().request().get(); } } @Override public Response get() { - return this.client.target(this.baseUrl).request().get(); + return getWebTarget().request().get(); } @Override @@ -184,7 +190,7 @@ public class JerseyClient implements HttpClient { @Override public Future<Response> get(InvocationCallback<Response> callback, Map<String, Object> headers) { - Builder builder = this.client.target(this.baseUrl).request(); + Builder builder = getWebTarget().request(); if (headers != null) { headers.forEach(builder::header); } @@ -328,7 +334,7 @@ public class JerseyClient implements HttpClient { } private Builder getBuilder(String path, Map<String, Object> headers) { - Builder builder = this.client.target(this.baseUrl).path(path).request(); + Builder builder = getWebTarget().path(path).request(); for (Entry<String, Object> header : headers.entrySet()) { builder.header(header.getKey(), header.getValue()); } |