Search in sources :

Example 41 with ClientConnectionManager

use of org.apache.http.conn.ClientConnectionManager in project androidannotations by androidannotations.

the class SSLConnectionTest method methodInjectedHttpsClient.

@Test
public void methodInjectedHttpsClient() {
    assertNotNull(activity.methodInjectedHttpsClient);
    ClientConnectionManager ccm = activity.methodInjectedHttpsClient.getConnectionManager();
    assertNotNull(ccm);
}
Also used : ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) Test(org.junit.Test)

Example 42 with ClientConnectionManager

use of org.apache.http.conn.ClientConnectionManager in project androidannotations by androidannotations.

the class SSLConnectionTest method truststoreProvided.

@Test
public void truststoreProvided() {
    assertNotNull(activity.mHttpsClientTest1);
    ClientConnectionManager ccm = activity.mHttpsClientTest1.getConnectionManager();
    assertNotNull(ccm);
    Scheme httpsScheme = ccm.getSchemeRegistry().getScheme("https");
    assertNotNull(httpsScheme);
    assertEquals(443, httpsScheme.getDefaultPort());
    SocketFactory socketFactHttps = httpsScheme.getSocketFactory();
    if (!(socketFactHttps instanceof SSLSocketFactory)) {
        fail("wrong instance should be org.apache.http.conn.ssl.SSLSocketFactory, getting " + socketFactHttps);
    }
    assertEquals(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER, ((SSLSocketFactory) socketFactHttps).getHostnameVerifier());
}
Also used : Scheme(org.apache.http.conn.scheme.Scheme) SocketFactory(org.apache.http.conn.scheme.SocketFactory) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) Test(org.junit.Test)

Example 43 with ClientConnectionManager

use of org.apache.http.conn.ClientConnectionManager in project androidannotations by androidannotations.

the class SSLConnectionTest method multiInjectedHttpsClient.

@Test
public void multiInjectedHttpsClient() {
    assertNotNull(activity.multiInjectedHttpsClient);
    ClientConnectionManager ccm = activity.multiInjectedHttpsClient.getConnectionManager();
    assertNotNull(ccm);
}
Also used : ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) Test(org.junit.Test)

Example 44 with ClientConnectionManager

use of org.apache.http.conn.ClientConnectionManager in project platformlayer by platformlayer.

the class ApacheCommonsHttpConfiguration method buildHttpClient.

HttpClient buildHttpClient(SslConfiguration sslConfiguration) {
    HttpParams httpParams = null;
    if (sslConfiguration == null || sslConfiguration.isEmpty()) {
        sslConfiguration = null;
    }
    ClientConnectionManager connectionManager;
    if (sslConfiguration != null) {
        SchemeSocketFactory schemeSocketFactory;
        try {
            javax.net.ssl.SSLSocketFactory sslSocketFactory = sslConfiguration.getSslSocketFactory();
            X509HostnameVerifier apacheHostnameVerifier = null;
            if (sslConfiguration.getHostnameVerifier() != null) {
                apacheHostnameVerifier = new ApacheHostnameVerifierAdapter(sslConfiguration.getHostnameVerifier());
            } else {
                apacheHostnameVerifier = new ApacheHostnameVerifierAdapter(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
            }
            schemeSocketFactory = new SSLSocketFactory(sslSocketFactory, apacheHostnameVerifier);
        } catch (GeneralSecurityException e) {
            throw new IllegalArgumentException("Error building SSL client", e);
        }
        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme("https", 443, schemeSocketFactory));
        connectionManager = buildConnectionManager(schemeRegistry);
    } else {
        SchemeRegistry schemeRegistry = SchemeRegistryFactory.createDefault();
        connectionManager = buildConnectionManager(schemeRegistry);
    }
    HttpClient httpClient = buildDefaultHttpClient(connectionManager, httpParams);
    httpClient = wrapHttpClient(httpClient);
    return httpClient;
}
Also used : Scheme(org.apache.http.conn.scheme.Scheme) SchemeSocketFactory(org.apache.http.conn.scheme.SchemeSocketFactory) GeneralSecurityException(java.security.GeneralSecurityException) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) HttpParams(org.apache.http.params.HttpParams) X509HostnameVerifier(org.apache.http.conn.ssl.X509HostnameVerifier) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) DecompressingHttpClient(org.apache.http.impl.client.DecompressingHttpClient) HttpClient(org.apache.http.client.HttpClient) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory)

Example 45 with ClientConnectionManager

use of org.apache.http.conn.ClientConnectionManager in project 12306-hunter by xautlx.

the class HttpClientService method buildHttpClient.

/**
 * 构建HttpClient对象
 *
 * @return
 */
public static HttpClient buildHttpClient() {
    try {
        SSLContext sslcontext = SSLContext.getInstance("TLS");
        sslcontext.init(null, new TrustManager[] { tm }, null);
        SSLSocketFactory ssf = new SSLSocketFactory(sslcontext);
        ClientConnectionManager ccm = new DefaultHttpClient().getConnectionManager();
        SchemeRegistry sr = ccm.getSchemeRegistry();
        sr.register(new Scheme("https", 443, ssf));
        HttpParams params = new BasicHttpParams();
        params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 8000);
        params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 8000);
        HttpClient httpclient = new DefaultHttpClient(ccm, params);
        httpclient.getParams().setParameter(HTTP.USER_AGENT, "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; BOIE9;ZHCN)");
        return httpclient;
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) Scheme(org.apache.http.conn.scheme.Scheme) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) SSLContext(javax.net.ssl.SSLContext) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory) BasicHttpParams(org.apache.http.params.BasicHttpParams) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) CertificateException(java.security.cert.CertificateException)

Aggregations

ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)74 Scheme (org.apache.http.conn.scheme.Scheme)51 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)48 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)39 HttpParams (org.apache.http.params.HttpParams)37 SSLSocketFactory (org.apache.http.conn.ssl.SSLSocketFactory)35 BasicHttpParams (org.apache.http.params.BasicHttpParams)28 ThreadSafeClientConnManager (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)26 IOException (java.io.IOException)21 Test (org.junit.Test)15 CertificateException (java.security.cert.CertificateException)14 HttpClient (org.apache.http.client.HttpClient)14 KeyManagementException (java.security.KeyManagementException)13 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)13 SSLContext (javax.net.ssl.SSLContext)12 HttpResponse (org.apache.http.HttpResponse)11 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)11 KeyStoreException (java.security.KeyStoreException)10 PoolingClientConnectionManager (org.apache.http.impl.conn.PoolingClientConnectionManager)10 UnrecoverableKeyException (java.security.UnrecoverableKeyException)9