aboutsummaryrefslogtreecommitdiffstats
path: root/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client
diff options
context:
space:
mode:
Diffstat (limited to 'policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client')
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClientFactory.java33
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/internal/JerseyClient.java47
2 files changed, 46 insertions, 34 deletions
diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClientFactory.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClientFactory.java
index c002402d..ca10680b 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClientFactory.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClientFactory.java
@@ -3,6 +3,7 @@
* policy-endpoints
* ================================================================================
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,6 +29,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Properties;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.endpoints.http.client.internal.JerseyClient;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
import org.slf4j.Logger;
@@ -41,8 +44,7 @@ public interface HttpClientFactory {
/**
* Build and http client with the following parameters.
*/
- public HttpClient build(String name, boolean https, boolean selfSignedCerts, String hostname, int port,
- String baseUrl, String userName, String password, boolean managed)
+ public HttpClient build(BusTopicParams busTopicParams)
throws KeyManagementException, NoSuchAlgorithmException;
/**
@@ -89,18 +91,17 @@ class IndexedHttpClientFactory implements HttpClientFactory {
protected HashMap<String, HttpClient> clients = new HashMap<>();
@Override
- public synchronized HttpClient build(String name, boolean https, boolean selfSignedCerts, String hostname, int port,
- String baseUrl, String userName, String password, boolean managed)
+ public synchronized HttpClient build(BusTopicParams busTopicParams)
throws KeyManagementException, NoSuchAlgorithmException {
- if (clients.containsKey(name)) {
- return clients.get(name);
+ if (clients.containsKey(busTopicParams.getClientName())) {
+ return clients.get(busTopicParams.getClientName());
}
JerseyClient client =
- new JerseyClient(name, https, selfSignedCerts, hostname, port, baseUrl, userName, password);
+ new JerseyClient(busTopicParams);
- if (managed) {
- clients.put(name, client);
+ if (busTopicParams.isManaged()) {
+ clients.put(busTopicParams.getClientName(), client);
}
return client;
@@ -122,7 +123,7 @@ class IndexedHttpClientFactory implements HttpClientFactory {
String httpsString = properties.getProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "."
+ clientName + PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX);
boolean https = false;
- if (httpsString != null && !httpsString.isEmpty()) {
+ if (StringUtils.isNotBlank(httpsString)) {
https = Boolean.parseBoolean(httpsString);
}
@@ -160,7 +161,17 @@ class IndexedHttpClientFactory implements HttpClientFactory {
try {
HttpClient client =
- this.build(clientName, https, https, hostName, port, baseUrl, userName, password, managed);
+ this.build(BusTopicParams.builder()
+ .clientName(clientName)
+ .useHttps(https)
+ .allowSelfSignedCerts(https)
+ .hostname(hostName)
+ .port(port)
+ .basePath(baseUrl)
+ .userName(userName)
+ .password(password)
+ .managed(managed)
+ .build());
clientList.add(client);
} catch (Exception e) {
logger.error("http-client-factory: cannot build client {}", clientName, e);
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 1fc00bfe..c227071c 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
@@ -3,6 +3,7 @@
* policy-endpoints
* ================================================================================
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,6 +37,7 @@ import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;
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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -64,43 +66,42 @@ public class JerseyClient implements HttpClient {
/**
* Constructor.
*
- * @param name the name
- * @param https is it https or not
- * @param selfSignedCerts are there self signed certs
- * @param hostname the hostname
- * @param port port being used
- * @param basePath base context
- * @param userName user
- * @param 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
*/
- public JerseyClient(String name, boolean https, boolean selfSignedCerts, String hostname, int port, String basePath,
- String userName, String password) throws KeyManagementException, NoSuchAlgorithmException {
+ public JerseyClient(BusTopicParams busTopicParams) throws KeyManagementException, NoSuchAlgorithmException {
super();
- if (name == null || name.isEmpty()) {
+ if (busTopicParams.isClientNameInvalid()) {
throw new IllegalArgumentException("Name must be provided");
}
- if (hostname == null || hostname.isEmpty()) {
+ if (busTopicParams.isHostnameInvalid()) {
throw new IllegalArgumentException("Hostname must be provided");
}
- if (port <= 0 && port >= 65535) {
- throw new IllegalArgumentException("Invalid Port provided: " + port);
+ if (busTopicParams.isPortInvalid()) {
+ throw new IllegalArgumentException("Invalid Port provided: " + busTopicParams.getPort());
}
- this.name = name;
- this.https = https;
- this.hostname = hostname;
- this.port = port;
- this.basePath = basePath;
- this.userName = userName;
- this.password = password;
- this.selfSignedCerts = selfSignedCerts;
+ this.name = busTopicParams.getClientName();
+ this.https = busTopicParams.isUseHttps();
+ this.hostname = busTopicParams.getHostname();
+ this.port = busTopicParams.getPort();
+ this.basePath = busTopicParams.getBasePath();
+ this.userName = busTopicParams.getUserName();
+ this.password = busTopicParams.getPassword();
+ this.selfSignedCerts = busTopicParams.isAllowSelfSignedCerts();
StringBuilder tmpBaseUrl = new StringBuilder();
if (this.https) {