List of usage examples for org.apache.http.conn.ssl SSLSocketFactory getSocketFactory
public static SSLSocketFactory getSocketFactory() throws SSLInitializationException
cacerts
file in the security properties directory). From source file:outfox.dict.contest.util.HttpToolKit.java
/** * @param maxConnectPerHost// w w w .java 2s . c o m * @param maxConnection * @param connectTimeOut * @param socketTimeOut * @param cookiePolicy * @param isAutoRetry * @param redirect */ public HttpToolKit(int maxConnectPerHost, int maxConnection, int connectTimeOut, int socketTimeOut, String cookiePolicy, boolean isAutoRetry, boolean redirect) { Scheme https = new Scheme("https", 443, SSLSocketFactory.getSocketFactory()); Scheme http = new Scheme("http", 80, PlainSocketFactory.getSocketFactory()); SchemeRegistry sr = new SchemeRegistry(); sr.register(https); sr.register(http); connectionManager = new PoolingClientConnectionManager(sr, socketTimeOut, TimeUnit.MILLISECONDS); connectionManager.setDefaultMaxPerRoute(maxConnectPerHost); connectionManager.setMaxTotal(maxConnection); HttpParams params = new BasicHttpParams(); params.setLongParameter(ClientPNames.CONN_MANAGER_TIMEOUT, connectTimeOut); params.setParameter(ClientPNames.COOKIE_POLICY, cookiePolicy); params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, redirect); params.setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, false); if (isAutoRetry) { client = new AutoRetryHttpClient(new DefaultHttpClient(connectionManager, params)); } else { client = new DefaultHttpClient(connectionManager, params); } }
From source file:net.networksaremadeofstring.rhybudd.ZenossAPIZaas.java
@Override protected void PrepareSSLHTTPClient() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException { client = new DefaultHttpClient(); SchemeRegistry registry = new SchemeRegistry(); SocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); registry.register(new Scheme("https", socketFactory, 443)); mgr = new ThreadSafeClientConnManager(client.getParams(), registry); httpclient = new DefaultHttpClient(mgr, client.getParams()); this.setTimeouts(); }
From source file:cn.clxy.upload.ApacheHCUploader.java
/** * The timeout should be adjusted by network condition. * @return/* www .j a va 2s.co m*/ */ private static HttpClient createClient() { SchemeRegistry schReg = new SchemeRegistry(); schReg.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schReg.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); PoolingClientConnectionManager ccm = new PoolingClientConnectionManager(schReg); ccm.setMaxTotal(Config.maxUpload); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 10 * 1000); HttpConnectionParams.setSoTimeout(params, Config.timeOut); return new DefaultHttpClient(ccm, params); }
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.rackspacecloud.client.service_registry.Client.java
public Client(String username, String apiKey, String region, String apiUrl) { AuthClient authClient = new AuthClient(new DefaultHttpClient() { protected HttpParams createHttpParams() { BasicHttpParams params = new BasicHttpParams(); org.apache.http.params.HttpConnectionParams.setSoTimeout(params, 10000); params.setParameter("http.socket.timeout", 10000); return params; }/* w w w . j a v a 2s . c o m*/ @Override protected ClientConnectionManager createClientConnectionManager() { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); return new ThreadSafeClientConnManager(createHttpParams(), schemeRegistry); } }, username, apiKey, region); this.services = new ServicesClient(authClient, apiUrl); this.configuration = new ConfigurationClient(authClient, apiUrl); this.events = new EventsClient(authClient, apiUrl); this.account = new AccountClient(authClient, apiUrl); }
From source file:cn.clxy.codes.upload.ApacheHCUploader.java
/** * The timeout should be adjusted by network condition. * @return/* www .ja va 2 s.c o m*/ */ private static HttpClient createClient() { SchemeRegistry schReg = new SchemeRegistry(); schReg.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schReg.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); PoolingClientConnectionManager ccm = new PoolingClientConnectionManager(schReg); ccm.setMaxTotal(Config.MAX_UPLOAD); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 10 * 1000); HttpConnectionParams.setSoTimeout(params, Config.PART_UPLOAD_TIMEOUT); return new DefaultHttpClient(ccm, params); }
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: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.todoroo.andlib.service.HttpRestClient.java
@SuppressWarnings("nls") public HttpRestClient() { DependencyInjectionService.getInstance().inject(this); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, timeout); HttpConnectionParams.setSoTimeout(params, timeout); params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30); params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30)); params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); cm = new ThreadSafeClientConnManager(params, schemeRegistry); }
From source file:com.piusvelte.sonet.core.SonetHttpClient.java
protected static DefaultHttpClient getThreadSafeClient(Context context) { if (sHttpClient == null) { Log.d(TAG, "create http client"); SocketFactory sf;/*from w ww . ja va 2 s. co m*/ try { Class<?> sslSessionCacheClass = Class.forName("android.net.SSLSessionCache"); Object sslSessionCache = sslSessionCacheClass.getConstructor(Context.class).newInstance(context); Method getHttpSocketFactory = Class.forName("android.net.SSLCertificateSocketFactory") .getMethod("getHttpSocketFactory", new Class<?>[] { int.class, sslSessionCacheClass }); sf = (SocketFactory) getHttpSocketFactory.invoke(null, CONNECTION_TIMEOUT, sslSessionCache); } catch (Exception e) { Log.e("HttpClientProvider", "Unable to use android.net.SSLCertificateSocketFactory to get a SSL session caching socket factory, falling back to a non-caching socket factory", e); sf = SSLSocketFactory.getSocketFactory(); } SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, SO_TIMEOUT); String versionName; try { versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { throw new RuntimeException(e); } StringBuilder userAgent = new StringBuilder(); userAgent.append(context.getPackageName()); userAgent.append("/"); userAgent.append(versionName); userAgent.append(" ("); userAgent.append("Linux; U; Android "); userAgent.append(Build.VERSION.RELEASE); userAgent.append("; "); userAgent.append(Locale.getDefault()); userAgent.append("; "); userAgent.append(Build.PRODUCT); userAgent.append(")"); if (HttpProtocolParams.getUserAgent(params) != null) { userAgent.append(" "); userAgent.append(HttpProtocolParams.getUserAgent(params)); } HttpProtocolParams.setUserAgent(params, userAgent.toString()); sHttpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(params, registry), params); } return sHttpClient; }