diff options
Diffstat (limited to 'reference/logging-filter/logging-filter-base')
-rw-r--r-- | reference/logging-filter/logging-filter-base/pom.xml | 14 | ||||
-rw-r--r-- | reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/PayloadLoggingServletFilter.java | 53 |
2 files changed, 51 insertions, 16 deletions
diff --git a/reference/logging-filter/logging-filter-base/pom.xml b/reference/logging-filter/logging-filter-base/pom.xml index e01ea0c..7bd9340 100644 --- a/reference/logging-filter/logging-filter-base/pom.xml +++ b/reference/logging-filter/logging-filter-base/pom.xml @@ -5,11 +5,13 @@ <parent> <groupId>org.onap.logging-analytics</groupId> <artifactId>logging-filter-parent</artifactId> - <version>1.6.3-SNAPSHOT</version> + <version>1.6.6-SNAPSHOT</version> </parent> <artifactId>logging-filter-base</artifactId> + <name>logging-analytics :: ${project.artifactId}</name> + <dependencies> <dependency> <groupId>javax.annotation</groupId> @@ -37,11 +39,6 @@ <scope>test</scope> </dependency> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-client</artifactId> <version>2.25.1</version> @@ -53,10 +50,5 @@ <version>2.10.0</version> <scope>test</scope> </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <scope>test</scope> - </dependency> </dependencies> </project> 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..e8d2813 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,51 @@ 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; + + 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 +227,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 +281,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()) { |