Fix DCAE connection issue
[clamp.git] / src / main / java / org / onap / clamp / clds / client / DcaeInventoryServices.java
index a53ea64..7662a9f 100644 (file)
@@ -27,17 +27,11 @@ import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;\r
 import com.fasterxml.jackson.core.JsonProcessingException;\r
 \r
-import java.io.BufferedReader;\r
 import java.io.IOException;\r
-import java.io.InputStreamReader;\r
-import java.net.HttpURLConnection;\r
-import java.net.URL;\r
 import java.security.GeneralSecurityException;\r
 import java.util.Date;\r
 import java.util.List;\r
 \r
-import javax.ws.rs.BadRequestException;\r
-\r
 import org.json.simple.JSONArray;\r
 import org.json.simple.JSONObject;\r
 import org.json.simple.parser.JSONParser;\r
@@ -67,8 +61,6 @@ public class DcaeInventoryServices {
     private RefProp                   refProp;\r
     @Autowired\r
     private CldsDao                   cldsDao;\r
-    @Autowired\r
-    private SdcCatalogServices        sdcCatalogServices;\r
 \r
     /**\r
      * \r
@@ -117,7 +109,7 @@ public class DcaeInventoryServices {
         } catch (JsonProcessingException e) {\r
             logger.error("Error during JSON decoding", e);\r
         } catch (IOException ex) {\r
-            logger.error("Error during JSON decoding", ex);\r
+            logger.error("Error during DCAE communication", ex);\r
         } finally {\r
             LoggingUtils.setTimeContext(startTime, new Date());\r
             metricsLogger.info("setEventInventory complete");\r
@@ -160,9 +152,7 @@ public class DcaeInventoryServices {
      *            The resource UUID\r
      * @return The DCAE inventory for the artifact\r
      * @throws IOException\r
-     *             In case of issues with the stream\r
      * @throws ParseException\r
-     *             In case of issues with the Json parsing\r
      * \r
      */\r
     public String getDcaeInformation(String artifactName, String serviceUuid, String resourceUuid)\r
@@ -174,34 +164,9 @@ public class DcaeInventoryServices {
         String fullUrl = refProp.getStringValue("DCAE_INVENTORY_URL") + "/dcae-service-types" + queryString;\r
         logger.info("Dcae Inventory Service full url - " + fullUrl);\r
         String daceInventoryResponse = null;\r
-        URL inventoryUrl = new URL(fullUrl);\r
-        HttpURLConnection conn = (HttpURLConnection) inventoryUrl.openConnection();\r
-        conn.setRequestMethod("GET");\r
-        String reqid = LoggingUtils.getRequestId();\r
-        logger.info("reqid set to " + reqid);\r
-        conn.setRequestProperty("X-ECOMP-RequestID", reqid);\r
-        boolean requestFailed = true;\r
-        int responseCode = conn.getResponseCode();\r
-        if (responseCode == 200) {\r
-            requestFailed = false;\r
-        }\r
-        StringBuilder response = new StringBuilder();\r
-        try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {\r
-            String inputLine = null;\r
-            while ((inputLine = in.readLine()) != null) {\r
-                response.append(inputLine);\r
-            }\r
-        }\r
-        String responseStr = response.toString();\r
-        if (responseStr != null) {\r
-            if (requestFailed) {\r
-                logger.error("requestFailed - responseStr=" + response);\r
-                throw new BadRequestException(responseStr);\r
-            }\r
-        }\r
-        String jsonResponseString = response.toString();\r
+        String responseStr = DcaeHttpConnectionManager.doDcaeHttpQuery(fullUrl, "GET", null, null);\r
         JSONParser parser = new JSONParser();\r
-        Object obj0 = parser.parse(jsonResponseString);\r
+        Object obj0 = parser.parse(responseStr);\r
         JSONObject jsonObj = (JSONObject) obj0;\r
         Long totalCount = (Long) jsonObj.get("totalCount");\r
         int numServices = totalCount.intValue();\r