use of org.apache.http.conn.scheme.SchemeRegistry 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);
}
use of org.apache.http.conn.scheme.SchemeRegistry in project platformlayer by platformlayer.
the class MetricClientImpl method buildHttpClient.
private HttpClient buildHttpClient(CertificateAndKey certificateAndKey, List<String> trustKeys) {
int port = metricBaseUrl.getPort();
if (port == -1) {
String scheme = metricBaseUrl.getScheme();
if (scheme.equals("https")) {
port = 443;
} else if (scheme.equals("http")) {
port = 80;
} else {
throw new IllegalArgumentException("Unknown scheme: " + scheme);
}
}
SchemeSocketFactory schemeSocketFactory;
try {
KeyManager keyManager = new SimpleClientCertificateKeyManager(certificateAndKey);
TrustManager trustManager;
X509HostnameVerifier hostnameVerifier;
if (trustKeys != null) {
trustManager = new PublicKeyTrustManager(trustKeys);
hostnameVerifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
} else {
trustManager = null;
hostnameVerifier = SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER;
}
javax.net.ssl.SSLSocketFactory sslSocketFactory = SslHelpers.buildSslSocketFactory(keyManager, trustManager);
schemeSocketFactory = new SSLSocketFactory(sslSocketFactory, hostnameVerifier);
} catch (GeneralSecurityException e) {
throw new IllegalArgumentException("Error building SSL client", e);
}
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("https", port, schemeSocketFactory));
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
HttpClient httpClient = new DefaultHttpClient(connectionManager);
httpClient = new DecompressingHttpClient(httpClient);
return httpClient;
}
use of org.apache.http.conn.scheme.SchemeRegistry in project platformlayer by platformlayer.
the class ApacheCommonsHttpConfiguration method buildHttpClient.
HttpClient buildHttpClient(SslConfiguration sslConfiguration) {
HttpParams httpParams = null;
if (sslConfiguration == null || sslConfiguration.isEmpty()) {
sslConfiguration = null;
}
ClientConnectionManager connectionManager;
if (sslConfiguration != null) {
SchemeSocketFactory schemeSocketFactory;
try {
javax.net.ssl.SSLSocketFactory sslSocketFactory = sslConfiguration.getSslSocketFactory();
X509HostnameVerifier apacheHostnameVerifier = null;
if (sslConfiguration.getHostnameVerifier() != null) {
apacheHostnameVerifier = new ApacheHostnameVerifierAdapter(sslConfiguration.getHostnameVerifier());
} else {
apacheHostnameVerifier = new ApacheHostnameVerifierAdapter(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
}
schemeSocketFactory = new SSLSocketFactory(sslSocketFactory, apacheHostnameVerifier);
} catch (GeneralSecurityException e) {
throw new IllegalArgumentException("Error building SSL client", e);
}
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("https", 443, schemeSocketFactory));
connectionManager = buildConnectionManager(schemeRegistry);
} else {
SchemeRegistry schemeRegistry = SchemeRegistryFactory.createDefault();
connectionManager = buildConnectionManager(schemeRegistry);
}
HttpClient httpClient = buildDefaultHttpClient(connectionManager, httpParams);
httpClient = wrapHttpClient(httpClient);
return httpClient;
}
use of org.apache.http.conn.scheme.SchemeRegistry in project LiveSDK-for-Android by liveservices.
the class LiveConnectClient method getHttpClient.
private static HttpClient getHttpClient() {
// The LiveConnectClients can share one HttpClient with a ThreadSafeConnManager.
if (HTTP_CLIENT == null) {
synchronized (HTTP_CLIENT_LOCK) {
if (HTTP_CLIENT == null) {
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, CONNECT_TIMEOUT_IN_MS);
HttpConnectionParams.setSoTimeout(params, SOCKET_TIMEOUT_IN_MS);
ConnManagerParams.setMaxTotalConnections(params, 100);
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));
// Create an HttpClient with the ThreadSafeClientConnManager.
// This connection manager must be used if more than one thread will
// be using the HttpClient, which is a common scenario.
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
HTTP_CLIENT = new DefaultHttpClient(cm, params);
}
}
}
return HTTP_CLIENT;
}
use of org.apache.http.conn.scheme.SchemeRegistry in project 12306-hunter by xautlx.
the class HttpClientService method buildHttpClient.
/**
* 构建HttpClient对象
*
* @return
*/
public static HttpClient buildHttpClient() {
try {
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, new TrustManager[] { tm }, null);
SSLSocketFactory ssf = new SSLSocketFactory(sslcontext);
ClientConnectionManager ccm = new DefaultHttpClient().getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", 443, ssf));
HttpParams params = new BasicHttpParams();
params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 8000);
params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 8000);
HttpClient httpclient = new DefaultHttpClient(ccm, params);
httpclient.getParams().setParameter(HTTP.USER_AGENT, "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; BOIE9;ZHCN)");
return httpclient;
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
Aggregations