aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java12
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractBaseMetricLogFilter.java135
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java93
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/CustomFilter.java25
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/FilteredMetricLogClientFilter.java62
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/HttpURLConnectionMetricUtil.java8
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java6
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/PayloadLoggingServletFilter.java1
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/SoapMetricLogHandler.java87
-rw-r--r--reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MetricLogClientFilterTest.java3
-rw-r--r--reference/logging-filter/logging-filter-spring/src/test/java/org/onap/logging/filter/spring/SpringClientFilterTest.java7
11 files changed, 334 insertions, 105 deletions
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java
index 00285b6..d8394a7 100644
--- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java
@@ -44,7 +44,7 @@ public abstract class AbstractAuditLogFilter<GenericRequest, GenericResponse> ex
additionalPreHandling(request);
setLogTimestamp();
setElapsedTime();
- logger.info(ONAPLogConstants.Markers.ENTRY, "Entering");
+ logEntering();
} catch (Exception e) {
logger.warn("Error in AbstractInboundFilter pre", e);
}
@@ -59,8 +59,8 @@ public abstract class AbstractAuditLogFilter<GenericRequest, GenericResponse> ex
setResponseDescription(responseCode);
setLogTimestamp();
setElapsedTime();
- logger.info(ONAPLogConstants.Markers.EXIT, "Exiting.");
additionalPostHandling(response);
+ logExiting();
} catch (Exception e) {
logger.warn("Error in AbstractInboundFilter post", e);
} finally {
@@ -80,4 +80,12 @@ public abstract class AbstractAuditLogFilter<GenericRequest, GenericResponse> ex
// override to add additional post handling
}
+ protected void logEntering() {
+ logger.info(ONAPLogConstants.Markers.ENTRY, "Entering");
+ }
+
+ protected void logExiting() {
+ logger.info(ONAPLogConstants.Markers.EXIT, "Exiting.");
+ }
+
}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractBaseMetricLogFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractBaseMetricLogFilter.java
new file mode 100644
index 0000000..fc5ae95
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractBaseMetricLogFilter.java
@@ -0,0 +1,135 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - Logging
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.logging.filter.base;
+
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.UUID;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+import org.slf4j.Marker;
+import org.slf4j.MarkerFactory;
+
+public abstract class AbstractBaseMetricLogFilter<Request, Response> extends MDCSetup {
+ protected static final Logger logger = LoggerFactory.getLogger(AbstractBaseMetricLogFilter.class);
+ protected final String partnerName;
+ protected static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE-RETURN");
+
+ public AbstractBaseMetricLogFilter() {
+ partnerName = getPartnerName();
+ }
+
+ protected abstract String getTargetServiceName(Request request);
+
+ protected abstract int getHttpStatusCode(Response response);
+
+ protected abstract String getResponseCode(Response response);
+
+ protected abstract String getTargetEntity(Request request);
+
+ protected void pre(Request request) {
+ try {
+ setupMDC(request);
+ extractRequestID();
+ setInvocationId();
+ additionalPre(request);
+ logRequest();
+ } catch (Exception e) {
+ logger.warn("Error in AbstractBaseMetricLogFilter pre", e);
+ }
+ }
+
+ protected void additionalPre(Request request) {
+ // override to add application specific logic
+ }
+
+ protected String setInvocationId() {
+ String invocationId = UUID.randomUUID().toString();
+ MDC.put(ONAPLogConstants.MDCs.CLIENT_INVOCATION_ID, invocationId);
+ MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId);
+ return invocationId;
+ }
+
+ protected void setupMDC(Request request) {
+ MDC.put(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP,
+ ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT));
+ MDC.put(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME, getTargetServiceName(request));
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.INPROGRESS.toString());
+
+ if (MDC.get(ONAPLogConstants.MDCs.TARGET_ENTITY) == null) {
+ String targetEntity = getTargetEntity(request);
+ if (targetEntity != null) {
+ MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, targetEntity);
+ } else {
+ MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, Constants.DefaultValues.UNKNOWN_TARGET_ENTITY);
+ }
+ }
+ setServerFQDN();
+ }
+
+ protected String extractRequestID() {
+ String requestId = MDC.get(ONAPLogConstants.MDCs.REQUEST_ID);
+ if (requestId == null || requestId.isEmpty()) {
+ requestId = UUID.randomUUID().toString();
+ setLogTimestamp();
+ setElapsedTimeInvokeTimestamp();
+ logger.trace("No value found in MDC when checking key {} value will be set to {}",
+ ONAPLogConstants.MDCs.REQUEST_ID, requestId);
+ MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestId);
+ }
+ return requestId;
+ }
+
+ protected void post(Request request, Response response) {
+ try {
+ setLogTimestamp();
+ setElapsedTimeInvokeTimestamp();
+ setResponseStatusCode(getHttpStatusCode(response));
+ setResponseDescription(getHttpStatusCode(response));
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, getResponseCode(response));
+ additionalPost(request, response);
+ logResponse();
+ clearClientMDCs();
+ } catch (Exception e) {
+ logger.warn("Error in AbstractBaseMetricLogFilter post", e);
+ }
+ }
+
+ protected void additionalPost(Request request, Response response) {
+ // override to add application specific logic
+ }
+
+ protected String getPartnerName() {
+ return getProperty(Constants.Property.PARTNER_NAME);
+ }
+
+ protected void logRequest() {
+ logger.info(ONAPLogConstants.Markers.INVOKE, "Invoke");
+ }
+
+ protected void logResponse() {
+ logger.info(INVOKE_RETURN, "InvokeReturn");
+ }
+
+}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java
index 16efdea..bdba9b6 100644
--- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java
@@ -20,42 +20,27 @@
package org.onap.logging.filter.base;
-import java.time.ZoneOffset;
-import java.time.ZonedDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.UUID;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.slf4j.MDC;
-import org.slf4j.Marker;
-import org.slf4j.MarkerFactory;
-public abstract class AbstractMetricLogFilter<Request, Response, RequestHeaders> extends MDCSetup {
+public abstract class AbstractMetricLogFilter<Request, Response, RequestHeaders>
+ extends AbstractBaseMetricLogFilter<Request, Response> {
protected static final Logger logger = LoggerFactory.getLogger(AbstractMetricLogFilter.class);
- private final String partnerName;
- private static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE-RETURN");
public AbstractMetricLogFilter() {
- partnerName = getPartnerName();
+ super();
}
protected abstract void addHeader(RequestHeaders requestHeaders, String headerName, String headerValue);
- protected abstract String getTargetServiceName(Request request);
-
- protected abstract int getHttpStatusCode(Response response);
-
- protected abstract String getResponseCode(Response response);
-
- protected abstract String getTargetEntity(Request request);
-
protected void pre(Request request, RequestHeaders requestHeaders) {
try {
setupMDC(request);
- setupHeaders(request, requestHeaders);
+ setupHeaders(request, requestHeaders, extractRequestID(), setInvocationId());
+ additionalPre(request);
additionalPre(request, requestHeaders);
- logger.info(ONAPLogConstants.Markers.INVOKE, "Invoke");
+ logRequest();
} catch (Exception e) {
logger.warn("Error in AbstractMetricLogFilter pre", e);
}
@@ -65,9 +50,8 @@ public abstract class AbstractMetricLogFilter<Request, Response, RequestHeaders>
// override to add application specific logic
}
- protected void setupHeaders(Request clientRequest, RequestHeaders requestHeaders) {
- String requestId = extractRequestID();
- String invocationId = setInvocationId();
+ protected void setupHeaders(Request clientRequest, RequestHeaders requestHeaders, String requestId,
+ String invocationId) {
addHeader(requestHeaders, ONAPLogConstants.Headers.REQUEST_ID, requestId);
addHeader(requestHeaders, Constants.HttpHeaders.HEADER_REQUEST_ID, requestId);
addHeader(requestHeaders, Constants.HttpHeaders.TRANSACTION_ID, requestId);
@@ -75,67 +59,6 @@ public abstract class AbstractMetricLogFilter<Request, Response, RequestHeaders>
addHeader(requestHeaders, ONAPLogConstants.Headers.PARTNER_NAME, partnerName);
logger.trace("Setting X-InvocationID header for outgoing request: {}", invocationId);
addHeader(requestHeaders, ONAPLogConstants.Headers.INVOCATION_ID, invocationId);
-
- }
-
- protected String setInvocationId() {
- String invocationId = UUID.randomUUID().toString();
- MDC.put(ONAPLogConstants.MDCs.CLIENT_INVOCATION_ID, invocationId);
- MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId);
- return invocationId;
- }
-
- protected void setupMDC(Request request) {
- MDC.put(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP,
- ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT));
- MDC.put(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME, getTargetServiceName(request));
- MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.INPROGRESS.toString());
-
- if (MDC.get(ONAPLogConstants.MDCs.TARGET_ENTITY) == null) {
- String targetEntity = getTargetEntity(request);
- if (targetEntity != null) {
- MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, targetEntity);
- } else {
- MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, Constants.DefaultValues.UNKNOWN_TARGET_ENTITY);
- }
- }
- setServerFQDN();
- }
-
- protected String extractRequestID() {
- String requestId = MDC.get(ONAPLogConstants.MDCs.REQUEST_ID);
- if (requestId == null || requestId.isEmpty()) {
- requestId = UUID.randomUUID().toString();
- setLogTimestamp();
- setElapsedTimeInvokeTimestamp();
- logger.warn("No value found in MDC when checking key {} value will be set to {}",
- ONAPLogConstants.MDCs.REQUEST_ID, requestId);
- MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestId);
- }
- return requestId;
- }
-
- protected void post(Request request, Response response) {
- try {
- setLogTimestamp();
- setElapsedTimeInvokeTimestamp();
- setResponseStatusCode(getHttpStatusCode(response));
- setResponseDescription(getHttpStatusCode(response));
- MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, getResponseCode(response));
- additionalPost(request, response);
- logger.info(INVOKE_RETURN, "InvokeReturn");
- clearClientMDCs();
- } catch (Exception e) {
- logger.warn("Error in AbstractMetricLogFilter post", e);
- }
- }
-
- protected void additionalPost(Request request, Response response) {
- // override to add application specific logic
- }
-
- protected String getPartnerName() {
- return getProperty(Constants.Property.PARTNER_NAME);
}
}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/CustomFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/CustomFilter.java
new file mode 100644
index 0000000..35379d2
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/CustomFilter.java
@@ -0,0 +1,25 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - Logging
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.logging.filter.base;
+
+public interface CustomFilter<Request, Response> {
+ Boolean shouldLog(Request req, Response resp);
+}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/FilteredMetricLogClientFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/FilteredMetricLogClientFilter.java
new file mode 100644
index 0000000..0e5efae
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/FilteredMetricLogClientFilter.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - Logging
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.logging.filter.base;
+
+import java.util.Map;
+
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.client.ClientResponseContext;
+
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.slf4j.MDC;
+
+public class FilteredMetricLogClientFilter extends MetricLogClientFilter {
+ protected CustomFilter<ClientRequestContext, ClientResponseContext> customFilter;
+ private static final String REQUEST_STATE_PROPERTY_NAME = "org.onap.logging.filter.base.RequestState";
+
+ public FilteredMetricLogClientFilter(CustomFilter<ClientRequestContext, ClientResponseContext> f) {
+ customFilter = f;
+ }
+
+ protected void additionalPre(ClientRequestContext request) {
+ request.setProperty(REQUEST_STATE_PROPERTY_NAME, MDC.getCopyOfContextMap());
+ }
+
+ protected void additionalPost(ClientRequestContext request, ClientResponseContext response) {
+ if (customFilter.shouldLog(request, response)) {
+ Map<String, String> responseState = MDC.getCopyOfContextMap();
+ Map<String, String> requestState = (Map<String, String>) request.getProperty(REQUEST_STATE_PROPERTY_NAME);
+ MDC.setContextMap(requestState);
+ logger.info(ONAPLogConstants.Markers.INVOKE, "Invoke");
+ MDC.setContextMap(responseState);
+ logger.info(INVOKE_RETURN, "InvokeReturn");
+ }
+ }
+
+ protected void logRequest() {
+ // override with empty so log entries are not duplicated
+ }
+
+ protected void logResponse() {
+ // override with empty so log entries are not duplicated
+ }
+
+}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/HttpURLConnectionMetricUtil.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/HttpURLConnectionMetricUtil.java
index 3784538..39274fc 100644
--- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/HttpURLConnectionMetricUtil.java
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/HttpURLConnectionMetricUtil.java
@@ -67,14 +67,6 @@ public class HttpURLConnectionMetricUtil
return Constants.DefaultValues.UNKNOWN_TARGET_ENTITY;
}
- public void pre(HttpURLConnection request) {
- pre(request, null);
- }
-
- public void filter(HttpURLConnection request, HttpURLConnection response) {
- post(request, response);
- }
-
@Override
protected void addHeader(HttpURLConnection request, String headerName, String headerValue) {
request.setRequestProperty(headerName, headerValue);
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java
index 983c719..03dc055 100644
--- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java
@@ -54,7 +54,7 @@ public class MDCSetup {
serverFQDN = addr.getCanonicalHostName();
MDC.put(ONAPLogConstants.MDCs.SERVER_IP_ADDRESS, addr.getHostAddress());
} catch (UnknownHostException e) {
- logger.warn("Cannot Resolve Host Name");
+ logger.trace("Cannot Resolve Host Name");
serverFQDN = "";
}
MDC.put(ONAPLogConstants.MDCs.SERVER_FQDN, serverFQDN);
@@ -164,7 +164,7 @@ public class MDCSetup {
MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME,
Long.toString(ChronoUnit.MILLIS.between(entryTimestamp, endTimestamp)));
} catch (Exception e) {
- logger.warn("Unable to calculate elapsed time due to error: {}", e.getMessage());
+ logger.trace("Unable to calculate elapsed time due to error: {}", e.getMessage());
}
}
@@ -179,7 +179,7 @@ public class MDCSetup {
MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME,
Long.toString(ChronoUnit.MILLIS.between(entryTimestamp, endTimestamp)));
} catch (Exception e) {
- logger.warn("Unable to calculate elapsed time due to error: {}", e.getMessage());
+ logger.trace("Unable to calculate elapsed time due to error: {}", e.getMessage());
}
}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/PayloadLoggingServletFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/PayloadLoggingServletFilter.java
index e8d2813..fd954b7 100644
--- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/PayloadLoggingServletFilter.java
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/PayloadLoggingServletFilter.java
@@ -51,6 +51,7 @@ public class PayloadLoggingServletFilter extends AbstractServletFilter implement
private static final int defaultMaxSize = 100000;
private static Integer maxResponseSize;
private static Integer maxRequestSize;
+ protected static Boolean LOG_INVOKE;
public PayloadLoggingServletFilter() {
String maxRequestSizeOverride = System.getProperty("FILTER_MAX_REQUEST_SIZE");
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/SoapMetricLogHandler.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/SoapMetricLogHandler.java
new file mode 100644
index 0000000..088c28f
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/SoapMetricLogHandler.java
@@ -0,0 +1,87 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - Logging
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.logging.filter.base;
+
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPHandler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+public class SoapMetricLogHandler extends AbstractBaseMetricLogFilter<SOAPMessageContext, SOAPMessageContext>
+ implements SOAPHandler<SOAPMessageContext> {
+
+ @Override
+ protected int getHttpStatusCode(SOAPMessageContext ctx) {
+ return (Integer) ctx.get(MessageContext.HTTP_RESPONSE_CODE);
+ }
+
+ @Override
+ protected String getResponseCode(SOAPMessageContext ctx) {
+ Integer responseCode = (Integer) ctx.get(MessageContext.HTTP_RESPONSE_CODE);
+ return String.valueOf(responseCode);
+ }
+
+ @Override
+ protected String getTargetEntity(SOAPMessageContext ctx) {
+ return Constants.DefaultValues.UNKNOWN_TARGET_ENTITY;
+ }
+
+ @Override
+ protected String getTargetServiceName(SOAPMessageContext ctx) {
+ QName svc = (QName) ctx.get(SOAPMessageContext.WSDL_SERVICE);
+ QName op = (QName) ctx.get(SOAPMessageContext.WSDL_OPERATION);
+ return svc.getLocalPart() + ":" + op.getLocalPart();
+ }
+
+ @Override
+ public void close(MessageContext context) {
+ // pass
+ }
+
+ @Override
+ public boolean handleFault(SOAPMessageContext context) {
+ logMessage(context);
+ return true;
+ }
+
+ @Override
+ public boolean handleMessage(SOAPMessageContext context) {
+ logMessage(context);
+ return true;
+ }
+
+ @Override
+ public Set<QName> getHeaders() {
+ return null;
+ }
+
+ private void logMessage(SOAPMessageContext context) {
+ boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ if (outbound) {
+ this.pre(context);
+ } else {
+ this.post(context, context);
+ }
+ }
+
+}
diff --git a/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MetricLogClientFilterTest.java b/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MetricLogClientFilterTest.java
index a0e1a2b..cfce542 100644
--- a/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MetricLogClientFilterTest.java
+++ b/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MetricLogClientFilterTest.java
@@ -58,9 +58,8 @@ public class MetricLogClientFilterTest {
@Test
public void setupHeadersTest() {
MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
- doReturn("0a908a5d-e774-4558-96ff-6edcbba65483").when(metricLogClientFilter).extractRequestID();
- metricLogClientFilter.setupHeaders(clientRequest, headers);
+ metricLogClientFilter.setupHeaders(clientRequest, headers, "0a908a5d-e774-4558-96ff-6edcbba65483", "hello");
assertEquals("0a908a5d-e774-4558-96ff-6edcbba65483", headers.getFirst(ONAPLogConstants.Headers.REQUEST_ID));
assertEquals("0a908a5d-e774-4558-96ff-6edcbba65483", headers.getFirst(Constants.HttpHeaders.HEADER_REQUEST_ID));
diff --git a/reference/logging-filter/logging-filter-spring/src/test/java/org/onap/logging/filter/spring/SpringClientFilterTest.java b/reference/logging-filter/logging-filter-spring/src/test/java/org/onap/logging/filter/spring/SpringClientFilterTest.java
index 042e6f1..ea54345 100644
--- a/reference/logging-filter/logging-filter-spring/src/test/java/org/onap/logging/filter/spring/SpringClientFilterTest.java
+++ b/reference/logging-filter/logging-filter-spring/src/test/java/org/onap/logging/filter/spring/SpringClientFilterTest.java
@@ -120,10 +120,9 @@ public class SpringClientFilterTest extends SpringClientFilter {
@Test
public void setupHeadersTest() {
- MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, "0a908a5d-e774-4558-96ff-6edcbba65483");
-
HttpHeaders headers = new HttpHeaders();
- setupHeaders(clientRequest, headers);
+ setupHeaders(clientRequest, headers, "0a908a5d-e774-4558-96ff-6edcbba65483",
+ "4d93e6e2-ff27-4818-9752-1cfe3090d3f1");
assertEquals("0a908a5d-e774-4558-96ff-6edcbba65483", headers.getFirst(ONAPLogConstants.Headers.REQUEST_ID));
assertEquals("0a908a5d-e774-4558-96ff-6edcbba65483", headers.getFirst(Constants.HttpHeaders.HEADER_REQUEST_ID));
@@ -131,8 +130,6 @@ public class SpringClientFilterTest extends SpringClientFilter {
assertEquals("0a908a5d-e774-4558-96ff-6edcbba65483", headers.getFirst(Constants.HttpHeaders.TRANSACTION_ID));
assertEquals("0a908a5d-e774-4558-96ff-6edcbba65483", headers.getFirst(Constants.HttpHeaders.ECOMP_REQUEST_ID));
assertNotNull(headers.getFirst(ONAPLogConstants.Headers.INVOCATION_ID));
- assertNotNull(MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID));
- assertNotNull(MDC.get(ONAPLogConstants.MDCs.CLIENT_INVOCATION_ID));
assertEquals("UNKNOWN", headers.getFirst(ONAPLogConstants.Headers.PARTNER_NAME));
}