public static CloseableHttpClient getPermissiveHttpClient(int retries) {
        SSLContextBuilder builder = new SSLContextBuilder();
        try {
            builder.loadTrustMaterial(null, new TrustStrategy() {
                @Override
                public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                    return true;
                }
            });
        } catch (NoSuchAlgorithmException | KeyStoreException e1) {
            LOG.error("Error creating SSL Context Builder with trusted certificates.", e1);
        }

        SSLConnectionSocketFactory sslSF = null;
        try {
            sslSF = new SSLConnectionSocketFactory(builder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        } catch (KeyManagementException | NoSuchAlgorithmException e1) {
            LOG.error("Error creating SSL Connection Factory.", e1);
        }

        CloseableHttpClient httpclient = HttpClients.custom()
                .setRetryHandler(new DefaultHttpRequestRetryHandler(retries, false))
                .setSSLSocketFactory(sslSF)
                .setHostnameVerifier(new AllowAllHostnameVerifier()).build();

        return httpclient;
    }
public static CloseableHttpClient getPermissiveHttpClient ( int retries ) { SSLContextBuilder builder = new SSLContextBuilder ( ) ; try { builder . loadTrustMaterial ( null , new TrustStrategy ( ) { @ Override public boolean isTrusted ( X509Certificate [ ] chain , String authType ) throws CertificateException { return true ; } } ) ; } catch ( NoSuchAlgorithmException | KeyStoreException e1 ) { LOG . error ( "Error creating SSL Context Builder with trusted certificates." , e1 ) ; } SSLConnectionSocketFactory sslSF = null ; try { sslSF = new SSLConnectionSocketFactory ( builder . build ( ) , SSLConnectionSocketFactory . ALLOW_ALL_HOSTNAME_VERIFIER ) ; } catch ( KeyManagementException | NoSuchAlgorithmException e1 ) { LOG . error ( "Error creating SSL Connection Factory." , e1 ) ; } CloseableHttpClient httpclient = HttpClients . custom ( ) . setRetryHandler ( new DefaultHttpRequestRetryHandler ( retries , false ) ) . setSSLSocketFactory ( sslSF ) . setHostnameVerifier ( new AllowAllHostnameVerifier ( ) ) . build ( ) ; return httpclient ; }
NOTE: Be sure to close the HTTP connection after every request!
@param retries - int number of retries to execute request in case of failure
@return Closeable "permissive" HttpClient instance, ignoring invalid SSL certificates.