From c3988ec2b7b98eeb3b061ddb08a74eeb90d49edb Mon Sep 17 00:00:00 2001 From: "Smokowski, Kevin (ks6305)" Date: Thu, 17 Oct 2019 21:00:21 +0000 Subject: add filters to base incorporate common filters into base adaptor Issue-ID: CCSDK-1849 Signed-off-by: Smokowski, Kevin (ks6305) Change-Id: Ib1de49f29ff88c0f8cff87642ae60dc11517331b --- base/http/provider/pom.xml | 6 ++++++ .../sli/adaptors/base/http/AbstractHttpAdapter.java | 17 +++++++++++------ .../sli/adaptors/base/http/AbstractHttpAdapterTest.java | 13 +++++-------- 3 files changed, 22 insertions(+), 14 deletions(-) (limited to 'base/http/provider') diff --git a/base/http/provider/pom.xml b/base/http/provider/pom.xml index 56728be6..e6061ed6 100644 --- a/base/http/provider/pom.xml +++ b/base/http/provider/pom.xml @@ -31,5 +31,11 @@ ${jersey.version} test + + org.onap.logging-analytics + logging-filter-base + 1.5.0 + provided + 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 index 92e64b6d..cc6f06a4 100644 --- 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 @@ -4,13 +4,13 @@ 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 javax.xml.bind.DatatypeConverter; - +import org.onap.logging.filter.base.MetricLogClientFilter; +import org.onap.logging.filter.base.PayloadLoggingClientFilter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,7 +26,6 @@ public abstract class AbstractHttpAdapter { public AbstractHttpAdapter() { clientBuilder = ClientBuilder.newBuilder(); setTimeouts(); - registerLoggingFilter(); defaultHostNameVerifier(); } @@ -39,7 +38,13 @@ public abstract class AbstractHttpAdapter { }); } - protected abstract void registerLoggingFilter(); + 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); @@ -83,7 +88,7 @@ public abstract class AbstractHttpAdapter { protected String getBasicAuthValue(String userName, String password) { String token = userName + ":" + password; try { - return "Basic " + DatatypeConverter.printBase64Binary(token.getBytes("UTF-8")); + return "Basic " + Base64.getEncoder().encodeToString(token.getBytes()); } catch (Exception e) { logger.error("getBasicAuthValue threw an exception, credentials will be null", e); } 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 index ee2d223d..d0973d90 100644 --- 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 @@ -12,16 +12,13 @@ import org.junit.Test; public class AbstractHttpAdapterTest { - public class NonLoggingHttpAdapter extends AbstractHttpAdapter { - @Override - protected void registerLoggingFilter() { - // nonlogging, do nothing - } + public class TestAdapter extends AbstractHttpAdapter { + } @Test public void checkTimeouts() throws Exception { - NonLoggingHttpAdapter adapter = new NonLoggingHttpAdapter(); + 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")); @@ -30,7 +27,7 @@ public class AbstractHttpAdapterTest { @Test public void propertiesTest() throws Exception { System.setProperty(AbstractHttpAdapter.SDNC_CONFIG_DIR, "src/test/resources/"); - NonLoggingHttpAdapter adapter = new NonLoggingHttpAdapter(); + TestAdapter adapter = new TestAdapter(); Properties props = adapter.getProperties("testprops.properties"); assertNotNull(props); assertEquals("world", props.get("hello")); @@ -38,7 +35,7 @@ public class AbstractHttpAdapterTest { @Test public void basicAuthFilter() throws Exception { - NonLoggingHttpAdapter adapter = new NonLoggingHttpAdapter(); + TestAdapter adapter = new TestAdapter(); adapter.addBasicAuthCredentials("hello", "world"); Set objs = adapter.getClientBuilder().getConfiguration().getInstances(); assertEquals(BasicAuthFilter.class,objs.iterator().next().getClass()); -- cgit 1.2.3-korg