use of org.apache.http.conn.ClientConnectionManager in project androidannotations by androidannotations.
the class SSLConnectionTest method methodInjectedHttpsClient.
@Test
public void methodInjectedHttpsClient() {
assertNotNull(activity.methodInjectedHttpsClient);
ClientConnectionManager ccm = activity.methodInjectedHttpsClient.getConnectionManager();
assertNotNull(ccm);
}
use of org.apache.http.conn.ClientConnectionManager in project androidannotations by androidannotations.
the class SSLConnectionTest method truststoreProvided.
@Test
public void truststoreProvided() {
assertNotNull(activity.mHttpsClientTest1);
ClientConnectionManager ccm = activity.mHttpsClientTest1.getConnectionManager();
assertNotNull(ccm);
Scheme httpsScheme = ccm.getSchemeRegistry().getScheme("https");
assertNotNull(httpsScheme);
assertEquals(443, httpsScheme.getDefaultPort());
SocketFactory socketFactHttps = httpsScheme.getSocketFactory();
if (!(socketFactHttps instanceof SSLSocketFactory)) {
fail("wrong instance should be org.apache.http.conn.ssl.SSLSocketFactory, getting " + socketFactHttps);
}
assertEquals(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER, ((SSLSocketFactory) socketFactHttps).getHostnameVerifier());
}
use of org.apache.http.conn.ClientConnectionManager in project androidannotations by androidannotations.
the class SSLConnectionTest method multiInjectedHttpsClient.
@Test
public void multiInjectedHttpsClient() {
assertNotNull(activity.multiInjectedHttpsClient);
ClientConnectionManager ccm = activity.multiInjectedHttpsClient.getConnectionManager();
assertNotNull(ccm);
}
use of org.apache.http.conn.ClientConnectionManager 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.ClientConnectionManager 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