summaryrefslogtreecommitdiffstats
path: root/base/http/provider/src
diff options
context:
space:
mode:
authorJessica Wagantall <jwagantall@linuxfoundation.org>2020-12-01 11:26:31 -0800
committerJessica Wagantall <jwagantall@linuxfoundation.org>2020-12-01 11:27:11 -0800
commit11510b43c277b8e1dd7e58d79785544810118c8e (patch)
treeb88a497c999d24b5f357ea9b26bc93e0990fd5e7 /base/http/provider/src
parent5d2eab72fc4442f14108b41800cec88126913823 (diff)
Migrate sli-adaptor files
Migrate sli-adaptor repo files into a new "adaptors" directory. Signed-off-by: Jessica Wagantall <jwagantall@linuxfoundation.org>
Diffstat (limited to 'base/http/provider/src')
-rw-r--r--base/http/provider/src/main/java/org/onap/ccsdk/sli/adaptors/base/http/AbstractHttpAdapter.java114
-rw-r--r--base/http/provider/src/main/java/org/onap/ccsdk/sli/adaptors/base/http/BasicAuthFilter.java22
-rw-r--r--base/http/provider/src/test/java/org/onap/ccsdk/sli/adaptors/base/http/AbstractHttpAdapterTest.java44
-rw-r--r--base/http/provider/src/test/java/org/onap/ccsdk/sli/adaptors/base/http/BasicAuthFilterTest.java20
-rw-r--r--base/http/provider/src/test/resources/testprops.properties1
5 files changed, 0 insertions, 201 deletions
diff --git a/base/http/provider/src/main/java/org/onap/ccsdk/sli/adaptors/base/http/AbstractHttpAdapter.java b/base/http/provider/src/main/java/org/onap/ccsdk/sli/adaptors/base/http/AbstractHttpAdapter.java
deleted file mode 100644
index cc6f06a4d..000000000
--- a/base/http/provider/src/main/java/org/onap/ccsdk/sli/adaptors/base/http/AbstractHttpAdapter.java
+++ /dev/null
@@ -1,114 +0,0 @@
-package org.onap.ccsdk.sli.adaptors.base.http;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.Base64;
-import java.util.Properties;
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.SSLSession;
-import javax.ws.rs.client.ClientBuilder;
-import org.onap.logging.filter.base.MetricLogClientFilter;
-import org.onap.logging.filter.base.PayloadLoggingClientFilter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class AbstractHttpAdapter {
- protected static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
- private static final String SDNC_CONFIG_DIR_DEFAULT = "/opt/sdnc/data/properties";
- protected static final int DEFAULT_HTTP_CONNECT_TIMEOUT_MS = 60000; // 1 minute
- protected static final int DEFAULT_HTTP_READ_TIMEOUT_MS = 1800000; // 30 minutes
- protected ClientBuilder clientBuilder;
-
- private static final Logger logger = LoggerFactory.getLogger(AbstractHttpAdapter.class);
-
- public AbstractHttpAdapter() {
- clientBuilder = ClientBuilder.newBuilder();
- setTimeouts();
- defaultHostNameVerifier();
- }
-
- private void defaultHostNameVerifier() {
- clientBuilder.hostnameVerifier(new HostnameVerifier() {
- @Override
- public boolean verify(String hostname, SSLSession session) {
- return true;
- }
- });
- }
-
- protected void enableMetricLogging() {
- clientBuilder.register(new MetricLogClientFilter());
- }
-
- protected void enablePayloadLogging() {
- clientBuilder.register(new PayloadLoggingClientFilter());
- }
-
- private void setTimeouts() {
- Integer httpReadTimeout = readOptionalInteger("HTTP_READ_TIMEOUT_MS", DEFAULT_HTTP_READ_TIMEOUT_MS);
- Integer httpConnectTimeout = readOptionalInteger("HTTP_CONNECT_TIMEOUT_MS", DEFAULT_HTTP_CONNECT_TIMEOUT_MS);
-
- // restore once we migrate to once we migrate to javax.ws.rs-api 2.1
- // clientBuilder.connectTimeout(30, TimeUnit.SECONDS);
- // clientBuilder.readTimeout(30, TimeUnit.SECONDS);
-
- // Setting jersey specific properties is ugly, such behavior should be removed
- // once we migrate to javax.ws.rs-api 2.1
- clientBuilder.property("jersey.config.client.readTimeout", httpReadTimeout);
- clientBuilder.property("jersey.config.client.connectTimeout", httpConnectTimeout);
- }
-
- public Properties getProperties(String propertiesFileName) throws FileNotFoundException, IOException {
- // Check System property, then environment variable then default if null
- String propDir = System.getProperty(SDNC_CONFIG_DIR);
- if (propDir == null || propDir.length() < 1) {
- propDir = System.getenv(SDNC_CONFIG_DIR);
- }
- if (propDir == null || propDir.length() < 1) {
- propDir = SDNC_CONFIG_DIR_DEFAULT;
- }
- Properties properties = new Properties();
- // forward slash is checked to support path src/test/resources on windows machine
- if (!propDir.endsWith(File.separator) && !propDir.endsWith("/")) {
- propDir = propDir + File.separator;
- }
- String path = propDir + propertiesFileName;
- properties.load(new FileInputStream(path));
- logger.trace("Initialized properties from ({}) properties ({})", path, properties);
- return properties;
- }
-
- protected void addBasicAuthCredentials(String username, String password) {
- String basicAuthValue = getBasicAuthValue(username,password);
- clientBuilder.register(new BasicAuthFilter(basicAuthValue));
- }
-
- protected String getBasicAuthValue(String userName, String password) {
- String token = userName + ":" + password;
- try {
- return "Basic " + Base64.getEncoder().encodeToString(token.getBytes());
- } catch (Exception e) {
- logger.error("getBasicAuthValue threw an exception, credentials will be null", e);
- }
- return null;
- }
-
- public ClientBuilder getClientBuilder() {
- return clientBuilder;
- }
-
- private Integer readOptionalInteger(String propertyName, Integer defaultValue) {
- String stringValue = System.getProperty(propertyName);
- if (stringValue != null && stringValue.length() > 0) {
- try {
- return Integer.valueOf(stringValue);
- } catch (NumberFormatException e) {
- logger.warn("property " + propertyName + " had the value " + stringValue + " that could not be converted to an Integer, default " + defaultValue + " will be used instead", e);
- }
- }
- return defaultValue;
- }
-
-}
diff --git a/base/http/provider/src/main/java/org/onap/ccsdk/sli/adaptors/base/http/BasicAuthFilter.java b/base/http/provider/src/main/java/org/onap/ccsdk/sli/adaptors/base/http/BasicAuthFilter.java
deleted file mode 100644
index 5d3d463c9..000000000
--- a/base/http/provider/src/main/java/org/onap/ccsdk/sli/adaptors/base/http/BasicAuthFilter.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package org.onap.ccsdk.sli.adaptors.base.http;
-
-import java.io.IOException;
-
-import javax.ws.rs.client.ClientRequestContext;
-import javax.ws.rs.client.ClientRequestFilter;
-import javax.ws.rs.core.MultivaluedMap;
-
-public class BasicAuthFilter implements ClientRequestFilter {
- private final String basicAuthValue;
-
- public BasicAuthFilter(String basicAuthValue) {
- this.basicAuthValue = basicAuthValue;
- }
-
- public void filter(ClientRequestContext requestContext) throws IOException {
- MultivaluedMap<String, Object> headers = requestContext.getHeaders();
- headers.add("Authorization", basicAuthValue);
- }
-
-
-}
diff --git a/base/http/provider/src/test/java/org/onap/ccsdk/sli/adaptors/base/http/AbstractHttpAdapterTest.java b/base/http/provider/src/test/java/org/onap/ccsdk/sli/adaptors/base/http/AbstractHttpAdapterTest.java
deleted file mode 100644
index d0973d90e..000000000
--- a/base/http/provider/src/test/java/org/onap/ccsdk/sli/adaptors/base/http/AbstractHttpAdapterTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package org.onap.ccsdk.sli.adaptors.base.http;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.util.Properties;
-import java.util.Set;
-
-import javax.ws.rs.client.Client;
-
-import org.junit.Test;
-
-public class AbstractHttpAdapterTest {
-
- public class TestAdapter extends AbstractHttpAdapter {
-
- }
-
- @Test
- public void checkTimeouts() throws Exception {
- TestAdapter adapter = new TestAdapter();
- Client client = adapter.getClientBuilder().build();
- assertNotNull(client.getConfiguration().getProperty("jersey.config.client.readTimeout"));
- assertNotNull(client.getConfiguration().getProperty("jersey.config.client.connectTimeout"));
- }
-
- @Test
- public void propertiesTest() throws Exception {
- System.setProperty(AbstractHttpAdapter.SDNC_CONFIG_DIR, "src/test/resources/");
- TestAdapter adapter = new TestAdapter();
- Properties props = adapter.getProperties("testprops.properties");
- assertNotNull(props);
- assertEquals("world", props.get("hello"));
- }
-
- @Test
- public void basicAuthFilter() throws Exception {
- TestAdapter adapter = new TestAdapter();
- adapter.addBasicAuthCredentials("hello", "world");
- Set<Object> objs = adapter.getClientBuilder().getConfiguration().getInstances();
- assertEquals(BasicAuthFilter.class,objs.iterator().next().getClass());
- }
-
-}
diff --git a/base/http/provider/src/test/java/org/onap/ccsdk/sli/adaptors/base/http/BasicAuthFilterTest.java b/base/http/provider/src/test/java/org/onap/ccsdk/sli/adaptors/base/http/BasicAuthFilterTest.java
deleted file mode 100644
index d9d552dac..000000000
--- a/base/http/provider/src/test/java/org/onap/ccsdk/sli/adaptors/base/http/BasicAuthFilterTest.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.onap.ccsdk.sli.adaptors.base.http;
-
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.Test;
-
-public class BasicAuthFilterTest {
-
- @Test
- public void notNullParameters() throws Exception {
- BasicAuthFilter myFilter = new BasicAuthFilter("hello");
- assertNotNull(myFilter);
- }
-
- @Test
- public void nullParameters() throws Exception {
- BasicAuthFilter myFilter = new BasicAuthFilter(null);
- assertNotNull(myFilter);
- }
-}
diff --git a/base/http/provider/src/test/resources/testprops.properties b/base/http/provider/src/test/resources/testprops.properties
deleted file mode 100644
index 3f602680e..000000000
--- a/base/http/provider/src/test/resources/testprops.properties
+++ /dev/null
@@ -1 +0,0 @@
-hello = world \ No newline at end of file