X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=rulemgt%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fholmes%2Frulemgt%2Fbolt%2Fenginebolt%2FEngineService.java;h=aa0bf3296ae61cca4a99fd48bdf3626196a7c7c6;hb=37b3bb9b015069ba5e9ad1845de30467decb61d4;hp=13507d67731e6c5287b9c1e7985acd3eaa7f4b9e;hpb=1985d463e60ab79a2fadc4065a9ea19861933692;p=holmes%2Frule-management.git diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java index 13507d6..aa0bf32 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java @@ -15,11 +15,13 @@ */ package org.onap.holmes.rulemgt.bolt.enginebolt; +import java.io.IOException; import java.util.HashMap; import javax.ws.rs.core.MediaType; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; import org.jvnet.hk2.annotations.Service; import org.onap.holmes.common.utils.GsonUtil; import org.onap.holmes.common.utils.HttpsUtils; @@ -38,7 +40,13 @@ public class EngineService { protected HttpResponse delete(String packageName, String ip) throws Exception { HashMap headers = createHeaders(); String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH + "/" + packageName; - return HttpsUtils.delete(url, headers); + CloseableHttpClient httpClient = null; + try { + httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT); + return HttpsUtils.delete(url, headers, httpClient); + } finally { + closeHttpClient(httpClient); + } } protected HttpResponse check(CorrelationCheckRule4Engine correlationCheckRule4Engine, String ip) @@ -46,14 +54,36 @@ public class EngineService { String content = GsonUtil.beanToJson(correlationCheckRule4Engine); HashMap headers = createHeaders(); String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH; - return HttpsUtils.post(url, headers, new HashMap<>(), new StringEntity(content)); + CloseableHttpClient httpClient = null; + try { + httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT); + return HttpsUtils.post(url, headers, new HashMap<>(), new StringEntity(content), httpClient); + } finally { + closeHttpClient(httpClient); + } } protected HttpResponse deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine, String ip) throws Exception { String content = GsonUtil.beanToJson(correlationDeployRule4Engine); HashMap headers = createHeaders(); String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH; - return HttpsUtils.put(url, headers, new HashMap<>(), new StringEntity(content)); + CloseableHttpClient httpClient = null; + try { + httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT); + return HttpsUtils.put(url, headers, new HashMap<>(), new StringEntity(content),httpClient); + } finally { + closeHttpClient(httpClient); + } + } + + private void closeHttpClient(CloseableHttpClient httpClient) { + if (httpClient != null) { + try { + httpClient.close(); + } catch (IOException e) { + log.warn("Failed to close http client!"); + } + } } private HashMap createHeaders() {