X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=holmes-actions%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fholmes%2Fcommon%2Fdmaap%2FPublisher.java;h=adddd6595dedc44c01abe5c6b50e25517d7402af;hb=96a6ea5cab6575b7e04d6736cee6906298065a7b;hp=ad5109b775d8151b5d42b7d2d0ed89f96420b503;hpb=bf20ddf00200c5468da7a0090caf28beebb93e9c;p=holmes%2Fcommon.git diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java index ad5109b..adddd65 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java @@ -15,6 +15,9 @@ */ package org.onap.holmes.common.dmaap; +import java.io.IOException; +import lombok.extern.slf4j.Slf4j; +import org.apache.http.impl.client.CloseableHttpClient; import org.onap.holmes.common.dmaap.entity.PolicyMsg; import org.onap.holmes.common.exception.CorrelationException; import com.alibaba.fastjson.JSON; @@ -31,6 +34,7 @@ import org.onap.holmes.common.utils.HttpsUtils; @Getter @Setter @Service +@Slf4j public class Publisher { private String topic; @@ -50,10 +54,20 @@ public class Publisher { HashMap headers = new HashMap<>(); headers.put("Accept", MediaType.APPLICATION_JSON); headers.put("Content-Type", MediaType.APPLICATION_JSON); + CloseableHttpClient httpClient = null; try { - httpResponse = HttpsUtils.post(url, headers, new HashMap<>(), new StringEntity(content, "utf-8")); + httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT); + httpResponse = HttpsUtils.post(url, headers, new HashMap<>(), new StringEntity(content, "utf-8"), httpClient); } catch (Exception e) { throw new CorrelationException("Failed to connect to DCAE.", e); + } finally { + if (httpClient != null) { + try { + httpClient.close(); + } catch (IOException e) { + log.warn("Failed to close http client!"); + } + } } return checkStatus(httpResponse); }