summaryrefslogtreecommitdiffstats
path: root/reference/logging-filter
diff options
context:
space:
mode:
authorPrudence Au <prudence.au@amdocs.com>2020-02-12 23:56:57 +0000
committerGerrit Code Review <gerrit@onap.org>2020-02-12 23:56:57 +0000
commit2c101110dbd2b8cf4ad82eec2c6848a0b671edf2 (patch)
tree04c39887ec6c3b5212f407dba27051869afca7d9 /reference/logging-filter
parente472260ef3aced8db16dcadb47f9b06e01fa261a (diff)
parenta9f822d903faf80df94c08bd881788956f7f2640 (diff)
Merge "PayloadLoggingServletFilter update"
Diffstat (limited to 'reference/logging-filter')
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/PayloadLoggingServletFilter.java53
1 files changed, 48 insertions, 5 deletions
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()) {