Search in sources :

Example 56 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)

Aggregations

ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)56 Scheme (org.apache.http.conn.scheme.Scheme)41 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)38 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)31 HttpParams (org.apache.http.params.HttpParams)29 BasicHttpParams (org.apache.http.params.BasicHttpParams)27 SSLSocketFactory (org.apache.http.conn.ssl.SSLSocketFactory)26 ThreadSafeClientConnManager (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)24 IOException (java.io.IOException)16 CertificateException (java.security.cert.CertificateException)13 HttpClient (org.apache.http.client.HttpClient)9 KeyManagementException (java.security.KeyManagementException)7 KeyStoreException (java.security.KeyStoreException)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)7 UnrecoverableKeyException (java.security.UnrecoverableKeyException)7 SSLContext (javax.net.ssl.SSLContext)7 PoolingClientConnectionManager (org.apache.http.impl.conn.PoolingClientConnectionManager)7 Test (org.junit.Test)7 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)5 UnknownHostException (java.net.UnknownHostException)5