diff options
author | Dan Timoney <dtimoney@att.com> | 2019-10-30 20:40:50 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-10-30 20:40:50 +0000 |
commit | fbc3ba88154c38afcbde691f6839c171445ac2fa (patch) | |
tree | a0be3de4c557620f84cb4311c7bf21f682941212 | |
parent | 985fee3d36c25611094145399e494972176612cd (diff) | |
parent | c3988ec2b7b98eeb3b061ddb08a74eeb90d49edb (diff) |
Merge "add filters to base"
3 files changed, 22 insertions, 14 deletions
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 @@ <version>${jersey.version}</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.onap.logging-analytics</groupId> + <artifactId>logging-filter-base</artifactId> + <version>1.5.0</version> + <scope>provided</scope> + </dependency> </dependencies> </project> 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<Object> objs = adapter.getClientBuilder().getConfiguration().getInstances();
assertEquals(BasicAuthFilter.class,objs.iterator().next().getClass());
|