summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractServletFilter.java58
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/PayloadLoggingServletFilter.java32
-rw-r--r--reference/logging-filter/logging-filter-spring/src/main/java/org/onap/logging/filter/spring/StatusLoggingInterceptor.java5
3 files changed, 61 insertions, 34 deletions
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractServletFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractServletFilter.java
new file mode 100644
index 0000000..bf165f9
--- /dev/null
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractServletFilter.java
@@ -0,0 +1,58 @@
+/*-
+ * ============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.util.Enumeration;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.core.HttpHeaders;
+
+public abstract class AbstractServletFilter {
+ protected static final String REDACTED = "***REDACTED***";
+
+ protected String getSecureRequestHeaders(HttpServletRequest httpRequest) {
+ StringBuilder sb = new StringBuilder();
+ String header;
+ for (Enumeration<String> e = httpRequest.getHeaderNames(); e.hasMoreElements();) {
+ header = e.nextElement();
+ sb.append(header);
+ sb.append(":");
+ if (header.equalsIgnoreCase(HttpHeaders.AUTHORIZATION)) {
+ sb.append(REDACTED);
+ } else {
+ sb.append(httpRequest.getHeader(header));
+ }
+ sb.append(";");
+ }
+ return sb.toString();
+ }
+
+ protected String formatResponseHeaders(HttpServletResponse response) {
+ StringBuilder sb = new StringBuilder();
+ for (String headerName : response.getHeaderNames()) {
+ sb.append(headerName);
+ sb.append(":");
+ sb.append(response.getHeader(headerName));
+ sb.append(";");
+ }
+ return sb.toString();
+ }
+}
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 4b9cd1f..fa8533a 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
@@ -29,7 +29,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
-import java.util.Enumeration;
import java.util.zip.GZIPInputStream;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@@ -45,12 +44,10 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
-import javax.ws.rs.core.HttpHeaders;
-public class PayloadLoggingServletFilter implements Filter {
+public class PayloadLoggingServletFilter extends AbstractServletFilter implements Filter {
private static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(PayloadLoggingServletFilter.class);
- private static final String REDACTED = "***REDACTED***";
private static class ByteArrayServletStream extends ServletOutputStream {
ByteArrayOutputStream baos;
@@ -330,31 +327,4 @@ public class PayloadLoggingServletFilter implements Filter {
return str.toString();
}
- protected String getSecureRequestHeaders(HttpServletRequest httpRequest) {
- StringBuilder sb = new StringBuilder();
- String header;
- for (Enumeration<String> e = httpRequest.getHeaderNames(); e.hasMoreElements();) {
- header = e.nextElement();
- sb.append(header);
- sb.append(":");
- if (header.equalsIgnoreCase(HttpHeaders.AUTHORIZATION)) {
- sb.append(REDACTED);
- } else {
- sb.append(httpRequest.getHeader(header));
- }
- sb.append(";");
- }
- return sb.toString();
- }
-
- protected String formatResponseHeaders(HttpServletResponse response) {
- StringBuilder sb = new StringBuilder();
- for (String headerName : response.getHeaderNames()) {
- sb.append(headerName);
- sb.append(":");
- sb.append(response.getHeader(headerName));
- sb.append(";");
- }
- return sb.toString();
- }
}
diff --git a/reference/logging-filter/logging-filter-spring/src/main/java/org/onap/logging/filter/spring/StatusLoggingInterceptor.java b/reference/logging-filter/logging-filter-spring/src/main/java/org/onap/logging/filter/spring/StatusLoggingInterceptor.java
index 887e621..3401efa 100644
--- a/reference/logging-filter/logging-filter-spring/src/main/java/org/onap/logging/filter/spring/StatusLoggingInterceptor.java
+++ b/reference/logging-filter/logging-filter-spring/src/main/java/org/onap/logging/filter/spring/StatusLoggingInterceptor.java
@@ -26,16 +26,15 @@ import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Providers;
-import org.onap.logging.filter.base.PayloadLoggingServletFilter;
+import org.onap.logging.filter.base.AbstractServletFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
-// TODO do we want this class to log message payloads? In the previous implementation it did not
@Component
-public class StatusLoggingInterceptor extends PayloadLoggingServletFilter implements HandlerInterceptor {
+public class StatusLoggingInterceptor extends AbstractServletFilter implements HandlerInterceptor {
private static final Logger logger = LoggerFactory.getLogger(StatusLoggingInterceptor.class);