summaryrefslogtreecommitdiffstats
path: root/holmes-actions/src/main
diff options
context:
space:
mode:
authorShiwei Tian <tian.shiwei@zte.com.cn>2017-10-20 12:31:37 +0800
committerShiwei Tian <tian.shiwei@zte.com.cn>2017-10-20 12:31:43 +0800
commitc3a783d2ed1e9e19525b7a88a0ef29aab419a436 (patch)
tree3dfda41499bcc050e6acb4d2599021c9376b5159 /holmes-actions/src/main
parent17a3500b535e9dd09a272c7428bdd9c9c945f1bb (diff)
modify bug
Issue-ID: HOLMES-71 Change-Id: Ib3a2f5b6614166aabccdbc78566d35d644661ee9 Signed-off-by: Shiwei Tian <tian.shiwei@zte.com.cn>
Diffstat (limited to 'holmes-actions/src/main')
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/utils/HttpsUtils.java30
1 files changed, 19 insertions, 11 deletions
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/HttpsUtils.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/HttpsUtils.java
index 091b25c..72e27db 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/utils/HttpsUtils.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/HttpsUtils.java
@@ -18,17 +18,15 @@ import java.io.IOException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.Consts;
-import org.apache.http.HeaderIterator;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
-import org.apache.http.ParseException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
@@ -46,16 +44,19 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.util.EntityUtils;
+import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.exception.CorrelationException;
@Slf4j
+@Service
public class HttpsUtils {
private static final String HTTP = "http";
private static final String HTTPS = "https";
private static SSLConnectionSocketFactory sslConnectionSocketFactory = null;
private static PoolingHttpClientConnectionManager connectionManager = null;
private static SSLContextBuilder sslContextBuilder = null;
- static {
+
+ static{
try {
sslContextBuilder = new SSLContextBuilder();
sslContextBuilder.loadTrustMaterial(null, new TrustStrategy() {
@@ -93,14 +94,25 @@ public class HttpsUtils {
public static String get(String url, Map<String, String> header) throws Exception {
HttpResponse httpResponse = null;
+ CloseableHttpClient httpClient = null;
+ HttpGet httpGet = null;
+ String response = "";
try {
- CloseableHttpClient httpClient = getHttpClient();
- HttpGet httpGet = getHttpGet(url, header);
+ httpClient = getHttpClient();
+ httpGet = getHttpGet(url, header);
httpResponse = getHttpResponse(httpClient, httpGet);
+ response = getResponseEntity(httpResponse);
} catch (Exception e) {
throw new CorrelationException("Failed to use get method query data from server");
+ } finally {
+ if (httpGet != null) {
+ httpGet.releaseConnection();
+ }
+ if (httpResponse != null) {
+ httpClient.close();
+ }
}
- return getResponseEntity(httpResponse);
+ return response;
}
private static HttpPost getHttpPost(String url, Map<String, String> header,
@@ -155,10 +167,6 @@ public class HttpsUtils {
httpResponse = httpClient.execute(httpRequest);
} catch (Exception e) {
throw new CorrelationException("Failed to get data from server");
- } finally {
- if (httpClient != null) {
- httpClient.close();
- }
}
return httpResponse;
}