From ef849e64bc904f729bace1fb2c43f8cf34de3dd5 Mon Sep 17 00:00:00 2001 From: mmis Date: Thu, 30 Aug 2018 13:34:55 +0100 Subject: Add support for http PUT Added support for http PUT for use by the policy forwarder in policy/distribution Issue-ID: POLICY-926 Change-Id: Ifa5c2e8be0582797936b95b772ad236f35c10f24 Signed-off-by: mmis --- .../common/endpoints/http/client/HttpClient.java | 6 ++++++ .../http/client/internal/JerseyClient.java | 23 ++++++++++++++-------- .../http/server/internal/JettyServletServer.java | 7 ++++--- 3 files changed, 25 insertions(+), 11 deletions(-) (limited to 'policy-endpoints/src/main/java/org') 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 f886e5ca..6e8865f5 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 @@ -20,6 +20,9 @@ package org.onap.policy.common.endpoints.http.client; +import java.util.Map; + +import javax.ws.rs.client.Entity; import javax.ws.rs.core.Response; import org.onap.policy.common.capabilities.Startable; @@ -30,6 +33,8 @@ public interface HttpClient extends Startable { public Response get(); + public Response put(String path, Entity entity, Map headers); + public static T getBody(Response response, Class entityType) { return response.readEntity(entityType); } @@ -54,4 +59,5 @@ public interface HttpClient extends Startable { public static final HttpClientFactory factory = new IndexedHttpClientFactory(); + } 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 c227071c..0be81099 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 @@ -28,12 +28,16 @@ import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; +import java.util.Map; +import java.util.Map.Entry; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; import javax.ws.rs.core.Response; import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; @@ -66,14 +70,9 @@ public class JerseyClient implements HttpClient { /** * Constructor. * - * name the name - * https is it https or not - * selfSignedCerts are there self signed certs - * hostname the hostname - * port port being used - * basePath base context - * userName user - * password password + * name the name https is it https or not selfSignedCerts are there self signed certs hostname + * the hostname port port being used basePath base context userName user password password + * * @param busTopicParams Input parameters object * @throws KeyManagementException key exception * @throws NoSuchAlgorithmException no algorithm exception @@ -163,6 +162,14 @@ public class JerseyClient implements HttpClient { return this.client.target(this.baseUrl).request().get(); } + @Override + public Response put(String path, Entity entity, Map headers) { + Builder builder = this.client.target(this.baseUrl).path(path).request(); + for (Entry header : headers.entrySet()) { + builder.header(header.getKey(), header.getValue()); + } + return builder.put(entity); + } @Override public boolean start() { diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/internal/JettyServletServer.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/internal/JettyServletServer.java index 7d37521e..3b8c08fc 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/internal/JettyServletServer.java +++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/internal/JettyServletServer.java @@ -23,7 +23,9 @@ package org.onap.policy.common.endpoints.http.server.internal; import com.fasterxml.jackson.annotation.JsonIgnore; import java.util.EnumSet; + import javax.servlet.DispatcherType; + import org.eclipse.jetty.security.ConstraintMapping; import org.eclipse.jetty.security.ConstraintSecurityHandler; import org.eclipse.jetty.security.HashLoginService; @@ -164,7 +166,7 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable } else { this.connector = httpConnector(); } - + this.connector.setName(srvName); this.connector.setReuseAddress(true); this.connector.setPort(port); @@ -189,8 +191,7 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable tempFilterPath = "/*"; } - context.addFilter(filterClass, tempFilterPath, - EnumSet.of(DispatcherType.INCLUDE, DispatcherType.REQUEST)); + context.addFilter(filterClass, tempFilterPath, EnumSet.of(DispatcherType.INCLUDE, DispatcherType.REQUEST)); } /** -- cgit 1.2.3-korg