summaryrefslogtreecommitdiffstats
path: root/common/src/main/java
diff options
context:
space:
mode:
authorBenjamin, Max (mb388a) <mb388a@us.att.com>2019-02-22 17:51:42 -0500
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-02-22 17:51:56 -0500
commit57af0e334073b329ca9f48b353ab4cc3bd2027a8 (patch)
tree8df57e53bc98bec68b3fa12e7c0ab3694f71c994 /common/src/main/java
parent3163cdda24894994dbfa834dbf530bea71e076ba (diff)
remove payload logging from metric/audit side
fixed unit test after changing how entities are read remove payload logging from metric/audit side Change-Id: Ibfe7cf96c76920926e9ae9ce5041389324d09b46 Issue-ID: SO-1564 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'common/src/main/java')
-rw-r--r--common/src/main/java/org/onap/so/client/ResponseExceptionMapper.java36
-rw-r--r--common/src/main/java/org/onap/so/logging/jaxrs/filter/JaxRsClientLogging.java18
2 files changed, 19 insertions, 35 deletions
diff --git a/common/src/main/java/org/onap/so/client/ResponseExceptionMapper.java b/common/src/main/java/org/onap/so/client/ResponseExceptionMapper.java
index 31cdd50aee..bcc60b6915 100644
--- a/common/src/main/java/org/onap/so/client/ResponseExceptionMapper.java
+++ b/common/src/main/java/org/onap/so/client/ResponseExceptionMapper.java
@@ -20,9 +20,6 @@
package org.onap.so.client;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
import java.util.Optional;
import javax.ws.rs.BadRequestException;
@@ -33,29 +30,34 @@ import javax.ws.rs.NotAllowedException;
import javax.ws.rs.NotAuthorizedException;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.NotSupportedException;
+import javax.ws.rs.ProcessingException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
-import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public abstract class ResponseExceptionMapper {
-
+ private static final Logger logger = LoggerFactory.getLogger(ResponseExceptionMapper.class);
public void map(Response response) {
-
- response.bufferEntity();
if (response.getStatus() >= 300) {
+ String body = "";
String message = "empty message";
- if (response.hasEntity()) {
- StringWriter writer = new StringWriter();
- try {
- IOUtils.copy((InputStream)response.getEntity(), writer, "UTF-8");
- } catch (IOException e) {
- writer.append("failed to read entity stream");
- }
- Optional<String> result = this.extractMessage(writer.toString());
- if (result.isPresent()) {
- message = result.get();
+ try {
+ response.bufferEntity();
+ if (response.hasEntity()) {
+ body = response.readEntity(String.class);
}
+ } catch (IllegalStateException e) {
+ body = "failed to read entity stream";
+ logger.error(body, e);
+ } catch (ProcessingException e) {
+ body = "could not buffer stream";
+ logger.error(body, e);
+ }
+ Optional<String> result = this.extractMessage(body);
+ if (result.isPresent()) {
+ message = result.get();
}
Response.Status status = Response.Status.fromStatusCode(response.getStatus());
WebApplicationException webAppException;
diff --git a/common/src/main/java/org/onap/so/logging/jaxrs/filter/JaxRsClientLogging.java b/common/src/main/java/org/onap/so/logging/jaxrs/filter/JaxRsClientLogging.java
index 6c2a96c87d..436faef27f 100644
--- a/common/src/main/java/org/onap/so/logging/jaxrs/filter/JaxRsClientLogging.java
+++ b/common/src/main/java/org/onap/so/logging/jaxrs/filter/JaxRsClientLogging.java
@@ -121,7 +121,6 @@ public class JaxRsClientLogging implements ClientRequestFilter,ClientResponseFil
statusCode=ONAPLogConstants.ResponseStatus.ERROR.toString();
}
MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, String.valueOf(responseContext.getStatus()));
- MDC.put(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION,getStringFromInputStream(responseContext));
MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, statusCode);
logger.info(ONAPLogConstants.Markers.INVOKE_RETURN, "InvokeReturn");
clearClientMDCs();
@@ -142,21 +141,4 @@ public class JaxRsClientLogging implements ClientRequestFilter,ClientResponseFil
MDC.remove(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP);
}
- private static String getStringFromInputStream(ClientResponseContext clientResponseContext) {
-
- InputStream is = clientResponseContext.getEntityStream();
- ByteArrayOutputStream boas = new ByteArrayOutputStream();
-
- try {
- IOUtils.copy(is,boas);
- InputStream copiedStream = new ByteArrayInputStream(boas.toByteArray());
- clientResponseContext.setEntityStream(copiedStream);
- return boas.toString();
-
- } catch (IOException e) {
- logger.warn("Failed to read response body", e);
- }
- return "Unable to read input stream";
- }
-
}