diff options
Diffstat (limited to 'reference/logging-filter')
4 files changed, 64 insertions, 47 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()) { diff --git a/reference/logging-filter/logging-filter-spring/pom.xml b/reference/logging-filter/logging-filter-spring/pom.xml index 3f7c659..8d971d1 100644 --- a/reference/logging-filter/logging-filter-spring/pom.xml +++ b/reference/logging-filter/logging-filter-spring/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-spring</artifactId> + <name>logging-analytics :: ${project.artifactId}</name> + <dependencyManagement> <dependencies> <dependency> @@ -53,19 +55,9 @@ <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> <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/pom.xml b/reference/logging-filter/pom.xml index a25c9a5..e518620 100644 --- a/reference/logging-filter/pom.xml +++ b/reference/logging-filter/pom.xml @@ -5,12 +5,14 @@ <parent> <groupId>org.onap.logging-analytics</groupId> <artifactId>logging-reference</artifactId> - <version>1.6.3-SNAPSHOT</version> + <version>1.6.6-SNAPSHOT</version> </parent> <artifactId>logging-filter-parent</artifactId> <packaging>pom</packaging> + <name>logging-analytics :: ${project.artifactId}</name> + <modules> <module>logging-filter-base</module> <module>logging-filter-spring</module> @@ -59,18 +61,6 @@ <version>2.11.2</version> <scope>test</scope> </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.11</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <version>2.15.0</version> - <scope>test</scope> - </dependency> </dependencies> </dependencyManagement> @@ -100,13 +90,13 @@ </plugin> <!-- Plugin to Generate/Validate Copyright License header --> - <!-- <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>license-maven-plugin</artifactId> <version>1.20</version> <configuration> <processStartTag>============LICENSE_START=======================================================</processStartTag> - <sectionDelimiter>================================================================================</sectionDelimiter> <processEndTag>============LICENSE_END=========================================================</processEndTag> - <licenseName>apache_v2</licenseName> <inceptionYear>2019</inceptionYear> <organizationName>AT&T Intellectual Property. All rights reserved.</organizationName> <projectName>ONAP - - Logging</projectName> <addJavaLicenseAfterPackage>false</addJavaLicenseAfterPackage> <skipUpdateLicense>${format.skipExecute}</skipUpdateLicense> <skipCheckLicense>${format.skipValidate}</skipCheckLicense> - </configuration> <executions> <execution> <id>update-headers</id> <goals> <goal>update-file-header</goal> </goals> <phase>process-sources</phase> <configuration> <canUpdateCopyright>true</canUpdateCopyright> - <canUpdateDescription>true</canUpdateDescription> <canUpdateLicense>true</canUpdateLicense> <emptyLineAfterHeader>true</emptyLineAfterHeader> </configuration> </execution> <execution> - <id>check-headers</id> <goals> <goal>check-file-header</goal> </goals> <phase>validate</phase> <configuration> <failOnNotUptodateHeader>true</failOnNotUptodateHeader> <failOnMissingHeader>true</failOnMissingHeader> + <!-- <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>license-maven-plugin</artifactId> <version>1.20</version> <configuration> <processStartTag>============LICENSE_START=======================================================</processStartTag> + <sectionDelimiter>================================================================================</sectionDelimiter> <processEndTag>============LICENSE_END=========================================================</processEndTag> + <licenseName>apache_v2</licenseName> <inceptionYear>2019</inceptionYear> <organizationName>AT&T Intellectual Property. All rights reserved.</organizationName> <projectName>ONAP + - Logging</projectName> <addJavaLicenseAfterPackage>false</addJavaLicenseAfterPackage> <skipUpdateLicense>${format.skipExecute}</skipUpdateLicense> <skipCheckLicense>${format.skipValidate}</skipCheckLicense> + </configuration> <executions> <execution> <id>update-headers</id> <goals> <goal>update-file-header</goal> </goals> <phase>process-sources</phase> <configuration> <canUpdateCopyright>true</canUpdateCopyright> + <canUpdateDescription>true</canUpdateDescription> <canUpdateLicense>true</canUpdateLicense> <emptyLineAfterHeader>true</emptyLineAfterHeader> </configuration> </execution> <execution> + <id>check-headers</id> <goals> <goal>check-file-header</goal> </goals> <phase>validate</phase> <configuration> <failOnNotUptodateHeader>true</failOnNotUptodateHeader> <failOnMissingHeader>true</failOnMissingHeader> </configuration> </execution> </executions> </plugin> --> <!-- Plugin to Format/Validate Java Classes --> |