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>
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/ResponseExceptionMapperImplTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/ResponseExceptionMapperImplTest.java
index 2df4b0b..14a3039 100644
--- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/ResponseExceptionMapperImplTest.java
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/ResponseExceptionMapperImplTest.java
@@ -95,7 +95,7 @@
         // given
     	Response response = createMockResponse(Status.BAD_REQUEST);
         when(response.hasEntity()).thenReturn(true);
-        when(response.getEntity()).thenReturn(new ByteArrayInputStream("test message".getBytes(StandardCharsets.UTF_8)));
+        when(response.readEntity(String.class)).thenReturn("test message");
         
         expectedExceptionTest.expect(BadRequestException.class);
         expectedExceptionTest.expectMessage("test message");
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 31cdd50..bcc60b6 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.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");
+			try {
+				response.bufferEntity();
+				if (response.hasEntity()) {
+					body = response.readEntity(String.class);
 				}
-				Optional<String> result = this.extractMessage(writer.toString());
-				if (result.isPresent()) {
-					message = result.get();
-				}
+			} 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 6c2a96c..436faef 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 @@
                 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 @@
         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";
-    }
-
 }
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java
index a55fbc9..73fbff6 100644
--- a/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java
@@ -35,6 +35,7 @@
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.spy;
 
+import javax.ws.rs.BadRequestException;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -207,6 +208,23 @@
 	}
 	
 	@Test
+	public void verifyFailedCallException() {
+		AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test");
+		wireMockRule.stubFor(get(
+				urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
+				.willReturn(
+					aResponse()
+					.withHeader("Content-Type", "text/plain")
+					.withBodyFile("aai/error-message.json")
+					.withStatus(400)));
+		AAIResourcesClient client= aaiClient;
+		
+		thrown.expect(BadRequestException.class);
+		thrown.expectMessage(containsString("Invalid input performing PUT on url (msg=Precondition Required:resource-version not passed for update of url"));
+		AAIResultWrapper result = client.get(path);
+	}
+	
+	@Test
 	public void buildRelationshipTest() {
 		AAIResourcesClient client = aaiClient;
 		AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test");
diff --git a/common/src/test/resources/__files/aai/error-message.json b/common/src/test/resources/__files/aai/error-message.json
new file mode 100644
index 0000000..1552322
--- /dev/null
+++ b/common/src/test/resources/__files/aai/error-message.json
@@ -0,0 +1 @@
+{"requestError":{"serviceException":{"messageId":"SVC3000","text":"Invalid input performing %1 on %2 (msg=%3) (ec=%4)","variables":["PUT","url","Precondition Required:resource-version not passed for update of url","ERR.5.4.6130"]}}}
\ No newline at end of file