fix https bug
[holmes/rule-management.git] / rulemgt / src / main / java / org / onap / holmes / rulemgt / bolt / enginebolt / EngineService.java
index 319347e..aa0bf32 100644 (file)
  */\r
 package org.onap.holmes.rulemgt.bolt.enginebolt;\r
 \r
+import java.io.IOException;\r
 import java.util.HashMap;\r
 import javax.ws.rs.core.MediaType;\r
 import lombok.extern.slf4j.Slf4j;\r
 import org.apache.http.HttpResponse;\r
 import org.apache.http.entity.StringEntity;\r
+import org.apache.http.impl.client.CloseableHttpClient;\r
 import org.jvnet.hk2.annotations.Service;\r
 import org.onap.holmes.common.utils.GsonUtil;\r
 import org.onap.holmes.common.utils.HttpsUtils;\r
@@ -32,25 +34,56 @@ import org.onap.holmes.common.config.MicroServiceConfig;
 @Service\r
 public class EngineService {\r
 \r
-    protected HttpResponse delete(String packageName) throws Exception {\r
+    private static final String PREFIX = "https://";\r
+    private static final String PORT = ":9102";\r
+\r
+    protected HttpResponse delete(String packageName, String ip) throws Exception {\r
         HashMap headers = createHeaders();\r
-        String url = MicroServiceConfig.getMsbServerAddrWithHttpPrefix() + RuleMgtConstant.ENGINE_PATH + "/" + packageName;\r
-        return HttpsUtils.delete(url, headers);\r
+        String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH + "/" + packageName;\r
+        CloseableHttpClient httpClient = null;\r
+        try {\r
+            httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);\r
+            return HttpsUtils.delete(url, headers, httpClient);\r
+        } finally {\r
+            closeHttpClient(httpClient);\r
+        }\r
     }\r
 \r
-    protected HttpResponse check(CorrelationCheckRule4Engine correlationCheckRule4Engine)\r
+    protected HttpResponse check(CorrelationCheckRule4Engine correlationCheckRule4Engine, String ip)\r
             throws Exception {\r
         String content = GsonUtil.beanToJson(correlationCheckRule4Engine);\r
         HashMap headers = createHeaders();\r
-        String url = MicroServiceConfig.getMsbServerAddrWithHttpPrefix() + RuleMgtConstant.ENGINE_PATH;\r
-        return HttpsUtils.post(url, headers, new HashMap<>(), new StringEntity(content));\r
+        String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH;\r
+        CloseableHttpClient httpClient = null;\r
+        try {\r
+            httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);\r
+            return HttpsUtils.post(url, headers, new HashMap<>(), new StringEntity(content), httpClient);\r
+        } finally {\r
+            closeHttpClient(httpClient);\r
+        }\r
     }\r
 \r
-    protected HttpResponse deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine) throws Exception {\r
+    protected HttpResponse deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine, String ip) throws Exception {\r
         String content = GsonUtil.beanToJson(correlationDeployRule4Engine);\r
         HashMap headers = createHeaders();\r
-        String url = MicroServiceConfig.getMsbServerAddrWithHttpPrefix() + RuleMgtConstant.ENGINE_PATH;\r
-        return HttpsUtils.put(url, headers, new HashMap<>(), new StringEntity(content));\r
+        String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH;\r
+        CloseableHttpClient httpClient = null;\r
+        try {\r
+            httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);\r
+            return HttpsUtils.put(url, headers, new HashMap<>(), new StringEntity(content),httpClient);\r
+        } finally {\r
+            closeHttpClient(httpClient);\r
+        }\r
+    }\r
+\r
+    private void closeHttpClient(CloseableHttpClient httpClient) {\r
+        if (httpClient != null) {\r
+            try {\r
+                httpClient.close();\r
+            } catch (IOException e) {\r
+                log.warn("Failed to close http client!");\r
+            }\r
+        }\r
     }\r
 \r
     private HashMap<String, String> createHeaders() {\r