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:com.navnorth.learningregistry.LRClient.java
public static HttpClient getHttpClient(String scheme) { // TODO: this allows for self-signed certificates, which should just be an option, not used by default. if (scheme.equals("https")) { try {/*w w w.jav a 2 s . c o m*/ KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new SelfSignSSLSocketFactory(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); } catch (Exception e) { return new DefaultHttpClient(); } } else { return new DefaultHttpClient(); } }
From source file:com.entertailion.android.dial.HttpRequestHelper.java
public static DefaultHttpClient createHttpClient() { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 20000); HttpConnectionParams.setSoTimeout(params, 20000); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET); SchemeRegistry schReg = new SchemeRegistry(); schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg); return new DefaultHttpClient(conMgr, params); }
From source file:com.lugia.timetable.SSLHttpClient.java
public static SSLHttpClient getHttpClient() throws KeyManagementException, KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException { HttpClient client = new DefaultHttpClient(); X509TrustManager tm = createX509TrustManager(); SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new MySSLSocketFactory(ctx); ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = client.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", ssf, 443)); return new SSLHttpClient(new ThreadSafeClientConnManager(client.getParams(), sr), client.getParams()); }
From source file:edu.vt.alerts.android.library.util.HttpClientFactory.java
/** * Create an HttpClient that is configured with the installer certificate * @param context The application context * @param installerKeystore The installer certificate * @return An HttpClient configured to talk to the VTAPNS using the supplied * installer keystore/* w ww . java 2 s . c o m*/ * @throws Exception Anything really */ public HttpClient generateInstallerClient(Context context, InputStream installerKeystore) throws Exception { HttpParams httpParameters = new BasicHttpParams(); SSLSocketFactory sockfact = new SSLSocketFactory(getInstallerKeyStore(context, installerKeystore), "changeit", getTrustStore(context)); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sockfact, 443)); return new DefaultHttpClient(new ThreadSafeClientConnManager(httpParameters, registry), httpParameters); }
From source file:com.entertailion.android.launcher.utils.HttpRequestHelper.java
public static DefaultHttpClient createHttpClient() { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 60000); HttpConnectionParams.setSoTimeout(params, 60000); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET); HttpProtocolParams.setUserAgent(params, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.5 Safari/537.22"); SchemeRegistry schReg = new SchemeRegistry(); schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg); return new DefaultHttpClient(conMgr, params); }
From source file:com.dubsar_dictionary.SecureClient.SecureAndroidHttpClient.java
/** * Create a new HttpClient with reasonable defaults (which you can update). * (Lifted and modified from AndroidHttpClient.) * * @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. *//* w w w .ja v a 2 s. co m*/ public static HttpClient newInstance(String userAgent) { Log.d(TAG, "Creating new client instance"); 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); // Default to following redirects HttpClientParams.setRedirecting(params, true); // Set the specified user agent and register standard protocols. HttpProtocolParams.setUserAgent(params, userAgent); SchemeRegistry schemeRegistry = new SchemeRegistry(); SSLSocketFactory sf = SecureSocketFactory.getHttpSocketFactory(SOCKET_OPERATION_TIMEOUT); schemeRegistry.register(new Scheme("https", sf, 443)); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry); // We use a factory method to modify superclass initialization // parameters without the funny call-a-static-method dance. return new SecureAndroidHttpClient(manager, params); }
From source file:Main.java
public static DefaultHttpClient getThreadSafeClient() { if (httpclient != null) return (DefaultHttpClient) httpclient; HttpParams params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params, 100); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); // Create and initialize scheme registry SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); httpclient = new DefaultHttpClient(cm, params); return (DefaultHttpClient) httpclient; }
From source file:eu.trentorise.smartcampus.portfolio.utils.HttpClientFactory.java
private final HttpClient createHttpClient() { HttpParams httpParams = new BasicHttpParams(); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(httpParams, HTTP.DEFAULT_CONTENT_CHARSET); SchemeRegistry schemeRegistry = new SchemeRegistry(); Scheme httpScheme = new Scheme(HTTP_SCHEMA, PlainSocketFactory.getSocketFactory(), 80); schemeRegistry.register(httpScheme); Scheme httpsScheme = new Scheme(HTTPS_SCHEMA, SSLSocketFactory.getSocketFactory(), 443); schemeRegistry.register(httpsScheme); ClientConnectionManager tsConnManager = new ThreadSafeClientConnManager(httpParams, schemeRegistry); HttpClient client = new DefaultHttpClient(tsConnManager, httpParams); HttpConnectionParams.setSoTimeout(client.getParams(), TIMEOUT); HttpConnectionParams.setConnectionTimeout(client.getParams(), TIMEOUT); return client; }
From source file:com.jsquant.listener.JsquantContextListener.java
public void contextInitialized(ServletContextEvent sce) { contextDestroyed(sce);/*www . j a v a2 s .c o m*/ ServletContext context = sce.getServletContext(); String fileCachePath = getFileCachePath(context); context.setAttribute(ATTR_FILE_CACHE, new FileCache(fileCachePath)); HttpParams params = new BasicHttpParams(); //params.setParameter("http.useragent", "Mozilla/5.0"); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "UTF-8"); final SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); final ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry); final HttpClient httpClient = new DefaultHttpClient(manager, params); //HttpHost proxy = new HttpHost("someproxy.com", 80); //httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); context.setAttribute(ATTR_HTTP_CLIENT, httpClient); }
From source file:org.ttrssreader.net.deprecated.HttpClientFactory.java
DefaultHttpClient getHttpClient(HttpParams httpParams) {
return new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, registry), httpParams);
}