use of org.apache.http.conn.scheme.Scheme in project SmartAndroidSource by jaychou2012.
the class MySSLSocketFactory method getNewHttpClient.
/**
* Gets a DefaultHttpClient which trusts a set of certificates specified by the KeyStore
*
* @param keyStore custom provided KeyStore instance
* @return DefaultHttpClient
*/
public static DefaultHttpClient getNewHttpClient(KeyStore keyStore) {
try {
SSLSocketFactory sf = new MySSLSocketFactory(keyStore);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
return new DefaultHttpClient(ccm, params);
} catch (Exception e) {
return new DefaultHttpClient();
}
}
use of org.apache.http.conn.scheme.Scheme in project k-9 by k9mail.
the class WebDavStore method getHttpClient.
public WebDavHttpClient getHttpClient() throws MessagingException {
if (httpClient == null) {
httpClient = httpClientFactory.create();
// Disable automatic redirects on the http client.
httpClient.getParams().setBooleanParameter("http.protocol.handle-redirects", false);
// Setup a cookie store for forms-based authentication.
httpContext = new BasicHttpContext();
authCookies = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, authCookies);
SchemeRegistry reg = httpClient.getConnectionManager().getSchemeRegistry();
try {
Scheme s = new Scheme("https", new WebDavSocketFactory(hostname, 443), 443);
reg.register(s);
} catch (NoSuchAlgorithmException nsa) {
Log.e(LOG_TAG, "NoSuchAlgorithmException in getHttpClient: " + nsa);
throw new MessagingException("NoSuchAlgorithmException in getHttpClient: " + nsa);
} catch (KeyManagementException kme) {
Log.e(LOG_TAG, "KeyManagementException in getHttpClient: " + kme);
throw new MessagingException("KeyManagementException in getHttpClient: " + kme);
}
}
return httpClient;
}
use of org.apache.http.conn.scheme.Scheme in project ignition by mttkay.
the class IgnitedHttp method setupHttpClient.
protected void setupHttpClient() {
BasicHttpParams httpParams = new BasicHttpParams();
ConnManagerParams.setTimeout(httpParams, DEFAULT_WAIT_FOR_CONNECTION_TIMEOUT);
ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(DEFAULT_MAX_CONNECTIONS));
ConnManagerParams.setMaxTotalConnections(httpParams, DEFAULT_MAX_CONNECTIONS);
HttpConnectionParams.setSoTimeout(httpParams, DEFAULT_SOCKET_TIMEOUT);
HttpConnectionParams.setTcpNoDelay(httpParams, true);
HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setUserAgent(httpParams, DEFAULT_HTTP_USER_AGENT);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
if (IgnitedDiagnostics.ANDROID_API_LEVEL >= 7) {
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
} else {
// used to work around a bug in Android 1.6:
// http://code.google.com/p/android/issues/detail?id=1946
// TODO: is there a less rigorous workaround for this?
schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));
}
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry);
httpClient = new DefaultHttpClient(cm, httpParams);
}
use of org.apache.http.conn.scheme.Scheme in project ignition by mttkay.
the class IgnitedHttp method setPortForScheme.
public void setPortForScheme(String scheme, int port) {
Scheme _scheme = new Scheme(scheme, PlainSocketFactory.getSocketFactory(), port);
httpClient.getConnectionManager().getSchemeRegistry().register(_scheme);
}
use of org.apache.http.conn.scheme.Scheme in project custom-cert-https by nelenkov.
the class MainActivity method createHttpClient.
private HttpClient createHttpClient(SocketFactory socketFactory) {
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
HttpConnectionParams.setConnectionTimeout(params, TIMEOUT);
ConnPerRoute connPerRoute = new ConnPerRouteBean(MAX_CONN_PER_ROUTE);
ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);
ConnManagerParams.setMaxTotalConnections(params, MAX_CONNECTIONS);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
SocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
if (socketFactory != null) {
sslSocketFactory = socketFactory;
}
schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
return new DefaultHttpClient(cm, params);
}
Aggregations