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:com.amazon.s3.http.ConnectionManagerFactory.java
public static ThreadSafeClientConnManager createThreadSafeClientConnManager(ClientConfiguration config, HttpParams httpClientParams) {//from w ww.j av a 2 s. com ConnManagerParams.setMaxConnectionsPerRoute(httpClientParams, new ConnPerRouteBean(20)); SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); sslSocketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sslSocketFactory, 443)); return new ThreadSafeClientConnManager(httpClientParams, registry); }
From source file:org.andstatus.app.net.http.MisconfiguredSslHttpClientFactory.java
static HttpClient getHttpClient() { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); // This is done to get rid of the "javax.net.ssl.SSLException: hostname in certificate didn't match" error // See e.g. http://stackoverflow.com/questions/8839541/hostname-in-certificate-didnt-match socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); schemeRegistry.register(new Scheme("https", socketFactory, 443)); HttpParams params = getHttpParams(); ClientConnectionManager clientConnectionManager = new ThreadSafeClientConnManager(params, schemeRegistry); HttpClient client = new DefaultHttpClient(clientConnectionManager, params); client.getParams()// ww w . j ava 2s . c o m .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, MyPreferences.getConnectionTimeoutMs()) .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, MyPreferences.getConnectionTimeoutMs()); return client; }
From source file:com.blueserial.MyApplication.java
private static DefaultHttpClient createClient() { BasicHttpParams params = new BasicHttpParams(); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); schemeRegistry.register(new Scheme("https", sslSocketFactory, 443)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); DefaultHttpClient httpclient = new DefaultHttpClient(cm, params); httpclient.getCookieStore().getCookies(); return httpclient; }
From source file:com.emobc.android.utils.HttpUtils.java
/** * Take a client address is https by default if * @param https//w w w .j a v a 2 s. c o m * @return */ public static DefaultHttpClient getHttpClient(boolean https) { if (https) { HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; DefaultHttpClient client = new DefaultHttpClient(); SchemeRegistry registry = new SchemeRegistry(); SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); registry.register(new Scheme("https", socketFactory, 443)); SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry); DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams()); // Set verifier HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); return httpClient; } return new DefaultHttpClient(); }
From source file:org.switchyard.quickstarts.rules.multi.RulesMultiThreadBindingUtils.java
/** * Gets the client./*from w w w . j av a 2s . c o m*/ * * @return the client */ public static DefaultHttpClient getClient() { DefaultHttpClient ret = null; // sets up parameters HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); params.setBooleanParameter("http.protocol.expect-continue", false); // registers schemes for both http and https SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); sslSocketFactory.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); registry.register(new Scheme("https", sslSocketFactory, 443)); ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry); ret = new DefaultHttpClient(manager, params); return ret; }
From source file:org.jasig.schedassist.impl.caldav.SchemeRegistryProvider.java
/** * /*from www . j a v a 2 s.c o m*/ * @see SchemeRegistryFactory#createDefault() * @param schemeName * @param port * @param useSsl * @return */ public static SchemeRegistry createSchemeRegistry(String schemeName, int port, boolean useSsl) { SchemeRegistry registry = SchemeRegistryFactory.createDefault(); if (useSsl) { registry.register(new Scheme(schemeName, port, SSLSocketFactory.getSocketFactory())); } else { registry.register(new Scheme(schemeName, port, PlainSocketFactory.getSocketFactory())); } return registry; }
From source file:com.healthcit.analytics.dao.HttpClientWrapper.java
/** * @return The unique instance of this class. *///from w w w . j a va 2 s . c o m public static synchronized HttpClientWrapper getHttpClient() { if (httpClient == null) { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 20 * 1000); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); httpClient = new HttpClientWrapper(cm, params); } return httpClient; }
From source file:com.jonbanjo.ssl.JfSSLScheme.java
private static Scheme getDefaultScheme() { SSLSocketFactory sf = SSLSocketFactory.getSocketFactory(); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); return new Scheme("https", sf, 443); }
From source file:com.game.sns.volley.MyVolley.java
public static void init(Context context) { // mHttpClient = new DefaultHttpClient(); BasicHttpParams params = new BasicHttpParams(); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); schemeRegistry.register(new Scheme("https", sslSocketFactory, 443)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); mHttpClient = new DefaultHttpClient(cm, params); mRequestQueue = Volley.newRequestQueue(context, new HttpClientStack(mHttpClient)); // int memClass = ((ActivityManager) // context.getSystemService(Context.ACTIVITY_SERVICE)) // .getMemoryClass(); // // Use 1/8th of the available memory for this memory cache. // int cacheSize = 1024 * 1024 * memClass / 8; mImageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache()); }
From source file:org.wso2.carbon.dynamic.client.web.proxy.util.DCRProxyUtils.java
public static DefaultHttpClient getHttpsClient() { DefaultHttpClient httpClient = new DefaultHttpClient(); // Setup the HTTPS settings to accept any certificate. HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; SchemeRegistry registry = new SchemeRegistry(); SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); registry.register(new Scheme(Constants.RemoteServiceProperties.DYNAMIC_CLIENT_SERVICE_PROTOCOL, socketFactory, DCRProxyUtils.getServerHTTPSPort())); SingleClientConnManager mgr = new SingleClientConnManager(httpClient.getParams(), registry); httpClient = new DefaultHttpClient(mgr, httpClient.getParams()); // Set verifier HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); return httpClient; }