Search in sources :

Example 76 with ClientConnectionManager

use of org.apache.http.conn.ClientConnectionManager 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 77 with ClientConnectionManager

use of org.apache.http.conn.ClientConnectionManager 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)

Aggregations

ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)77 Scheme (org.apache.http.conn.scheme.Scheme)54 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)51 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)42 SSLSocketFactory (org.apache.http.conn.ssl.SSLSocketFactory)38 HttpParams (org.apache.http.params.HttpParams)38 BasicHttpParams (org.apache.http.params.BasicHttpParams)31 ThreadSafeClientConnManager (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)29 IOException (java.io.IOException)24 CertificateException (java.security.cert.CertificateException)17 HttpClient (org.apache.http.client.HttpClient)15 Test (org.junit.Test)15 KeyManagementException (java.security.KeyManagementException)14 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)14 SSLContext (javax.net.ssl.SSLContext)14 HttpResponse (org.apache.http.HttpResponse)12 KeyStoreException (java.security.KeyStoreException)11 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)11 UnrecoverableKeyException (java.security.UnrecoverableKeyException)10 PoolingClientConnectionManager (org.apache.http.impl.conn.PoolingClientConnectionManager)10