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);
}
}
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 OpenMEAP by OpenMEAP.
the class SSLUtils method getRelaxedSSLVerificationHttpClient.
public static HttpClient getRelaxedSSLVerificationHttpClient() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, FormConstants.CHAR_ENC_DEFAULT);
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();
}
}
use of org.apache.http.conn.scheme.SchemeRegistry in project oxCore by GluuFederation.
the class SslDefaultHttpClient method createClientConnectionManager.
@Override
protected ClientConnectionManager createClientConnectionManager() {
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
// Register for port 443 our SSLSocketFactory with our keystore to the
// ConnectionManager
registry.register(new Scheme("https", 443, newSslSocketFactory()));
return new PoolingClientConnectionManager(registry);
}
use of org.apache.http.conn.scheme.SchemeRegistry in project coprhd-controller by CoprHD.
the class RenderProxy method createClientConnectionManager.
private static ClientConnectionManager createClientConnectionManager() {
SchemeRegistry schemeRegistry = SchemeRegistryFactory.createDefault();
SSLSocketFactory sf;
if (StorageOsPlugin.isEnabled()) {
try {
// initialize an SSLContext with the vipr keystore and trustmanager.
// This is basically a dup of most of the ViPRSSLSocketFactory constructor,
// and could be extracted
X509TrustManager[] trustManagers = { BourneUtil.getTrustManager() };
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(BourneUtil.getKeyStore(), "".toCharArray());
SSLContext context = SSLContext.getInstance("TLS");
context.init(kmf.getKeyManagers(), trustManagers, new SecureRandom());
sf = new SSLSocketFactory(context, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
} catch (Exception e) {
throw new RuntimeException("Unable to initialize the ViPRX509TrustManager for RenderProxy", e);
}
} else {
sf = new SSLSocketFactory(SSLUtil.getTrustAllContext(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
}
Scheme httpsScheme = new Scheme("https", 443, sf);
schemeRegistry.register(httpsScheme);
ClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
return connectionManager;
}
Aggregations