From f0d0522cf3e32162a1160588ad6b2c2d07063abe Mon Sep 17 00:00:00 2001
From: "Smokowski, Steve (ss835w)" <ss835w@us.att.com>
Date: Fri, 10 Aug 2018 12:09:06 -0400
Subject: Fix Error Scenario

If Camunda returns a non-auth error, or invalid JSON. APIH was not
logging the error or properly updating the request database record

Issue-ID: SO-818
Change-Id: I8b164002132ca6c25f95e1fa2b194e6cb4c3be03

Change-Id: If6e06de0fb8a01a00ef06ade915dd7c13623047b
Signed-off-by: Smokowski, Steve (ss835w) <ss835w@us.att.com>
---
 .../org/onap/so/apihandlerinfra/ServiceInstances.java  | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

(limited to 'mso-api-handlers/mso-api-handler-infra/src/main/java')

diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
index e259839d6e..b241a5136e 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
@@ -845,8 +845,20 @@ public class ServiceInstances {
             throw clientException;
 		}
 
-		ResponseHandler respHandler = new ResponseHandler (response, requestClient.getType ());
-		int bpelStatus = respHandler.getStatus ();
+		ResponseHandler respHandler = null;
+        int bpelStatus = 500;
+        try {
+            respHandler = new ResponseHandler (response, requestClient.getType ());
+            bpelStatus = respHandler.getStatus ();
+        } catch (ApiException e) {
+            msoLogger.error(e);
+            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, MsoLogger.ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
+            ValidateException validateException = new ValidateException.Builder("Exception caught mapping Camunda JSON response to object", HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).cause(e)
+                        .errorInfo(errorLoggerInfo).build();
+            currentActiveReq.setRequestStatus(Status.FAILED.name());
+            currentActiveReq.setStatusMessage(validateException.getMessage());
+           throw validateException;
+        }
 
 		// BPEL accepted the request, the request is in progress
 		if (bpelStatus == HttpStatus.SC_ACCEPTED) {
@@ -858,7 +870,7 @@ public class ServiceInstances {
 					ObjectMapper mapper = new ObjectMapper();
 					jsonResponse = mapper.readValue(camundaResp.getResponse(), ServiceInstancesResponse.class);
 				} catch (IOException e) {
-					e.printStackTrace();
+					msoLogger.error(e);
 					ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, MsoLogger.ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
 					ValidateException validateException = new ValidateException.Builder("Exception caught mapping Camunda JSON response to object", HttpStatus.SC_NOT_ACCEPTABLE, ErrorNumbers.SVC_BAD_PARAMETER).cause(e)
 			                    .errorInfo(errorLoggerInfo).build();
-- 
cgit