aboutsummaryrefslogtreecommitdiffstats
path: root/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/internal/JerseyClient.java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-01-21 12:42:10 -0500
committerJim Hahn <jrh3@att.com>2019-01-23 18:43:43 -0500
commit18914b033f67d25cc9377b2e381648a9e3184968 (patch)
tree973bfdd2a119c19d11e3770e2a4a82d898279284 /policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/internal/JerseyClient.java
parent9f15e1987dc9fc6bb8196c415b817b3f1cf6bd5f (diff)
Add gson support to policy-endpoints
Added "provider" property to both http client and server builders. The provider defaults to jackson, to maintain backward compatibility until other policy code has been converted to gson. Removed commented item from pom. Added some comments and re-arranged a few pieces of code. Fixed a few typos and removed spacing at the end of some lines. Reordered imports. Added comments about limitations when using jersey-media-json-jackson. Address ridiculous checkstyle complaint. Support comma-separated list of serialization providers in jersey client. Disabled metainf discovery from jersey client and server so that the media-json dependencies could be re-instated in the pom. Address another ridiculous checkstyle complaint. Change-Id: Ic5a93b475d0ee9b435352b3516de6b865b00a86a Issue-ID: POLICY-1428 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/internal/JerseyClient.java')
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/internal/JerseyClient.java38
1 files changed, 32 insertions, 6 deletions
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 b55a7bb2..2287486e 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
@@ -22,7 +22,6 @@
package org.onap.policy.common.endpoints.http.client.internal;
import com.fasterxml.jackson.annotation.JsonIgnore;
-
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
@@ -30,7 +29,6 @@ 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;
@@ -39,7 +37,7 @@ 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.ClientProperties;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.endpoints.http.client.HttpClient;
@@ -48,6 +46,10 @@ import org.slf4j.LoggerFactory;
/**
* Http Client implementation using a Jersey Client.
+ *
+ * <p>Note: the serialization provider will be ignored if the maven artifact,
+ * <i>jersey-media-json-jackson</i>, is included, regardless of whether it's included
+ * directly or indirectly.
*/
public class JerseyClient implements HttpClient {
@@ -55,6 +57,9 @@ public class JerseyClient implements HttpClient {
* Logger.
*/
private static Logger logger = LoggerFactory.getLogger(JerseyClient.class);
+
+ protected static final String JERSEY_DEFAULT_SERIALIZATION_PROVIDER =
+ "com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider";
protected final String name;
protected final boolean https;
@@ -73,14 +78,17 @@ public class JerseyClient implements HttpClient {
/**
* Constructor.
*
- * <p>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
+ * <p>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
+ * @throws ClassNotFoundException if the serialization provider cannot be found
*/
- public JerseyClient(BusTopicParams busTopicParams) throws KeyManagementException, NoSuchAlgorithmException {
+ public JerseyClient(BusTopicParams busTopicParams)
+ throws KeyManagementException, NoSuchAlgorithmException, ClassNotFoundException {
super();
@@ -147,10 +155,28 @@ public class JerseyClient implements HttpClient {
this.client.register(authFeature);
}
+ registerSerProviders(busTopicParams.getSerializationProvider());
+
+ this.client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
+
this.baseUrl = tmpBaseUrl.append(this.hostname).append(":").append(this.port).append("/")
.append((this.basePath == null) ? "" : this.basePath).toString();
}
+ /**
+ * Registers the serialization provider(s) with the client.
+ *
+ * @param serializationProvider comma-separated list of serialization providers
+ * @throws ClassNotFoundException if the serialization provider cannot be found
+ */
+ private void registerSerProviders(String serializationProvider) throws ClassNotFoundException {
+ String providers = (serializationProvider == null || serializationProvider.isEmpty()
+ ? JERSEY_DEFAULT_SERIALIZATION_PROVIDER : serializationProvider);
+ for (String prov : providers.split(",")) {
+ this.client.register(Class.forName(prov));
+ }
+ }
+
@Override
public Response get(String path) {
if (path != null && !path.isEmpty()) {