summaryrefslogtreecommitdiffstats
path: root/common/src
diff options
context:
space:
mode:
authorPlummer, Brittany <brittany.plummer@att.com>2019-09-19 10:22:19 -0400
committerBenjamin, Max (mb388a) <mb388a@att.com>2019-09-19 10:22:19 -0400
commita2fd007e4d1b03f7258d71fa86658510ff2f1790 (patch)
tree92b1e304bd3ee1a909276380b62f717aa9962ce7 /common/src
parenta1f8a0c1ce64e90653397c5ce8d4949fe0244d07 (diff)
update logging to match onap logging library
Updated to use changes added to logging library in ONAP Updated RestClient to set mdc rather than extend filter Updated filter removal to include new spring filter Updated to exclude filter causing failure in catdb Excluded filter causing failures in requestdb Updated requestdbatt to exclude filter Updated check for spring filters to fix failing tests Issue-ID: SO-2353 Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com> Change-Id: Idb081a0f5527690f9dc41c7914a2d721f9022aea
Diffstat (limited to 'common/src')
-rw-r--r--common/src/main/java/org/onap/so/client/BaseClient.java2
-rw-r--r--common/src/main/java/org/onap/so/client/RestClient.java1
-rw-r--r--common/src/main/java/org/onap/so/client/RestTemplateConfig.java3
-rw-r--r--common/src/main/java/org/onap/so/externaltasks/logging/AuditMDCSetup.java4
-rw-r--r--common/src/main/java/org/onap/so/logging/jaxrs/filter/SOMetricLogClientFilter.java15
-rw-r--r--common/src/main/java/org/onap/so/logging/jaxrs/filter/SOSpringClientFilter.java33
-rw-r--r--common/src/test/java/org/onap/so/externaltasks/logging/AuditMDCSetupTest.java4
7 files changed, 32 insertions, 30 deletions
diff --git a/common/src/main/java/org/onap/so/client/BaseClient.java b/common/src/main/java/org/onap/so/client/BaseClient.java
index d1523a1f96..24c83cbcab 100644
--- a/common/src/main/java/org/onap/so/client/BaseClient.java
+++ b/common/src/main/java/org/onap/so/client/BaseClient.java
@@ -22,6 +22,7 @@ package org.onap.so.client;
import java.util.ArrayList;
import java.util.List;
+import org.onap.logging.filter.spring.SpringClientPayloadFilter;
import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
@@ -81,6 +82,7 @@ public class BaseClient<I, O> {
restTemplate
.setRequestFactory(new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory()));
restTemplate.getInterceptors().add(new SOSpringClientFilter());
+ restTemplate.getInterceptors().add((new SpringClientPayloadFilter()));
ResponseEntity<O> responseEntity =
restTemplate.exchange(getTargetUrl(), method, requestEntity, typeRef, uriVariables);
return responseEntity.getBody();
diff --git a/common/src/main/java/org/onap/so/client/RestClient.java b/common/src/main/java/org/onap/so/client/RestClient.java
index c8d7dc9f5c..077ba24c2b 100644
--- a/common/src/main/java/org/onap/so/client/RestClient.java
+++ b/common/src/main/java/org/onap/so/client/RestClient.java
@@ -50,7 +50,6 @@ import org.onap.logging.filter.base.PayloadLoggingClientFilter;
import org.onap.so.client.policy.CommonObjectMapperProvider;
import org.onap.so.logging.jaxrs.filter.SOMetricLogClientFilter;
import org.onap.so.utils.CryptoUtils;
-import org.onap.logging.filter.base.ONAPComponents;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
diff --git a/common/src/main/java/org/onap/so/client/RestTemplateConfig.java b/common/src/main/java/org/onap/so/client/RestTemplateConfig.java
index 5fbc9126cf..f8587ff776 100644
--- a/common/src/main/java/org/onap/so/client/RestTemplateConfig.java
+++ b/common/src/main/java/org/onap/so/client/RestTemplateConfig.java
@@ -20,6 +20,7 @@
package org.onap.so.client;
+import org.onap.logging.filter.spring.SpringClientPayloadFilter;
import org.onap.so.configuration.rest.HttpComponentsClientConfiguration;
import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter;
import org.springframework.beans.factory.annotation.Autowired;
@@ -46,6 +47,7 @@ public class RestTemplateConfig {
restTemplate
.setRequestFactory(new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory()));
restTemplate.getInterceptors().add(new SOSpringClientFilter());
+ restTemplate.getInterceptors().add((new SpringClientPayloadFilter()));
return restTemplate;
}
@@ -57,6 +59,7 @@ public class RestTemplateConfig {
final RestTemplate restTemplate =
new RestTemplate(new BufferingClientHttpRequestFactory(clientHttpRequestFactory));
restTemplate.getInterceptors().add(new SOSpringClientFilter());
+ restTemplate.getInterceptors().add((new SpringClientPayloadFilter()));
return restTemplate;
}
}
diff --git a/common/src/main/java/org/onap/so/externaltasks/logging/AuditMDCSetup.java b/common/src/main/java/org/onap/so/externaltasks/logging/AuditMDCSetup.java
index 8d30ad35ff..9f71e61e1f 100644
--- a/common/src/main/java/org/onap/so/externaltasks/logging/AuditMDCSetup.java
+++ b/common/src/main/java/org/onap/so/externaltasks/logging/AuditMDCSetup.java
@@ -16,10 +16,10 @@ import org.springframework.stereotype.Component;
@Component
public class AuditMDCSetup {
- private MDCSetup mdcSetup = new MDCSetup();
-
private static final Logger logger = LoggerFactory.getLogger(AuditMDCSetup.class);
+ private MDCSetup mdcSetup = new MDCSetup();
+
public void setupMDC(ExternalTask externalTask) {
MDC.put(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP,
ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT));
diff --git a/common/src/main/java/org/onap/so/logging/jaxrs/filter/SOMetricLogClientFilter.java b/common/src/main/java/org/onap/so/logging/jaxrs/filter/SOMetricLogClientFilter.java
index 248e2f00bf..22a8d0405a 100644
--- a/common/src/main/java/org/onap/so/logging/jaxrs/filter/SOMetricLogClientFilter.java
+++ b/common/src/main/java/org/onap/so/logging/jaxrs/filter/SOMetricLogClientFilter.java
@@ -2,7 +2,6 @@ package org.onap.so.logging.jaxrs.filter;
import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientResponseContext;
-import org.onap.logging.filter.base.MDCSetup;
import org.onap.logging.filter.base.MetricLogClientFilter;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.onap.so.logger.MdcConstants;
@@ -15,21 +14,19 @@ import org.slf4j.MarkerFactory;
public class SOMetricLogClientFilter extends MetricLogClientFilter {
- protected static Logger logger = LoggerFactory.getLogger(MDCSetup.class);
+ protected static Logger logger = LoggerFactory.getLogger(SOMetricLogClientFilter.class);
private static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE-RETURN");
- private MDCSetup mdcSetup = new MDCSetup();
-
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) {
try {
- mdcSetup.setLogTimestamp();
- mdcSetup.setElapsedTimeInvokeTimestamp();
- mdcSetup.setResponseStatusCode(responseContext.getStatus());
- mdcSetup.setResponseDescription(responseContext.getStatus());
+ setLogTimestamp();
+ setElapsedTimeInvokeTimestamp();
+ setResponseStatusCode(responseContext.getStatus());
+ setResponseDescription(responseContext.getStatus());
MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, String.valueOf(responseContext.getStatus()));
logger.info(INVOKE_RETURN, "InvokeReturn");
- mdcSetup.clearClientMDCs();
+ clearClientMDCs();
setOpenStackResponseCode();
} catch (Exception e) {
logger.warn("Error in JAX-RS request,response client filter", e);
diff --git a/common/src/main/java/org/onap/so/logging/jaxrs/filter/SOSpringClientFilter.java b/common/src/main/java/org/onap/so/logging/jaxrs/filter/SOSpringClientFilter.java
index c2b8df37c2..23df408ca5 100644
--- a/common/src/main/java/org/onap/so/logging/jaxrs/filter/SOSpringClientFilter.java
+++ b/common/src/main/java/org/onap/so/logging/jaxrs/filter/SOSpringClientFilter.java
@@ -2,7 +2,6 @@ package org.onap.so.logging.jaxrs.filter;
import java.io.IOException;
import java.nio.charset.Charset;
-import org.onap.logging.filter.base.MDCSetup;
import org.onap.logging.filter.spring.SpringClientFilter;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.onap.so.logger.MdcConstants;
@@ -11,6 +10,7 @@ import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
+import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.stereotype.Component;
@@ -20,27 +20,24 @@ import org.springframework.util.StreamUtils;
public class SOSpringClientFilter extends SpringClientFilter implements ClientHttpRequestInterceptor {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
- private MDCSetup mdcSetup = new MDCSetup();
private static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE-RETURN");
-
- protected void processResponse(ClientHttpResponse response) throws IOException {
- if (logger.isDebugEnabled()) {
- logger.debug("============================response begin==========================================");
- logger.debug("Status code : {}", response.getStatusCode());
- logger.debug("Status text : {}", response.getStatusText());
- logger.debug("Headers : {}", response.getHeaders());
- logger.debug("Response body: {}", StreamUtils.copyToString(response.getBody(), Charset.defaultCharset()));
- logger.debug("=======================response end=================================================");
+ @Override
+ protected void post(HttpRequest request, ClientHttpResponse response) {
+ setLogTimestamp();
+ setElapsedTimeInvokeTimestamp();
+ try {
+ setResponseStatusCode(response.getRawStatusCode());
+ int statusCode = response.getRawStatusCode();
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, String.valueOf(statusCode));
+ setResponseDescription(statusCode);
+ } catch (IOException e) {
+ logger.error("Unable to get statusCode from response");
}
- mdcSetup.setLogTimestamp();
- mdcSetup.setElapsedTimeInvokeTimestamp();
- mdcSetup.setResponseStatusCode(response.getRawStatusCode());
- int statusCode = response.getRawStatusCode();
- MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, String.valueOf(statusCode));
- mdcSetup.setResponseDescription(statusCode);
+
+
logger.info(INVOKE_RETURN, "InvokeReturn");
- mdcSetup.clearClientMDCs();
+ clearClientMDCs();
setOpenStackResponseCode();
}
diff --git a/common/src/test/java/org/onap/so/externaltasks/logging/AuditMDCSetupTest.java b/common/src/test/java/org/onap/so/externaltasks/logging/AuditMDCSetupTest.java
index 5e2a51a56f..c4609f0336 100644
--- a/common/src/test/java/org/onap/so/externaltasks/logging/AuditMDCSetupTest.java
+++ b/common/src/test/java/org/onap/so/externaltasks/logging/AuditMDCSetupTest.java
@@ -12,6 +12,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.logging.filter.base.MDCSetup;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.onap.so.logger.MdcConstants;
import org.slf4j.MDC;
@@ -22,6 +23,9 @@ public class AuditMDCSetupTest {
@Mock
private ExternalTask externalTask;
+ @Mock
+ private MDCSetup mdcSet;
+
@Spy
@InjectMocks
private AuditMDCSetup mdcSetup;