Merge Casablanca
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / client / namingservice / NamingClientResponseValidator.java
index ab06395..3dcafe0 100644 (file)
@@ -1,5 +1,26 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
 package org.onap.so.client.namingservice;
 
+import java.io.IOException;
 import java.util.List;
 
 import org.apache.http.HttpStatus;
@@ -12,6 +33,9 @@ import org.onap.so.logger.MessageEnum;
 import org.onap.so.logger.MsoLogger;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Component;
+import org.springframework.web.client.HttpStatusCodeException;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
 
 @Component
 public class NamingClientResponseValidator {
@@ -99,5 +123,20 @@ public class NamingClientResponseValidator {
        private boolean isHttpCodeSuccess(int code) {
         return code >= HttpStatus.SC_OK && code < HttpStatus.SC_MULTIPLE_CHOICES || code == 0;
     }
+       
+       protected String formatError(HttpStatusCodeException e) throws IOException {
+               ObjectMapper mapper = new ObjectMapper();
+               NameGenResponse errorResponse = mapper.readValue(e.getResponseBodyAsString(), NameGenResponse.class);
+               NameGenResponseError error = errorResponse.getError();
+               
+               String errorMessageString = null;
+               if (error != null) {
+                       errorMessageString = error.getMessage();
+               }
+               String errorMessage = String.format(NAMING_SERVICE_ERROR, errorMessageString);
+               msoLogger.error(MessageEnum.RA_GENERAL_EXCEPTION, errorMessage, "BPMN", MsoLogger.getServiceName(),
+                               MsoLogger.ErrorCode.DataError, errorMessage);
+               return errorMessage;
+       }
 
 }