src/main/java/com/rockagen/commons/http/HttpConn.java
protected static String execute(HttpHost targetHost, HttpHost proxyHost,
                                    HttpRequest httpRequestMethod, String encoding,
                                    UsernamePasswordCredentials upc, InputStream keystore,
                                    char[] password) throws IOException {

        HttpClientBuilder hcb = HttpClients.custom();
        hcb.setDefaultRequestConfig(getRequestConfig());
        if (proxyHost != null) {
            hcb.setProxy(proxyHost);
        }
        if (keystore != null) {

            try {
                KeyStore trustStore = KeyStore.getInstance(KeyStore
                        .getDefaultType());
                trustStore.load(keystore, password);
                SSLContext sslcontext = SSLContexts.custom()
                        .loadTrustMaterial(trustStore, new TrustSelfSignedStrategy())
                        .build();
                SSLConnectionSocketFactory ssf = new SSLConnectionSocketFactory(
                        sslcontext);
                hcb.setSSLSocketFactory(ssf);
            } catch (KeyStoreException e) {
                log.error("{}", e.getMessage(), e);
            } catch (CertificateException e) {
                log.error("{}", e.getMessage(), e);
            } catch (NoSuchAlgorithmException e) {
                log.error("{}", e.getMessage(), e);
            } catch (KeyManagementException e) {
                log.error("{}", e.getMessage(), e);
            } finally {
                keystore.close();
            }

        }


        if (upc != null) {
            CredentialsProvider cp = new BasicCredentialsProvider();

            AuthScope as = new AuthScope(targetHost);

            cp.setCredentials(as, upc);
            hcb.setDefaultCredentialsProvider(cp);
        }

        CloseableHttpClient chc = hcb.build();
        try {
            CloseableHttpResponse response = chc.execute(targetHost, httpRequestMethod);
            return getResponse(response, encoding);
        } finally {
            chc.close();
        }

    }
protected static String execute(HttpHost targetHost, HttpHost proxyHost,
                                    HttpRequest httpRequestMethod, String encoding,
                                    UsernamePasswordCredentials upc, InputStream keystore,
                                    char[] password) throws IOException {

        HttpClientBuilder hcb = HttpClients.custom();
        hcb.setDefaultRequestConfig(getRequestConfig());
        if (proxyHost != null) {
            hcb.setProxy(proxyHost);
        }
        if (keystore != null) {

            try {
                KeyStore trustStore = KeyStore.getInstance(KeyStore
                        .getDefaultType());
                trustStore.load(keystore, password);
                SSLContext sslcontext = SSLContexts.custom()
                        .loadTrustMaterial(trustStore, new TrustSelfSignedStrategy())
                        .build();
                SSLConnectionSocketFactory ssf = new SSLConnectionSocketFactory(
                        sslcontext);
                hcb.setSSLSocketFactory(ssf);
            } catch (KeyStoreException e) {
                log.error("{}", e.getMessage(), e);
            } catch (CertificateException e) {
                log.error("{}", e.getMessage(), e);
            } catch (NoSuchAlgorithmException e) {
                log.error("{}", e.getMessage(), e);
            } catch (KeyManagementException e) {
                log.error("{}", e.getMessage(), e);
            } finally {
                keystore.close();
            }

        }


        if (upc != null) {
            CredentialsProvider cp = new BasicCredentialsProvider();

            AuthScope as = new AuthScope(targetHost);

            cp.setCredentials(as, upc);
            hcb.setDefaultCredentialsProvider(cp);
        }

        CloseableHttpClient chc = hcb.build();
        try {
            CloseableHttpResponse response = chc.execute(targetHost, httpRequestMethod);
            return getResponse(response, encoding);
        } finally {
            chc.close();
        }

    }
protected static String execute ( HttpHost targetHost , HttpHost proxyHost , HttpRequest httpRequestMethod , String encoding , UsernamePasswordCredentials upc , InputStream keystore , char [ ] password ) throws IOException { HttpClientBuilder hcb = HttpClients . custom ( ) ; hcb . setDefaultRequestConfig ( getRequestConfig ( ) ) ; if ( proxyHost != null ) { hcb . setProxy ( proxyHost ) ; } if ( keystore != null ) { try { KeyStore trustStore = KeyStore . getInstance ( KeyStore . getDefaultType ( ) ) ; trustStore . load ( keystore , password ) ; SSLContext sslcontext = SSLContexts . custom ( ) . loadTrustMaterial ( trustStore , new TrustSelfSignedStrategy ( ) ) . build ( ) ; SSLConnectionSocketFactory ssf = new SSLConnectionSocketFactory ( sslcontext ) ; hcb . setSSLSocketFactory ( ssf ) ; } catch ( KeyStoreException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } catch ( CertificateException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } catch ( NoSuchAlgorithmException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } catch ( KeyManagementException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } finally { keystore . close ( ) ; } } if ( upc != null ) { CredentialsProvider cp = new BasicCredentialsProvider ( ) ; AuthScope as = new AuthScope ( targetHost ) ; cp . setCredentials ( as , upc ) ; hcb . setDefaultCredentialsProvider ( cp ) ; } CloseableHttpClient chc = hcb . build ( ) ; try { CloseableHttpResponse response = chc . execute ( targetHost , httpRequestMethod ) ; return getResponse ( response , encoding ) ; } finally { chc . close ( ) ; } }
Handler main

@param targetHost target {@link HttpHost}
@param proxyHost proxy {@link HttpHost}
@param httpRequestMethod HttpGet or HttpPost...
@param encoding encoding
@param upc {@link UsernamePasswordCredentials}
@param keystore keystore stream
@param password keystore password
@return result String
@throws IOException  if an I/O error occurs
Handler main