diff options
author | 2019-09-11 13:38:45 +0000 | |
---|---|---|
committer | 2019-09-11 14:36:27 +0000 | |
commit | 66930a9199640842054baa070ed4c7d3b5b6adc0 (patch) | |
tree | 9d246a31bf8b0e43eebfb39ccd5385c972ed2c42 /reference/logging-filter/logging-filter-base | |
parent | af7b98db7774e3232a9fe3b988a0c7f86a1af4ea (diff) |
Update StatusLoggingInterceptor
StatusLoggingInterceptor should not extend PayloadLoggingServletFilter
Issue-ID: LOG-1127
Signed-off-by: Smokowski, Kevin (ks6305) <kevin.smokowski@att.com>
Change-Id: Ic66ee14445efd57c92b4fcc894ec0b4c5470a441
Diffstat (limited to 'reference/logging-filter/logging-filter-base')
2 files changed, 59 insertions, 31 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(); - } } |