aboutsummaryrefslogtreecommitdiffstats
path: root/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AuditLogContainerFilter.java
diff options
context:
space:
mode:
authorBrittany Plummer (bp896r) <bp896r@att.com>2019-08-27 15:36:44 -0400
committerKevin Smokowski <kevin.smokowski@att.com>2019-08-29 20:37:00 +0000
commit5104a66d12a2ada0819d1cbcaf935785748f2b87 (patch)
tree1a48cbc173ff46060bbcf679f83a75a23d194df9 /reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AuditLogContainerFilter.java
parented4107f4ff0aa1ad65a96371bf69242847daedaa (diff)
Add JAX-RS and Spring filters for setting up MDC
Issue-ID: LOG-1113 Change-Id: I7167943384e3983c7eced1c969ed51fcd8130c88 Signed-off-by: Brittany Plummer (bp896r) <bp896r@att.com>
Diffstat (limited to 'reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AuditLogContainerFilter.java')
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AuditLogContainerFilter.java75
1 files changed, 75 insertions, 0 deletions
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
new file mode 100644
index 0000000..3d04b62
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AuditLogContainerFilter.java
@@ -0,0 +1,75 @@
+/*-
+ * ============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.io.IOException;
+import javax.annotation.Priority;
+import javax.servlet.http.HttpServletRequest;
+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.core.Context;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.Providers;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+
+@Priority(1)
+@Provider
+public class AuditLogContainerFilter extends AbstractAuditLogFilter<ContainerRequestContext, ContainerResponseContext>
+ implements ContainerRequestFilter, ContainerResponseFilter {
+
+ protected static Logger logger = LoggerFactory.getLogger(AuditLogContainerFilter.class);
+
+ @Context
+ private HttpServletRequest httpServletRequest;
+
+ @Context
+ private Providers providers;
+
+ private MDCSetup mdcSetup = new MDCSetup();
+
+ @Override
+ public void filter(ContainerRequestContext containerRequest) {
+ SimpleMap headers = new SimpleJaxrsHeadersMap(containerRequest.getHeaders());
+ pre(mdcSetup, headers, containerRequest, httpServletRequest);
+ }
+
+ @Override
+ public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
+ throws IOException {
+ post(mdcSetup, responseContext);
+ }
+
+ @Override
+ protected void setServiceName(ContainerRequestContext containerRequest) {
+ MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, containerRequest.getUriInfo().getPath());
+ }
+
+ @Override
+ protected int getResponseCode(ContainerResponseContext response) {
+ return response.getStatus();
+ }
+
+}