From c729cb1356a3bacead0d9d63920c889966f64bdd Mon Sep 17 00:00:00 2001 From: Eylon Malin Date: Thu, 12 Sep 2019 17:02:46 +0300 Subject: logging of HttpResponse use raw body print raw body for cases like errors make sure the response can be read logging it Issue-ID: VID-611 Signed-off-by: Eylon Malin Change-Id: If138531f515fb2927a13417040b68e81babebc4e --- vid-app-common/src/main/java/org/onap/vid/utils/Logging.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'vid-app-common/src/main/java/org/onap') diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java b/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java index 77b7ee869..0d8e58878 100644 --- a/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java +++ b/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java @@ -31,11 +31,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.google.common.collect.ImmutableList; import io.joshworks.restclient.http.HttpResponse; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Optional; import java.util.UUID; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.util.SystemProperties; @@ -123,7 +125,9 @@ public class Logging { public void logResponse(final EELFLogger logger, final HttpMethod method, final String url, final HttpResponse response) { try { - logger.debug("Received {} {} Status: {} . Body: {}", method.name(), url, response.getStatus(), response.getBody()); + logger.debug("Received {} {} Status: {} . Body: {}", method.name(), + url, response.getStatus(), IOUtils.toString(response.getRawBody(), StandardCharsets.UTF_8)); + response.getRawBody().reset(); } catch (Exception e) { logger.debug("Received {} {} Status: {} . Failed to read response", method.name(), url, response.getStatus()); -- cgit 1.2.3-korg