|
|
@@ -61,39 +61,39 @@ import java.security.cert.X509Certificate;
|
|
|
public class HttpServiceImpl implements HttpService {
|
|
|
private final static Logger log = LoggerFactory.getLogger(HttpService.class);
|
|
|
|
|
|
- private static CloseableHttpClient closeableHttpClient;
|
|
|
- public static CloseableHttpClient createUnsafeHttpClient() {
|
|
|
- if (closeableHttpClient==null) {
|
|
|
- try {
|
|
|
- SSLContext sslContext = SSLContexts.custom()
|
|
|
- .loadTrustMaterial(new TrustStrategy() {
|
|
|
- @Override
|
|
|
- public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
|
|
- return true; // 忽略证书验证
|
|
|
- }
|
|
|
- })
|
|
|
- .build();
|
|
|
- SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
|
|
|
-
|
|
|
- RequestConfig requestConfig = RequestConfig.custom()
|
|
|
- .setConnectTimeout(6000) // 设置连接超时
|
|
|
- .setSocketTimeout(12000) // 设置读取超时
|
|
|
- .setConnectionRequestTimeout(20000) // 设置从连接池获取连接实例的超时
|
|
|
- .build();
|
|
|
-
|
|
|
- CloseableHttpClient httpClient = HttpClients.custom()
|
|
|
- .setSSLSocketFactory(sslConnectionFactory)
|
|
|
- .setConnectionManagerShared(true)
|
|
|
- .setDefaultRequestConfig(requestConfig)
|
|
|
- .build();
|
|
|
- closeableHttpClient=httpClient;
|
|
|
- } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
- return closeableHttpClient;
|
|
|
- }
|
|
|
+// private static CloseableHttpClient closeableHttpClient;
|
|
|
+// public static CloseableHttpClient createUnsafeHttpClient() {
|
|
|
+// if (closeableHttpClient==null) {
|
|
|
+// try {
|
|
|
+// SSLContext sslContext = SSLContexts.custom()
|
|
|
+// .loadTrustMaterial(new TrustStrategy() {
|
|
|
+// @Override
|
|
|
+// public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
|
|
+// return true; // 忽略证书验证
|
|
|
+// }
|
|
|
+// })
|
|
|
+// .build();
|
|
|
+// SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
|
|
|
+//
|
|
|
+// RequestConfig requestConfig = RequestConfig.custom()
|
|
|
+// .setConnectTimeout(6000) // 设置连接超时
|
|
|
+// .setSocketTimeout(12000) // 设置读取超时
|
|
|
+// .setConnectionRequestTimeout(20000) // 设置从连接池获取连接实例的超时
|
|
|
+// .build();
|
|
|
+//
|
|
|
+// CloseableHttpClient httpClient = HttpClients.custom()
|
|
|
+// .setSSLSocketFactory(sslConnectionFactory)
|
|
|
+// .setConnectionManagerShared(true)
|
|
|
+// .setDefaultRequestConfig(requestConfig)
|
|
|
+// .build();
|
|
|
+// closeableHttpClient=httpClient;
|
|
|
+// } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return closeableHttpClient;
|
|
|
+// }
|
|
|
|
|
|
@Override
|
|
|
public String sendPost(String uri, JSONObject requestBody, List<NameValuePair> params, String token) throws Exception {
|
|
|
@@ -109,7 +109,7 @@ public class HttpServiceImpl implements HttpService {
|
|
|
httpPost.setHeader("Content-Type", "application/json;chartset=UTF-8");
|
|
|
httpPost.setEntity(new StringEntity(JSON.toJSONString(requestBody), StandardCharsets.UTF_8));
|
|
|
httpPost.setConfig(RequestConfig.DEFAULT);
|
|
|
- CloseableHttpClient client = HttpServiceImpl.createUnsafeHttpClient();
|
|
|
+ CloseableHttpClient client = HttpClients.createDefault();
|
|
|
CloseableHttpResponse response = client.execute(httpPost);
|
|
|
HttpEntity entity = response.getEntity();
|
|
|
String result = EntityUtils.toString(entity);
|
|
|
@@ -167,7 +167,7 @@ public class HttpServiceImpl implements HttpService {
|
|
|
HttpGet httpGet = new HttpGet(completedUri);
|
|
|
httpGet.setConfig(RequestConfig.DEFAULT);
|
|
|
httpGet.setHeader("Authorization", token);
|
|
|
- CloseableHttpClient client = HttpServiceImpl.createUnsafeHttpClient();
|
|
|
+ CloseableHttpClient client = HttpClients.createDefault();
|
|
|
CloseableHttpResponse response = client.execute(httpGet);
|
|
|
HttpEntity entity = response.getEntity();
|
|
|
String result = EntityUtils.toString(entity);
|
|
|
@@ -203,7 +203,7 @@ public class HttpServiceImpl implements HttpService {
|
|
|
} else {
|
|
|
completedUri = uri;
|
|
|
}
|
|
|
- CloseableHttpClient httpClient = HttpServiceImpl.createUnsafeHttpClient();
|
|
|
+ CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
HttpPut httpPut = new HttpPut(completedUri);
|
|
|
if (token != null) {
|
|
|
httpPut.setHeader("Authorization", token);
|