From 0ff46010362eed22971dc462ba6b112c2aea78ec Mon Sep 17 00:00:00 2001 From: Wojciech Sliwka Date: Tue, 6 Nov 2018 09:53:54 +0100 Subject: Fix reading entity ensure that response is read only once Change-Id: Id456263f58f8d69ad1a484f26352db62b74a4f08 Issue-ID: VID-227 Signed-off-by: Wojciech Sliwka --- .../src/main/java/org/onap/vid/aai/AaiClient.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'vid-app-common/src/main/java') diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java index c1964c161..06e0f0174 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java @@ -413,9 +413,7 @@ public class AaiClient implements AaiClientInterface { } else { logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "getSubscribers() resp=" + resp.getStatusInfo().toString()); if (resp.getStatus() != HttpStatus.SC_OK) { - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "Invalid response from AAI"); - String rawData = resp.readEntity(String.class); - subscriberDataResponse = new AaiResponse<>(null, rawData, resp.getStatus()); + subscriberDataResponse = processFailureResponse(resp,responseBody); } else { subscriberDataResponse = processOkResponse(resp, classType, responseBody, omType, propagateExceptions); } @@ -423,6 +421,17 @@ public class AaiClient implements AaiClientInterface { return subscriberDataResponse; } + private AaiResponse processFailureResponse(Response resp, String responseBody) { + logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "Invalid response from AAI"); + String rawData; + if (responseBody != null) { + rawData = responseBody; + } else { + rawData = resp.readEntity(String.class); + } + return new AaiResponse<>(null, rawData, resp.getStatus()); + } + private AaiResponse processOkResponse(Response resp, Class classType, String responseBody, VidObjectMapperType omType, boolean propagateExceptions) { AaiResponse subscriberDataResponse; String finalResponse = null; -- cgit 1.2.3-korg