Search in sources :

Example 76 with Scheme

use of org.apache.http.conn.scheme.Scheme in project androidquery by androidquery.

the class AbstractAjaxCallback method getClient.

private static DefaultHttpClient getClient() {
    if (client == null || !REUSE_CLIENT) {
        AQUtility.debug("creating http client");
        HttpParams httpParams = new BasicHttpParams();
        //httpParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
        HttpConnectionParams.setConnectionTimeout(httpParams, NET_TIMEOUT);
        HttpConnectionParams.setSoTimeout(httpParams, NET_TIMEOUT);
        //ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(NETWORK_POOL));
        ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(25));
        //Added this line to avoid issue at: http://stackoverflow.com/questions/5358014/android-httpclient-oom-on-4g-lte-htc-thunderbolt
        HttpConnectionParams.setSocketBufferSize(httpParams, 8192);
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", ssf == null ? SSLSocketFactory.getSocketFactory() : ssf, 443));
        ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, registry);
        client = new DefaultHttpClient(cm, httpParams);
    }
    return client;
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) Scheme(org.apache.http.conn.scheme.Scheme) ThreadSafeClientConnManager(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) BasicHttpParams(org.apache.http.params.BasicHttpParams) ConnPerRouteBean(org.apache.http.conn.params.ConnPerRouteBean) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 77 with Scheme

use of org.apache.http.conn.scheme.Scheme in project androidannotations by androidannotations.

the class SSLConnectionTest method strictHostnameVerifier.

@Test
public void strictHostnameVerifier() {
    assertNotNull(activity.mHttpsClientTest2);
    ClientConnectionManager ccm = activity.mHttpsClientTest2.getConnectionManager();
    Scheme httpsScheme = ccm.getSchemeRegistry().getScheme("https");
    SSLSocketFactory socketFactHttps = (SSLSocketFactory) httpsScheme.getSocketFactory();
    assertEquals(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER, socketFactHttps.getHostnameVerifier());
}
Also used : Scheme(org.apache.http.conn.scheme.Scheme) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) Test(org.junit.Test)

Example 78 with Scheme

use of org.apache.http.conn.scheme.Scheme in project RoboZombie by sahan.

the class ConfigurationService method getDefault.

/**
	 * <p>The <i>out-of-the-box</i> configuration for an instance of {@link HttpClient} which will be used for 
	 * executing all endpoint requests. Below is a detailed description of all configured properties.</p> 
	 * <br>
	 * <ul>
	 * <li>
	 * <p><b>HttpClient</b></p>
	 * <br>
	 * <p>It registers two {@link Scheme}s:</p>
	 * <br>
	 * <ol>
	 * 	<li><b>HTTP</b> on port <b>80</b> using sockets from {@link PlainSocketFactory#getSocketFactory}</li>
	 * 	<li><b>HTTPS</b> on port <b>443</b> using sockets from {@link SSLSocketFactory#getSocketFactory}</li>
	 * </ol>
	 * 
	 * <p>It uses a {@link ThreadSafeClientConnManager} with the following parameters:</p>
	 * <br>
	 * <ol>
	 * 	<li><b>Redirecting:</b> enabled</li>
	 * 	<li><b>Connection Timeout:</b> 30 seconds</li>
	 * 	<li><b>Socket Timeout:</b> 30 seconds</li>
	 * 	<li><b>Socket Buffer Size:</b> 12000 bytes</li>
	 * 	<li><b>User-Agent:</b> via <code>System.getProperty("http.agent")</code></li>
	 * </ol>
	 * </li>
	 * </ul>
	 * @return the instance of {@link HttpClient} which will be used for request execution
	 * <br><br>
	 * @since 1.3.0
	 */
@Override
public Configuration getDefault() {
    return new Configuration() {

        @Override
        public HttpClient httpClient() {
            try {
                HttpParams params = new BasicHttpParams();
                HttpClientParams.setRedirecting(params, true);
                HttpConnectionParams.setConnectionTimeout(params, 30 * 1000);
                HttpConnectionParams.setSoTimeout(params, 30 * 1000);
                HttpConnectionParams.setSocketBufferSize(params, 12000);
                HttpProtocolParams.setUserAgent(params, System.getProperty("http.agent"));
                SchemeRegistry schemeRegistry = new SchemeRegistry();
                schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
                schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
                ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);
                return new DefaultHttpClient(manager, params);
            } catch (Exception e) {
                throw new ConfigurationFailedException(e);
            }
        }
    };
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) Scheme(org.apache.http.conn.scheme.Scheme) ThreadSafeClientConnManager(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) Configuration(com.lonepulse.robozombie.proxy.Zombie.Configuration) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) BasicHttpParams(org.apache.http.params.BasicHttpParams) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 79 with Scheme

use of org.apache.http.conn.scheme.Scheme in project RoboZombie by sahan.

the class ZombieConfig method httpClient.

@Override
public HttpClient httpClient() {
    HttpParams params = new BasicHttpParams();
    //to simulate a socket timeout
    HttpConnectionParams.setSoTimeout(params, 2 * 1000);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);
    return new DefaultHttpClient(manager, params);
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) Scheme(org.apache.http.conn.scheme.Scheme) ThreadSafeClientConnManager(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) BasicHttpParams(org.apache.http.params.BasicHttpParams) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 80 with Scheme

use of org.apache.http.conn.scheme.Scheme in project XobotOS by xamarin.

the class AndroidHttpClient method newInstance.

/**
     * Create a new HttpClient with reasonable defaults (which you can update).
     *
     * @param userAgent to report in your HTTP requests
     * @param context to use for caching SSL sessions (may be null for no caching)
     * @return AndroidHttpClient for you to use for all your requests.
     */
public static AndroidHttpClient newInstance(String userAgent, Context context) {
    HttpParams params = new BasicHttpParams();
    // Turn off stale checking.  Our connections break all the time anyway,
    // and it's not worth it to pay the penalty of checking every time.
    HttpConnectionParams.setStaleCheckingEnabled(params, false);
    HttpConnectionParams.setConnectionTimeout(params, SOCKET_OPERATION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, SOCKET_OPERATION_TIMEOUT);
    HttpConnectionParams.setSocketBufferSize(params, 8192);
    // Don't handle redirects -- return them to the caller.  Our code
    // often wants to re-POST after a redirect, which we must do ourselves.
    HttpClientParams.setRedirecting(params, false);
    // Use a session cache for SSL sockets
    SSLSessionCache sessionCache = context == null ? null : new SSLSessionCache(context);
    // Set the specified user agent and register standard protocols.
    HttpProtocolParams.setUserAgent(params, userAgent);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLCertificateSocketFactory.getHttpSocketFactory(SOCKET_OPERATION_TIMEOUT, sessionCache), 443));
    ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);
    // parameters without the funny call-a-static-method dance.
    return new AndroidHttpClient(manager, params);
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) Scheme(org.apache.http.conn.scheme.Scheme) ThreadSafeClientConnManager(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) SSLSessionCache(android.net.SSLSessionCache) BasicHttpParams(org.apache.http.params.BasicHttpParams) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager)

Aggregations

Scheme (org.apache.http.conn.scheme.Scheme)104 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)64 SSLSocketFactory (org.apache.http.conn.ssl.SSLSocketFactory)54 ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)41 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)40 BasicHttpParams (org.apache.http.params.BasicHttpParams)33 HttpParams (org.apache.http.params.HttpParams)31 ThreadSafeClientConnManager (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)30 HttpClient (org.apache.http.client.HttpClient)19 AllowAllHostnameVerifier (org.apache.http.conn.ssl.AllowAllHostnameVerifier)17 SSLContext (javax.net.ssl.SSLContext)16 HttpResponse (org.apache.http.HttpResponse)15 IOException (java.io.IOException)13 CertificateException (java.security.cert.CertificateException)13 HttpHost (org.apache.http.HttpHost)13 MockResponse (com.google.mockwebserver.MockResponse)12 RecordedRequest (com.google.mockwebserver.RecordedRequest)12 TestSSLContext (libcore.javax.net.ssl.TestSSLContext)12 HttpGet (org.apache.http.client.methods.HttpGet)12 InetAddress (java.net.InetAddress)9