fix https bug 19/41619/2
authorShiwei Tian <tian.shiwei@zte.com.cn>
Mon, 9 Apr 2018 01:23:54 +0000 (09:23 +0800)
committerShiwei Tian <tian.shiwei@zte.com.cn>
Mon, 9 Apr 2018 01:24:51 +0000 (09:24 +0800)
Issue-ID: HOLMES-104

Change-Id: I40d490e535923e6c66b9b4ed3ffb822e675797ab
Signed-off-by: Shiwei Tian <tian.shiwei@zte.com.cn>
dmaap-dsa/src/main/java/org/onap/holmes/dsa/dmaappolling/Subscriber.java
dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/SubscriberTest.java
pom.xml

index e4276d4..d696dee 100644 (file)
@@ -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);
     }
index e9e0849..04a42cd 100644 (file)
@@ -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();
diff --git a/pom.xml b/pom.xml
index 5e01f37..65e4e3b 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -70,7 +70,7 @@
             <dependency>\r
                 <groupId>org.onap.msb.java-sdk</groupId>\r
                 <artifactId>msb-java-sdk</artifactId>\r
-                <version>1.1.0-SNAPSHOT</version>\r
+                <version>1.1.1-SNAPSHOT</version>\r
             </dependency>\r
             <dependency>\r
                 <groupId>org.easymock</groupId>\r