summaryrefslogtreecommitdiffstats
path: root/common/src/main/java
diff options
context:
space:
mode:
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";
- }
-
}