|
|
@@ -61,25 +61,29 @@ 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() {
|
|
|
- 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);
|
|
|
- CloseableHttpClient httpClient = HttpClients.custom()
|
|
|
- .setSSLSocketFactory(sslConnectionFactory)
|
|
|
- .build();
|
|
|
- return httpClient;
|
|
|
- } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return null;
|
|
|
+ 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);
|
|
|
+ CloseableHttpClient httpClient = HttpClients.custom()
|
|
|
+ .setSSLSocketFactory(sslConnectionFactory)
|
|
|
+ .build();
|
|
|
+ closeableHttpClient=httpClient;
|
|
|
+ } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
+ return closeableHttpClient;
|
|
|
}
|
|
|
|
|
|
@Override
|