diff options
author | Shiwei Tian <tian.shiwei@zte.com.cn> | 2018-04-09 09:23:54 +0800 |
---|---|---|
committer | Shiwei Tian <tian.shiwei@zte.com.cn> | 2018-04-09 09:24:51 +0800 |
commit | bfe7264117cdcf6aa570db8643676e73a7158ef0 (patch) | |
tree | ecb3f03b20f6caa7d63a73855c98094cd11d5caa | |
parent | d464ff641643cfbf776d0d2acba3d0ac02e20009 (diff) |
fix https bug
Issue-ID: HOLMES-104
Change-Id: I40d490e535923e6c66b9b4ed3ffb822e675797ab
Signed-off-by: Shiwei Tian <tian.shiwei@zte.com.cn>
-rw-r--r-- | dmaap-dsa/src/main/java/org/onap/holmes/dsa/dmaappolling/Subscriber.java | 15 | ||||
-rw-r--r-- | dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java | 3 | ||||
-rw-r--r-- | pom.xml | 2 |
3 files changed, 17 insertions, 3 deletions
diff --git a/dmaap-dsa/src/main/java/org/onap/holmes/dsa/dmaappolling/Subscriber.java b/dmaap-dsa/src/main/java/org/onap/holmes/dsa/dmaappolling/Subscriber.java index e4276d4..d696dee 100644 --- a/dmaap-dsa/src/main/java/org/onap/holmes/dsa/dmaappolling/Subscriber.java +++ b/dmaap-dsa/src/main/java/org/onap/holmes/dsa/dmaappolling/Subscriber.java @@ -24,7 +24,9 @@ import java.util.UUID; import lombok.Getter; import lombok.Setter; +import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; +import org.apache.http.impl.client.CloseableHttpClient; import org.onap.holmes.common.api.stat.VesAlarm; import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder; import org.onap.holmes.common.exception.CorrelationException; @@ -33,6 +35,7 @@ import org.onap.holmes.common.utils.HttpsUtils; @Getter @Setter +@Slf4j public class Subscriber { private DMaaPResponseUtil dMaaPResponseUtil = ServiceLocatorHolder.getLocator() @@ -80,12 +83,22 @@ public class Subscriber { private List<String> getDMaaPData() throws Exception { String response; + CloseableHttpClient closeableHttpClient = null; try { + closeableHttpClient = HttpsUtils.getHttpClient(timeout); HttpResponse httpResponse = HttpsUtils - .get(url + "/" + consumerGroup + "/" + consumer, new HashMap<>(), timeout); + .get(url + "/" + consumerGroup + "/" + consumer, new HashMap<>(), closeableHttpClient); response = HttpsUtils.extractResponseEntity(httpResponse); } catch (Exception e) { throw e; + } finally { + if (closeableHttpClient != null) { + try { + closeableHttpClient.close(); + } catch (IOException e) { + log.warn("Failed to close http client!"); + } + } } return GsonUtil.jsonToBean(response, List.class); } diff --git a/dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java b/dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java index e9e0849..04a42cd 100644 --- a/dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java +++ b/dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java @@ -17,6 +17,7 @@ package org.onap.holmes.dsa.dmaappolling; import java.util.HashMap; import org.apache.http.HttpResponse; +import org.apache.http.impl.client.CloseableHttpClient; import org.glassfish.hk2.api.ServiceLocator; import org.junit.Before; import org.junit.Test; @@ -124,7 +125,7 @@ public class SubscriberTest { PowerMockito.mockStatic(HttpsUtils.class); HttpResponse httpResponse = PowerMockito.mock(HttpResponse.class); PowerMockito.when(HttpsUtils.get(Matchers.eq("https://www.onap.org/group/consumer"), - Matchers.any(HashMap.class), Matchers.eq(15000))).thenReturn(httpResponse); + Matchers.any(HashMap.class), Matchers.any(CloseableHttpClient.class))).thenReturn(httpResponse); PowerMockito.when(HttpsUtils.extractResponseEntity(httpResponse)).thenReturn(responseJson); PowerMock.replayAll(); @@ -70,7 +70,7 @@ <dependency>
<groupId>org.onap.msb.java-sdk</groupId>
<artifactId>msb-java-sdk</artifactId>
- <version>1.1.0-SNAPSHOT</version>
+ <version>1.1.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
|