diff options
author | Smokowski, Kevin (ks6305) <kevin.smokowski@att.com> | 2019-10-17 21:00:21 +0000 |
---|---|---|
committer | Dan Timoney <dtimoney@att.com> | 2019-10-23 16:34:42 +0000 |
commit | c3988ec2b7b98eeb3b061ddb08a74eeb90d49edb (patch) | |
tree | 36b3bc6751a7c8eaf59b4a6964111ede0dd4f065 /base/http/provider/src | |
parent | fe8c4ae15a2301db06f1a1b217b8db82f4716211 (diff) |
add filters to base
incorporate common filters into base adaptor
Issue-ID: CCSDK-1849
Signed-off-by: Smokowski, Kevin (ks6305) <kevin.smokowski@att.com>
Change-Id: Ib1de49f29ff88c0f8cff87642ae60dc11517331b
Diffstat (limited to 'base/http/provider/src')
2 files changed, 16 insertions, 14 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 index 92e64b6dd..cc6f06a4d 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 ee2d223d3..d0973d90e 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());
|