From b313283ddae4d435d6a96b4dd1e33f74c22ca2ad Mon Sep 17 00:00:00 2001 From: "Smokowski, Kevin (ks6305)" Date: Fri, 20 Sep 2019 15:48:14 +0000 Subject: PayloadLoggingClientFilter bugfix log response body in PayloadLoggingClientFilter Issue-ID: LOG-1146 Signed-off-by: Smokowski, Kevin (ks6305) Change-Id: I17a96f40577ba709d7f623209cdd19143dc8f1ec --- .../org/onap/logging/filter/base/AbstractServletFilter.java | 3 +-- .../src/main/java/org/onap/logging/filter/base/Constants.java | 1 + .../onap/logging/filter/base/PayloadLoggingClientFilter.java | 11 +++++++---- .../logging/filter/base/PayloadLoggingClientFilterTest.java | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) (limited to 'reference') 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); } } -- cgit 1.2.3-korg