List of usage examples for org.apache.http.impl.conn.tsccm ThreadSafeClientConnManager ThreadSafeClientConnManager
@Deprecated public ThreadSafeClientConnManager(final HttpParams params, final SchemeRegistry schreg)
From source file:net.sf.dvstar.transmission.protocol.TestConnection.java
public static void testConnection() throws Exception { // make sure to use a proxy that supports CONNECT HttpHost target = new HttpHost("195.74.67.237", 80, "http"); HttpHost proxy = new HttpHost("192.168.4.7", 3128, "http"); // general setup SchemeRegistry supportedSchemes = new SchemeRegistry(); // Register the "http" and "https" protocol schemes, they are // required by the default operator to look up socket factories. supportedSchemes.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); supportedSchemes.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); // prepare parameters HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "UTF-8"); HttpProtocolParams.setUseExpectContinue(params, true); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, supportedSchemes); DefaultHttpClient httpclient = new DefaultHttpClient(ccm, params); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); HttpGet req = new HttpGet("/"); System.out.println("executing request to " + target + " via " + proxy); HttpResponse rsp = httpclient.execute(target, req); HttpEntity entity = rsp.getEntity(); System.out.println("----------------------------------------"); System.out.println(rsp.getStatusLine()); Header[] headers = rsp.getAllHeaders(); for (int i = 0; i < headers.length; i++) { System.out.println(headers[i]); }/*from w w w .j a v a 2 s .c o m*/ System.out.println("----------------------------------------"); if (entity != null) { System.out.println(EntityUtils.toString(entity)); } // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); }
From source file:com.leanengine.Configuration.java
/** * Create client connection manager./*from w w w.j a va 2 s . co m*/ * Override in a sub class if needed. * * Create an HttpClient with the ThreadSafeClientConnManager. * This connection manager must be used if more than one thread will * be using the HttpClient. * * @param params the http params * @param schemeRegistry the scheme registry * @return new client connection manager */ protected ClientConnectionManager createClientConnectionManager(HttpParams params, SchemeRegistry schemeRegistry) { return new ThreadSafeClientConnManager(params, schemeRegistry); }
From source file:com.pursuer.reader.easyrss.Utils.java
public static DefaultHttpClient createHttpClient() { final HttpParams config = new BasicHttpParams(); HttpProtocolParams.setVersion(config, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(config, HTTP.UTF_8); HttpProtocolParams.setUserAgent(config, Utils.class.getName()); final SchemeRegistry reg = new SchemeRegistry(); reg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); reg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); final ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(config, reg); final DefaultHttpClient client = new DefaultHttpClient(manager, config); client.getParams().setParameter("http.socket.timeout", 30 * 1000); return client; }
From source file:com.splunk.shuttl.archiver.http.InsecureHttpClientFactory.java
/** * @return HttpClient that accepts all SSL certificates. *//*from www .ja v a 2 s. c om*/ @SuppressWarnings("deprecation") public static HttpClient getInsecureHttpClient() { KeyStore trustStore = getTrustStore(); SSLSocketFactory sf = createSSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); }
From source file:org.thoughtcrime.ssl.pinning.util.PinningHelper.java
/** * Constructs an HttpClient that will validate SSL connections with a PinningTrustManager. * * @param pins An array of encoded pins to match a seen certificate * chain against. A pin is a hex-encoded hash of a X.509 certificate's * SubjectPublicKeyInfo. A pin can be generated using the provided pin.py * script: python ./tools/pin.py certificate_file.pem *//*from w w w . j a v a 2s .c o m*/ public static HttpClient getPinnedHttpClient(Context context, String[] pins) { try { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", new PinningSSLSocketFactory(context, pins, 0), 443)); HttpParams httpParams = new BasicHttpParams(); ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(httpParams, schemeRegistry); return new DefaultHttpClient(connectionManager, httpParams); } catch (UnrecoverableKeyException e) { throw new AssertionError(e); } catch (KeyManagementException e) { throw new AssertionError(e); } catch (NoSuchAlgorithmException e) { throw new AssertionError(e); } catch (KeyStoreException e) { throw new AssertionError(e); } }
From source file:org.cvasilak.jboss.mobile.admin.net.ssl.CustomHTTPClient.java
public static synchronized AbstractHttpClient getHttpClient() { try {/*w w w . ja v a 2 s .c o m*/ if (client == null) { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new EasySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); client = new DefaultHttpClient(ccm, params); } } catch (Exception e) { Log.d(TAG, "unable to create http client", e); } return client; }
From source file:it.restrung.rest.misc.HttpClientFactory.java
/** * Private helper to initialize an http client * * @return the initialize http client/*from www . ja v a2 s . co m*/ */ private static synchronized DefaultHttpClient initializeClient() { //prepare for the https connection //call this in the constructor of the class that does the connection if //it's used multiple times SchemeRegistry schemeRegistry = new SchemeRegistry(); // http scheme schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); // https scheme schemeRegistry.register(new Scheme("https", new FakeSocketFactory(), 443)); HttpParams params; params = new BasicHttpParams(); params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 1); params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(1)); params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); HttpClientParams.setRedirecting(params, true); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf8"); // ignore that the ssl cert is self signed ThreadSafeClientConnManager clientConnectionManager = new ThreadSafeClientConnManager(params, schemeRegistry); instance = new DefaultHttpClient(clientConnectionManager, params); instance.setRedirectHandler(new DefaultRedirectHandler()); //If the link has a redirect return instance; }
From source file:org.transdroid.util.HttpHelper.java
public static HttpClient buildDefaultSearchHttpClient(boolean ignoreSslIssues) { SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", new PlainSocketFactory(), 80)); registry.register(new Scheme("https", ignoreSslIssues ? new IgnoreTlsSniSocketFactory() : new TlsSniSocketFactory(), 443)); HttpParams httpparams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpparams, 8000); HttpConnectionParams.setSoTimeout(httpparams, 8000); DefaultHttpClient httpclient = new DefaultHttpClient(new ThreadSafeClientConnManager(httpparams, registry), httpparams);//from www . j a v a2 s . c o m httpclient.addRequestInterceptor(HttpHelper.gzipRequestInterceptor); httpclient.addResponseInterceptor(HttpHelper.gzipResponseInterceptor); return httpclient; }
From source file:org.codegist.crest.io.http.HttpClientFactory.java
public static HttpClient create(CRestConfig crestConfig, Class<?> source) { HttpClient httpClient = crestConfig.get(source.getName() + HTTP_CLIENT); if (httpClient != null) { return httpClient; }//from www .jav a 2s .co m int concurrencyLevel = crestConfig.getConcurrencyLevel(); if (concurrencyLevel > 1) { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(concurrencyLevel)); ConnManagerParams.setMaxTotalConnections(params, concurrencyLevel); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), HTTP_PORT)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), HTTPS_PORT)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); httpClient = new DefaultHttpClient(cm, params); } else { httpClient = new DefaultHttpClient(); } ((DefaultHttpClient) httpClient).setRoutePlanner(new ProxySelectorRoutePlanner( httpClient.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault())); return httpClient; }
From source file:org.pluroid.pluroium.HttpClientFactory.java
public static DefaultHttpClient createHttpClient(ClientConnectionManager connMgr) { DefaultHttpClient httpClient;/*from w ww . j av a 2s. c o m*/ HttpParams params = new BasicHttpParams(); params.setParameter("http.socket.timeout", new Integer(READ_TIMEOUT)); params.setParameter("http.connection.timeout", new Integer(CONNECT_TIMEOUT)); connMgr = new ThreadSafeClientConnManager(params, supportedSchemes); httpClient = new DefaultHttpClient(connMgr, params); httpClient.removeRequestInterceptorByClass(RequestExpectContinue.class); return httpClient; }