change to java 8 lambda
[holmes/rule-management.git] / rulemgt / src / main / java / org / onap / holmes / rulemgt / msb / EngineIpList.java
index cfccd18..2e91993 100644 (file)
 package org.onap.holmes.rulemgt.msb;
 
 
+import java.io.IOException;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
 import org.jvnet.hk2.annotations.Service;
 import org.onap.holmes.common.api.entity.ServiceEntity;
 import org.onap.holmes.common.api.entity.ServiceNode4Query;
@@ -30,6 +34,7 @@ import java.util.HashMap;
 import java.util.List;
 
 @Service
+@Slf4j
 public class EngineIpList {
 
     private String[] msbAddrInfo;
@@ -46,21 +51,24 @@ public class EngineIpList {
     }
 
     public List<String> getServiceCount()throws Exception{
-        String response;
-        try {
-            HttpResponse httpResponse = HttpsUtils
-                    .get(url, new HashMap<>());
-            response = HttpsUtils.extractResponseEntity(httpResponse);
-        } catch (Exception e) {
-            throw e;
-        }
-        ServiceEntity service = GsonUtil.jsonToBean(response, ServiceEntity.class);
-        List<ServiceNode4Query> nodesList = service.getNodes();
-        List<String> ipList = new ArrayList<>();
-        for(ServiceNode4Query node : nodesList){
-            ipList.add(node.getIp());
-        }
-        return ipList;
+               String response;
+               HttpGet httpGet = new HttpGet(url);
+               try (CloseableHttpClient httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT)) {
+                       HttpResponse httpResponse = HttpsUtils.get(httpGet, new HashMap<>(), httpClient);
+                       response = HttpsUtils.extractResponseEntity(httpResponse);
+               } catch (Exception e) {
+                       throw e;
+               } finally {
+                       httpGet.releaseConnection();
+
+               }
+               ServiceEntity service = GsonUtil.jsonToBean(response, ServiceEntity.class);
+               List<ServiceNode4Query> nodesList = service.getNodes();
+               List<String> ipList = new ArrayList<>();
+               for (ServiceNode4Query node : nodesList) {
+                       ipList.add(node.getIp());
+               }
+               return ipList;
 
     }