summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSmokowski, Kevin (ks6305) <kevin.smokowski@att.com>2019-09-20 15:48:14 +0000
committerSmokowski, Kevin (ks6305) <kevin.smokowski@att.com>2019-09-20 16:14:14 +0000
commitb313283ddae4d435d6a96b4dd1e33f74c22ca2ad (patch)
tree1543ef906d95fe405716ea6fb2e4b5b59ef70ab5
parent94e4eb867e0194f6fe99f472eb60c41044df63f2 (diff)
PayloadLoggingClientFilter bugfix
log response body in PayloadLoggingClientFilter Issue-ID: LOG-1146 Signed-off-by: Smokowski, Kevin (ks6305) <kevin.smokowski@att.com> Change-Id: I17a96f40577ba709d7f623209cdd19143dc8f1ec
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractServletFilter.java3
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/Constants.java1
-rw-r--r--reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/PayloadLoggingClientFilter.java11
-rw-r--r--reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/PayloadLoggingClientFilterTest.java2
4 files changed, 10 insertions, 7 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
index bf165f9..28495c8 100644
--- 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
@@ -26,7 +26,6 @@ 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();
@@ -36,7 +35,7 @@ public abstract class AbstractServletFilter {
sb.append(header);
sb.append(":");
if (header.equalsIgnoreCase(HttpHeaders.AUTHORIZATION)) {
- sb.append(REDACTED);
+ sb.append(Constants.REDACTED);
} else {
sb.append(httpRequest.getHeader(header));
}
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/Constants.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/Constants.java
index 1549be1..be28f0b 100644
--- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/Constants.java
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/Constants.java
@@ -21,6 +21,7 @@
package org.onap.logging.filter.base;
public class Constants {
+ protected static final String REDACTED = "***REDACTED***";
public static final class DefaultValues {
public static final String UNKNOWN = "UNKNOWN";
diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/PayloadLoggingClientFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/PayloadLoggingClientFilter.java
index 3777719..88c95aa 100644
--- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/PayloadLoggingClientFilter.java
+++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/PayloadLoggingClientFilter.java
@@ -92,6 +92,8 @@ public class PayloadLoggingClientFilter implements ClientRequestFilter, ClientRe
for (String header : headers.keySet()) {
if (!header.equals(HttpHeaders.AUTHORIZATION)) {
printHeaders.add(header, headers.getFirst(header));
+ } else {
+ printHeaders.add(header, Constants.REDACTED);;
}
}
return printHeaders.toString();
@@ -99,13 +101,14 @@ public class PayloadLoggingClientFilter implements ClientRequestFilter, ClientRe
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
- final StringBuilder sb = new StringBuilder();
- if (responseContext.hasEntity()) {
- responseContext.setEntityStream(logInboundEntity(sb, responseContext.getEntityStream(), DEFAULT_CHARSET));
- }
String method = formatMethod(requestContext);
logger.debug("Response from method:{} performed on uri:{} has http status code:{} and response headers:{}",
method, requestContext.getUri(), responseContext.getStatus(), responseContext.getHeaders().toString());
+ if (responseContext.hasEntity()) {
+ final StringBuilder sb = new StringBuilder();
+ responseContext.setEntityStream(logInboundEntity(sb, responseContext.getEntityStream(), DEFAULT_CHARSET));
+ logger.debug(sb.toString());
+ }
}
@Override
diff --git a/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/PayloadLoggingClientFilterTest.java b/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/PayloadLoggingClientFilterTest.java
index 0290784..c2446a3 100644
--- a/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/PayloadLoggingClientFilterTest.java
+++ b/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/PayloadLoggingClientFilterTest.java
@@ -69,6 +69,6 @@ public class PayloadLoggingClientFilterTest {
String printHeaders = payloadLoggingClientFilter.getHeaders(headers);
- assertEquals("{X-ONAP-PartnerName=[SO]}", printHeaders);
+ assertEquals("{Authorization=[***REDACTED***], X-ONAP-PartnerName=[SO]}", printHeaders);
}
}