fix https bug
[holmes/common.git] / holmes-actions / src / main / java / org / onap / holmes / common / dmaap / Publisher.java
index ad5109b..adddd65 100644 (file)
@@ -15,6 +15,9 @@
  */\r
 package org.onap.holmes.common.dmaap;\r
 \r
+import java.io.IOException;\r
+import lombok.extern.slf4j.Slf4j;\r
+import org.apache.http.impl.client.CloseableHttpClient;\r
 import org.onap.holmes.common.dmaap.entity.PolicyMsg;\r
 import org.onap.holmes.common.exception.CorrelationException;\r
 import com.alibaba.fastjson.JSON;\r
@@ -31,6 +34,7 @@ import org.onap.holmes.common.utils.HttpsUtils;
 @Getter\r
 @Setter\r
 @Service\r
+@Slf4j\r
 public class Publisher {\r
 \r
     private String topic;\r
@@ -50,10 +54,20 @@ public class Publisher {
         HashMap<String, String> headers = new HashMap<>();\r
         headers.put("Accept", MediaType.APPLICATION_JSON);\r
         headers.put("Content-Type", MediaType.APPLICATION_JSON);\r
+        CloseableHttpClient httpClient = null;\r
         try {\r
-            httpResponse = HttpsUtils.post(url, headers, new HashMap<>(), new StringEntity(content, "utf-8"));\r
+            httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);\r
+            httpResponse = HttpsUtils.post(url, headers, new HashMap<>(), new StringEntity(content, "utf-8"), httpClient);\r
         } catch (Exception e) {\r
             throw new CorrelationException("Failed to connect to DCAE.", e);\r
+        } finally {\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
         return checkStatus(httpResponse);\r
     }\r