Search in sources :

Example 51 with ClientConnectionManager

use of org.apache.http.conn.ClientConnectionManager in project oxAuth by GluuFederation.

the class HttpService method getHttpsClientDefaulTrustStore.

@Deprecated
public HttpClient getHttpsClientDefaulTrustStore() {
    try {
        PlainSocketFactory psf = PlainSocketFactory.getSocketFactory();
        SSLContext ctx = SSLContext.getInstance("TLS");
        SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", 80, psf));
        registry.register(new Scheme("https", 443, ssf));
        ClientConnectionManager ccm = new PoolingClientConnectionManager(registry);
        return new DefaultHttpClient(ccm);
    } catch (Exception ex) {
        log.error("Failed to create https client", ex);
        return new DefaultHttpClient();
    }
}
Also used : PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) Scheme(org.apache.http.conn.scheme.Scheme) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) SSLContext(javax.net.ssl.SSLContext) PlainSocketFactory(org.apache.http.conn.scheme.PlainSocketFactory) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory) PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) SslDefaultHttpClient(org.xdi.net.SslDefaultHttpClient) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 52 with ClientConnectionManager

use of org.apache.http.conn.ClientConnectionManager in project oxAuth by GluuFederation.

the class BaseTest method createHttpClientTrustAll.

public static HttpClient createHttpClientTrustAll() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
    SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy() {

        @Override
        public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
            return true;
        }
    }, new AllowAllHostnameVerifier());
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    registry.register(new Scheme("https", 443, sf));
    ClientConnectionManager ccm = new PoolingClientConnectionManager(registry);
    return new DefaultHttpClient(ccm);
}
Also used : TrustStrategy(org.apache.http.conn.ssl.TrustStrategy) PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) Scheme(org.apache.http.conn.scheme.Scheme) AllowAllHostnameVerifier(org.apache.http.conn.ssl.AllowAllHostnameVerifier) CertificateException(java.security.cert.CertificateException) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) X509Certificate(java.security.cert.X509Certificate) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory)

Example 53 with ClientConnectionManager

use of org.apache.http.conn.ClientConnectionManager in project java-chassis by ServiceComb.

the class HttpsClient method getHttpsClient.

public static HttpClient getHttpsClient(HttpsConfigInfoBean configBean) {
    try {
        SSLContext sslContext = createSSLContext(configBean);
        SSLSocketFactory sf = new SSLSocketFactory(sslContext);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
        HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT);
        HttpConnectionParams.setSoTimeout(params, SO_TIMEOUT);
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), PORT_80));
        registry.register(new Scheme("https", sf, PORT_443));
        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
        return new DefaultHttpClient(ccm, params);
    } catch (RuntimeException e) {
        LOGGER.error("Get https client runtime exception: {}", FortifyUtils.getErrorInfo(e));
        return new DefaultHttpClient();
    } catch (GeneralSecurityException | IOException e) {
        LOGGER.error("Get https client exception: {}", FortifyUtils.getErrorInfo(e));
        return new DefaultHttpClient();
    }
}
Also used : Scheme(org.apache.http.conn.scheme.Scheme) GeneralSecurityException(java.security.GeneralSecurityException) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) ThreadSafeClientConnManager(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory) BasicHttpParams(org.apache.http.params.BasicHttpParams)

Example 54 with ClientConnectionManager

use of org.apache.http.conn.ClientConnectionManager in project cdap by caskdata.

the class NettyRouterHttpsTest method getHTTPClient.

@Override
protected DefaultHttpClient getHTTPClient() throws Exception {
    SSLContext sslContext = SSLContext.getInstance("SSL");
    // set up a TrustManager that trusts everything
    sslContext.init(null, new TrustManager[] { new X509TrustManager() {

        @Override
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
            return null;
        }

        @Override
        public void checkClientTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws CertificateException {
        //
        }

        @Override
        public void checkServerTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws CertificateException {
        //
        }
    } }, new SecureRandom());
    SSLSocketFactory sf = new SSLSocketFactory(sslContext);
    Scheme httpsScheme = new Scheme("https", 10101, sf);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(httpsScheme);
    // apache HttpClient version >4.2 should use BasicClientConnectionManager
    ClientConnectionManager cm = new BasicClientConnectionManager(schemeRegistry);
    return new DefaultHttpClient(cm);
}
Also used : Scheme(org.apache.http.conn.scheme.Scheme) SecureRandom(java.security.SecureRandom) CertificateException(java.security.cert.CertificateException) SSLContext(javax.net.ssl.SSLContext) BasicClientConnectionManager(org.apache.http.impl.conn.BasicClientConnectionManager) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) X509Certificate(java.security.cert.X509Certificate) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) X509TrustManager(javax.net.ssl.X509TrustManager) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) BasicClientConnectionManager(org.apache.http.impl.conn.BasicClientConnectionManager) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory)

Example 55 with ClientConnectionManager

use of org.apache.http.conn.ClientConnectionManager in project cdap by caskdata.

the class ExternalMTLSAuthenticationServerTestBase method getHTTPClient.

private HttpClient getHTTPClient(KeyManager[] kms, TrustManager[] tms) throws Exception {
    SSLContext sslContext = SSLContext.getInstance("SSL");
    sslContext.init(kms, tms, new SecureRandom());
    // only for test purposes ignoring check of certificate hostname matching host on which server runs
    SSLSocketFactory sf = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    Scheme httpsScheme = new Scheme("https", getAuthServerPort(), sf);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(httpsScheme);
    // Apache HttpClient version >4.2 should use BasicClientConnectionManager
    ClientConnectionManager cm = new BasicClientConnectionManager(schemeRegistry);
    return new DefaultHttpClient(cm);
}
Also used : Scheme(org.apache.http.conn.scheme.Scheme) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) BasicClientConnectionManager(org.apache.http.impl.conn.BasicClientConnectionManager) SecureRandom(java.security.SecureRandom) SSLContext(javax.net.ssl.SSLContext) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory) BasicClientConnectionManager(org.apache.http.impl.conn.BasicClientConnectionManager) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Aggregations

ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)55 Scheme (org.apache.http.conn.scheme.Scheme)40 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)37 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)30 HttpParams (org.apache.http.params.HttpParams)28 BasicHttpParams (org.apache.http.params.BasicHttpParams)26 SSLSocketFactory (org.apache.http.conn.ssl.SSLSocketFactory)25 ThreadSafeClientConnManager (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)23 IOException (java.io.IOException)15 CertificateException (java.security.cert.CertificateException)13 HttpClient (org.apache.http.client.HttpClient)9 SSLContext (javax.net.ssl.SSLContext)7 PoolingClientConnectionManager (org.apache.http.impl.conn.PoolingClientConnectionManager)7 Test (org.junit.Test)7 KeyManagementException (java.security.KeyManagementException)6 KeyStoreException (java.security.KeyStoreException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 UnrecoverableKeyException (java.security.UnrecoverableKeyException)6 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)5 X509Certificate (java.security.cert.X509Certificate)5