aboutsummaryrefslogtreecommitdiffstats
path: root/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging
diff options
context:
space:
mode:
Diffstat (limited to 'reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging')
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java13
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractBaseMetricLogFilter.java134
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMDCSetupAspect.java78
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java89
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AuditLogContainerFilter.java2
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/Constants.java1
-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/CustomResponseStatus.java62
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ErrorCode.java40
-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.java175
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/PayloadLoggingServletFilter.java54
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledLogging.java32
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledTaskException.java45
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledTasksMDCSetupAspect.java47
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/SoapMetricLogHandler.java87
17 files changed, 781 insertions, 173 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 ce2f448..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);
}
@@ -52,14 +52,15 @@ public abstract class AbstractAuditLogFilter<GenericRequest, GenericResponse> ex
protected void post(GenericResponse response) {
try {
+ MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, MDC.get(ONAPLogConstants.MDCs.SERVER_INVOCATION_ID));
int responseCode = getResponseCode(response);
setResponseStatusCode(responseCode);
MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, String.valueOf(responseCode));
setResponseDescription(responseCode);
setLogTimestamp();
setElapsedTime();
- logger.info(ONAPLogConstants.Markers.EXIT, "Exiting.");
additionalPostHandling(response);
+ logExiting();
} catch (Exception e) {
logger.warn("Error in AbstractInboundFilter post", e);
} finally {
@@ -79,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..4dd1b49
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractBaseMetricLogFilter.java
@@ -0,0 +1,134 @@
+/*-
+ * ============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, getCurrentTimeStamp());
+ 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();
+ setLogTimestamp();
+ setElapsedTimeInvokeTimestamp();
+ }
+
+ protected String extractRequestID() {
+ String requestId = MDC.get(ONAPLogConstants.MDCs.REQUEST_ID);
+ if (requestId == null || requestId.isEmpty()) {
+ requestId = UUID.randomUUID().toString();
+ 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/AbstractMDCSetupAspect.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMDCSetupAspect.java
new file mode 100644
index 0000000..c9424c4
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMDCSetupAspect.java
@@ -0,0 +1,78 @@
+/*-
+ * ============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.UUID;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.slf4j.MDC;
+
+public abstract class AbstractMDCSetupAspect extends MDCSetup {
+
+ public abstract void logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable;
+
+ protected void setupMDC(String methodName) {
+ try {
+ setEntryTimeStamp();
+ setServerFQDN();
+ String partnerName = getProperty(Constants.Property.PARTNER_NAME);
+ MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, UUID.randomUUID().toString());
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.INPROGRESS.toString());
+ MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, UUID.randomUUID().toString());
+ MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, partnerName);
+ MDC.put(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME, Constants.DefaultValues.UNKNOWN);
+ MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, methodName);
+ setLogTimestamp();
+ setElapsedTime();
+ MDC.put(ONAPLogConstants.MDCs.PARTNER_NAME, partnerName);
+ logger.info(ONAPLogConstants.Markers.ENTRY, "Entering");
+ } catch (Exception e) {
+ logger.warn("Error in ScheduledTasksMDCSetup: {}", e.getMessage());
+ }
+ }
+
+ protected void exitAndClearMDC() {
+ try {
+ setStatusCode();
+ setLogTimestamp();
+ setElapsedTime();
+ logger.info(ONAPLogConstants.Markers.EXIT, "Exiting.");
+ } catch (Exception e) {
+ logger.warn("Error in ScheduledTasksMDCSetup clear MDC: {}", e.getMessage());
+ }
+ MDC.clear();
+ }
+
+ protected void setStatusCode() {
+ String currentStatusCode = MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE);
+ if (currentStatusCode == null || !currentStatusCode.equals(ONAPLogConstants.ResponseStatus.ERROR.toString())) {
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.COMPLETE.toString());
+ }
+ }
+
+ public void errorMDCSetup(ErrorCode errorCode, String errorDescription) {
+ MDC.put(ONAPLogConstants.MDCs.ERROR_CODE, String.valueOf(errorCode.getValue()));
+ MDC.put(ONAPLogConstants.MDCs.ERROR_DESC, errorDescription);
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.ERROR.toString());
+ }
+
+}
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 4e164ae..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,71 +50,15 @@ 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 = UUID.randomUUID().toString();
+ 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);
addHeader(requestHeaders, Constants.HttpHeaders.ECOMP_REQUEST_ID, requestId);
addHeader(requestHeaders, ONAPLogConstants.Headers.PARTNER_NAME, partnerName);
- logger.info("Setting X-InvocationID header for outgoing request: {}", invocationId);
+ logger.trace("Setting X-InvocationID header for outgoing request: {}", invocationId);
addHeader(requestHeaders, ONAPLogConstants.Headers.INVOCATION_ID, 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());
- setInvocationIdFromMDC();
-
- 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/AuditLogContainerFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AuditLogContainerFilter.java
index 4783e7b..30f6d62 100644
--- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AuditLogContainerFilter.java
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AuditLogContainerFilter.java
@@ -27,6 +27,7 @@ import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.container.PreMatching;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Provider;
import javax.ws.rs.ext.Providers;
@@ -36,6 +37,7 @@ import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
@Priority(1)
+@PreMatching
@Provider
public class AuditLogContainerFilter extends AbstractAuditLogFilter<ContainerRequestContext, ContainerResponseContext>
implements ContainerRequestFilter, ContainerResponseFilter {
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/Constants.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/Constants.java
index be28f0b..2da32e1 100644
--- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/Constants.java
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/Constants.java
@@ -35,7 +35,6 @@ public class Constants {
public static final String TRANSACTION_ID = "X-TransactionID";
public static final String ECOMP_REQUEST_ID = "X-ECOMP-RequestID";
public static final String ONAP_REQUEST_ID = "X-ONAP-RequestID";
- public static final String CLIENT_ID = "X-ClientID";
public static final String INVOCATION_ID_HEADER = "X-InvocationID";
public static final String TARGET_ENTITY_HEADER = "X-Target-Entity";
}
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/CustomResponseStatus.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/CustomResponseStatus.java
new file mode 100644
index 0000000..91626bb
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/CustomResponseStatus.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - Logging
+ * ================================================================================
+ * Copyright (C) 2021 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 enum CustomResponseStatus {
+ PROCESSING(102, "Processing"),
+ MULTI_STATUS(207, "Multi-Status"),
+ ALREADY_REPORTED(208, "Already Reported"),
+ UNPROCESSABLE_ENTITY(422, "Unprocessable Entity"),
+ LOCKED(423, "Locked"),
+ FAILED_DEPENDENCY(424, "Failed Dependency"),
+ INSUFFICIENT_STORAGE(508, "Insufficient Storage"),
+ LOOP_DETECTED(508, "Loop Detected");
+
+ private final int code;
+ private final String reason;
+
+ CustomResponseStatus(int statusCode, String reasonPhrase) {
+ this.code = statusCode;
+ this.reason = reasonPhrase;
+ }
+
+ public static CustomResponseStatus fromStatusCode(int statusCode) {
+ for (CustomResponseStatus s : values()) {
+ if (s.code == statusCode) {
+ return s;
+ }
+ }
+
+ return null;
+ }
+
+ public int getStatusCode() {
+ return this.code;
+ }
+
+ public String getReasonPhrase() {
+ return this.toString();
+ }
+
+ public String toString() {
+ return this.reason;
+ }
+}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ErrorCode.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ErrorCode.java
new file mode 100644
index 0000000..3935ccd
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ErrorCode.java
@@ -0,0 +1,40 @@
+/*-
+ * ============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 enum ErrorCode {
+ PermissionError(100),
+ AvailabilityError(200),
+ DataError(300),
+ SchemaError(400),
+ BusinessProcessError(500),
+ UnknownError(900);
+
+ private int value;
+
+ ErrorCode(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return this.value;
+ }
+}
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 a900968..a90f053 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
@@ -25,6 +25,7 @@ import java.net.UnknownHostException;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.ChronoUnit;
import java.util.Base64;
import java.util.UUID;
@@ -39,25 +40,70 @@ import org.slf4j.MDC;
public class MDCSetup {
protected static Logger logger = LoggerFactory.getLogger(MDCSetup.class);
-
private static final String INSTANCE_UUID = UUID.randomUUID().toString();
+ protected static final String serverIpAddressOverride = "SERVER_IP_ADDRESS_OVERRIDE";
+ protected static final String serverFqdnOverride = "SERVER_FQDN_OVERRIDE";
+ protected static final String INSTANT_PRECISION_OVERRIDE = "INSTANT_PRECISION_OVERRIDE";
+ protected static final String checkHeaderLogPattern = "Checking {} header to determine the value of {}";
+ protected String serverFqdn;
+ protected String serverIpAddress;
+ protected String[] prioritizedIdHeadersNames;
+ protected String[] prioritizedPartnerHeadersNames;
+ protected DateTimeFormatter iso8601Formatter;
+
+ public MDCSetup() {
+ this.prioritizedIdHeadersNames =
+ new String[] {ONAPLogConstants.Headers.REQUEST_ID, Constants.HttpHeaders.HEADER_REQUEST_ID,
+ Constants.HttpHeaders.TRANSACTION_ID, Constants.HttpHeaders.ECOMP_REQUEST_ID};
+ this.prioritizedPartnerHeadersNames =
+ new String[] {HttpHeaders.AUTHORIZATION, ONAPLogConstants.Headers.PARTNER_NAME, HttpHeaders.USER_AGENT};
+ initServerFqdnandIp();
+ this.iso8601Formatter = createFormatter();
+ }
+
+ protected String getCurrentTimeStamp() {
+ return ZonedDateTime.now(ZoneOffset.UTC).format(iso8601Formatter);
+ }
+
+ protected DateTimeFormatter createFormatter() {
+ DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
+ try {
+ Integer instantPrecision = Integer.valueOf(System.getProperty(INSTANT_PRECISION_OVERRIDE, "3"));
+ builder.appendInstant(instantPrecision);
+ } catch (NumberFormatException nfe) {
+ logger.warn("instant precision could not be read and thus won't be set, the default will be used instead."
+ + nfe.getMessage());
+ }
+ return builder.toFormatter();
+ }
public void setInstanceID() {
MDC.put(ONAPLogConstants.MDCs.INSTANCE_UUID, INSTANCE_UUID);
}
- public void setServerFQDN() {
- String serverFQDN = "";
- InetAddress addr = null;
- try {
- addr = InetAddress.getLocalHost();
- serverFQDN = addr.getCanonicalHostName();
- MDC.put(ONAPLogConstants.MDCs.SERVER_IP_ADDRESS, addr.getHostAddress());
- } catch (UnknownHostException e) {
- logger.warn("Cannot Resolve Host Name");
- serverFQDN = "";
+ protected void initServerFqdnandIp() {
+ serverFqdn = getProperty(serverFqdnOverride);
+ serverIpAddress = getProperty(serverIpAddressOverride);
+
+ if (serverIpAddress.equals(Constants.DefaultValues.UNKNOWN)
+ || serverFqdn.equals(Constants.DefaultValues.UNKNOWN)) {
+ try {
+ InetAddress addr = InetAddress.getLocalHost();
+ if (serverFqdn.equals(Constants.DefaultValues.UNKNOWN)) {
+ serverFqdn = addr.getCanonicalHostName();
+ }
+ if (serverIpAddress.equals(Constants.DefaultValues.UNKNOWN)) {
+ serverIpAddress = addr.getHostAddress();
+ }
+ } catch (UnknownHostException e) {
+ logger.trace("Cannot Resolve Host Name." + e.getMessage());
+ }
}
- MDC.put(ONAPLogConstants.MDCs.SERVER_FQDN, serverFQDN);
+ }
+
+ public void setServerFQDN() {
+ MDC.put(ONAPLogConstants.MDCs.SERVER_FQDN, serverFqdn);
+ MDC.put(ONAPLogConstants.MDCs.SERVER_IP_ADDRESS, serverIpAddress);
}
public void setClientIPAddress(HttpServletRequest httpServletRequest) {
@@ -76,35 +122,18 @@ public class MDCSetup {
}
public void setEntryTimeStamp() {
- MDC.put(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP,
- ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT));
+ MDC.put(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP, getCurrentTimeStamp());
}
public String getRequestId(SimpleMap headers) {
- logger.trace("Checking X-ONAP-RequestID header for requestId.");
- String requestId = headers.get(ONAPLogConstants.Headers.REQUEST_ID);
- if (requestId != null && !requestId.isEmpty()) {
- return requestId;
- }
-
- logger.trace("No valid X-ONAP-RequestID header value. Checking X-RequestID header for requestId.");
- requestId = headers.get(Constants.HttpHeaders.HEADER_REQUEST_ID);
- if (requestId != null && !requestId.isEmpty()) {
- return requestId;
- }
-
- logger.trace("No valid X-RequestID header value. Checking X-TransactionID header for requestId.");
- requestId = headers.get(Constants.HttpHeaders.TRANSACTION_ID);
- if (requestId != null && !requestId.isEmpty()) {
- return requestId;
- }
-
- logger.trace("No valid X-TransactionID header value. Checking X-ECOMP-RequestID header for requestId.");
- requestId = headers.get(Constants.HttpHeaders.ECOMP_REQUEST_ID);
- if (requestId != null && !requestId.isEmpty()) {
- return requestId;
+ String requestId = null;
+ for (String headerName : this.prioritizedIdHeadersNames) {
+ logger.trace(checkHeaderLogPattern, headerName, ONAPLogConstants.Headers.REQUEST_ID);
+ requestId = headers.get(headerName);
+ if (requestId != null && !requestId.isEmpty()) {
+ return requestId;
+ }
}
-
logger.trace("No valid requestId headers. Generating requestId: {}", requestId);
return UUID.randomUUID().toString();
}
@@ -113,13 +142,7 @@ public class MDCSetup {
String invocationId = headers.get(ONAPLogConstants.Headers.INVOCATION_ID);
if (invocationId == null || invocationId.isEmpty())
invocationId = UUID.randomUUID().toString();
- MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId);
- }
-
- public void setInvocationIdFromMDC() {
- String invocationId = MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID);
- if (invocationId == null || invocationId.isEmpty())
- invocationId = UUID.randomUUID().toString();
+ MDC.put(ONAPLogConstants.MDCs.SERVER_INVOCATION_ID, invocationId);
MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId);
}
@@ -129,40 +152,26 @@ public class MDCSetup {
}
protected String getMDCPartnerName(SimpleMap headers) {
- String checkHeaderLogPattern = "Checking {} header to determine the value of {}";
-
- logger.trace(checkHeaderLogPattern, HttpHeaders.AUTHORIZATION, ONAPLogConstants.MDCs.PARTNER_NAME);
- String partnerName = getBasicAuthUserName(headers);
- if (partnerName != null && !partnerName.isEmpty()) {
- return partnerName;
- }
-
- logger.trace(checkHeaderLogPattern, ONAPLogConstants.Headers.PARTNER_NAME, ONAPLogConstants.MDCs.PARTNER_NAME);
- partnerName = headers.get(ONAPLogConstants.Headers.PARTNER_NAME);
- if (partnerName != null && !partnerName.isEmpty()) {
- return partnerName;
- }
-
- logger.trace(checkHeaderLogPattern, HttpHeaders.USER_AGENT, ONAPLogConstants.MDCs.PARTNER_NAME);
- partnerName = headers.get(HttpHeaders.USER_AGENT);
- if (partnerName != null && !partnerName.isEmpty()) {
- return partnerName;
- }
+ String partnerName = null;
+ for (String headerName : prioritizedPartnerHeadersNames) {
+ logger.trace(checkHeaderLogPattern, headerName, ONAPLogConstants.MDCs.PARTNER_NAME);
+ if (headerName.equals(HttpHeaders.AUTHORIZATION)) {
+ partnerName = getBasicAuthUserName(headers);
+ } else {
+ partnerName = headers.get(headerName);
+ }
+ if (partnerName != null && !partnerName.isEmpty()) {
+ return partnerName;
+ }
- logger.trace(checkHeaderLogPattern, Constants.HttpHeaders.CLIENT_ID, ONAPLogConstants.MDCs.PARTNER_NAME);
- partnerName = headers.get(Constants.HttpHeaders.CLIENT_ID);
- if (partnerName != null && !partnerName.isEmpty()) {
- return partnerName;
}
-
logger.trace("{} value could not be determined, defaulting partnerName to {}.",
ONAPLogConstants.MDCs.PARTNER_NAME, Constants.DefaultValues.UNKNOWN);
return Constants.DefaultValues.UNKNOWN;
}
public void setLogTimestamp() {
- MDC.put(ONAPLogConstants.MDCs.LOG_TIMESTAMP,
- ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT));
+ MDC.put(ONAPLogConstants.MDCs.LOG_TIMESTAMP, getCurrentTimeStamp());
}
public void setElapsedTime() {
@@ -176,7 +185,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());
}
}
@@ -191,7 +200,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());
}
}
@@ -202,7 +211,7 @@ public class MDCSetup {
} else {
statusCode = ONAPLogConstants.ResponseStatus.ERROR.toString();
setErrorCode(code);
- setErrorDesc(code);
+ setErrorDescription(code);
}
MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, statusCode);
}
@@ -212,7 +221,7 @@ public class MDCSetup {
}
public void clearClientMDCs() {
- MDC.remove(ONAPLogConstants.MDCs.INVOCATION_ID);
+ MDC.remove(ONAPLogConstants.MDCs.CLIENT_INVOCATION_ID);
MDC.remove(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION);
MDC.remove(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE);
MDC.remove(ONAPLogConstants.MDCs.RESPONSE_CODE);
@@ -224,15 +233,27 @@ public class MDCSetup {
}
public void setResponseDescription(int statusCode) {
- MDC.put(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION, Response.Status.fromStatusCode(statusCode).toString());
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION, extractDescription(statusCode));
+ }
+
+ private String extractDescription(int statusCode) {
+ Response.Status responseStatus = Response.Status.fromStatusCode(statusCode);
+ if (responseStatus != null) {
+ return responseStatus.toString();
+ }
+ CustomResponseStatus customResponseStatus = CustomResponseStatus.fromStatusCode(statusCode);
+ if (customResponseStatus != null) {
+ return customResponseStatus.toString();
+ }
+ return String.format("Unknown description for response code %d.", statusCode);
}
public void setErrorCode(int statusCode) {
MDC.put(ONAPLogConstants.MDCs.ERROR_CODE, String.valueOf(statusCode));
}
- public void setErrorDesc(int statusCode) {
- MDC.put(ONAPLogConstants.MDCs.ERROR_DESC, Response.Status.fromStatusCode(statusCode).toString());
+ public void setErrorDescription(int statusCode) {
+ MDC.put(ONAPLogConstants.MDCs.ERROR_DESC, extractDescription(statusCode));
}
public String getProperty(String property) {
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 0c0f5c4..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
@@ -22,18 +22,52 @@
package org.onap.logging.filter.base;
-import javax.servlet.*;
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.util.zip.GZIPInputStream;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ReadListener;
+import javax.servlet.ServletException;
+import javax.servlet.ServletInputStream;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.WriteListener;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
-import java.io.*;
-import java.util.zip.GZIPInputStream;
public class PayloadLoggingServletFilter extends AbstractServletFilter implements Filter {
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(PayloadLoggingServletFilter.class);
+ 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");
+ if (maxRequestSizeOverride != null) {
+ maxRequestSize = Integer.valueOf(maxRequestSizeOverride);
+ } else {
+ maxRequestSize = defaultMaxSize;
+ }
+ String maxResponseSizeOverride = System.getProperty("FILTER_MAX_RESPONSE_SIZE");
+ if (maxResponseSizeOverride != null) {
+ maxResponseSize = Integer.valueOf(maxResponseSizeOverride);
+ } else {
+ maxResponseSize = defaultMaxSize;
+ }
+ }
private static class ByteArrayServletStream extends ServletOutputStream {
ByteArrayOutputStream baos;
@@ -194,7 +228,13 @@ public class PayloadLoggingServletFilter extends AbstractServletFilter implement
requestHeaders.append(getSecureRequestHeaders(httpRequest));
log.info(requestHeaders.toString());
- log.info("REQUEST BODY|{}", new String(bufferedRequest.getBuffer()));
+
+ byte[] buffer = bufferedRequest.getBuffer();
+ if (buffer.length < maxRequestSize) {
+ log.info("REQUEST BODY|{}", new String(buffer));
+ } else {
+ log.info("REQUEST BODY|{}", new String(buffer, 0, maxRequestSize));
+ }
final HttpServletResponse response = (HttpServletResponse) servletResponse;
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -242,7 +282,11 @@ public class PayloadLoggingServletFilter extends AbstractServletFilter implement
if ("gzip".equals(response.getHeader("Content-Encoding"))) {
log.info("UNGZIPED RESPONSE BODY|{}", decompressGZIPByteArray(bytes));
} else {
- log.info("RESPONSE BODY|{}", new String(bytes));
+ if (bytes.length < maxResponseSize) {
+ log.info("RESPONSE BODY|{}", new String(bytes));
+ } else {
+ log.info("RESPONSE BODY|{}", new String(bytes, 0, maxResponseSize));
+ }
}
if (pw.hasErrored()) {
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledLogging.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledLogging.java
new file mode 100644
index 0000000..39e5653
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledLogging.java
@@ -0,0 +1,32 @@
+/*-
+ * ============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.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.RetentionPolicy;
+
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ScheduledLogging {
+
+}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledTaskException.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledTaskException.java
new file mode 100644
index 0000000..499d452
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledTaskException.java
@@ -0,0 +1,45 @@
+/*-
+ * ============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 class ScheduledTaskException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+ private ErrorCode errorCode;
+
+ public ScheduledTaskException(ErrorCode errorCode, String errorMessage, Throwable cause) {
+ super(errorMessage, cause);
+ this.setErrorCode(errorCode);
+ }
+
+ public ScheduledTaskException(ErrorCode errorCode, String errorMessage) {
+ super(errorMessage);
+ this.setErrorCode(errorCode);
+ }
+
+ public ErrorCode getErrorCode() {
+ return errorCode;
+ }
+
+ public void setErrorCode(ErrorCode errorCode) {
+ this.errorCode = errorCode;
+ }
+}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledTasksMDCSetupAspect.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledTasksMDCSetupAspect.java
new file mode 100644
index 0000000..74642b1
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/ScheduledTasksMDCSetupAspect.java
@@ -0,0 +1,47 @@
+/*-
+ * ============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 org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.onap.logging.filter.base.AbstractMDCSetupAspect;
+import org.onap.logging.filter.base.ScheduledTaskException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Aspect
+public class ScheduledTasksMDCSetupAspect extends AbstractMDCSetupAspect {
+
+ protected static Logger logger = LoggerFactory.getLogger(ScheduledTasksMDCSetupAspect.class);
+
+ @Around("@annotation(ScheduledLogging)")
+ public void logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
+ setupMDC(joinPoint.getSignature().getName());
+ try {
+ joinPoint.proceed();
+ } catch (ScheduledTaskException e) {
+ errorMDCSetup(e.getErrorCode(), e.getMessage());
+ logger.error("ScheduledTaskException: ", e);
+ }
+ exitAndClearMDC();
+ }
+}
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);
+ }
+ }
+
+}