use of org.apache.http.conn.ClientConnectionManager 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.ClientConnectionManager in project android-app by eoecn.
the class CustomHttpClient method getHttpClient.
/**
* 创建httpClient实例
*
* @return
* @throws Exception
*/
private static synchronized HttpClient getHttpClient(Context context) {
if (null == customerHttpClient) {
HttpParams params = new BasicHttpParams();
// 设置一些基本参数
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, CHARSET_UTF8);
HttpProtocolParams.setUseExpectContinue(params, true);
HttpProtocolParams.setUserAgent(params, "Mozilla/5.0(Linux;U;Android 2.2.1;en-us;Nexus One Build.FRG83) " + "AppleWebKit/553.1(KHTML,like Gecko) Version/4.0 Mobile Safari/533.1");
// 超时设置
/* 从连接池中取连接的超时时间 */
ConnManagerParams.setTimeout(params, 1000);
/* 连接超时 */
int ConnectionTimeOut = 3000;
if (!HttpUtils.isWifiDataEnable(context)) {
ConnectionTimeOut = 10000;
}
HttpConnectionParams.setConnectionTimeout(params, ConnectionTimeOut);
/* 请求超时 */
HttpConnectionParams.setSoTimeout(params, 4000);
// 设置我们的HttpClient支持HTTP和HTTPS两种模式
SchemeRegistry schReg = new SchemeRegistry();
schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
// 使用线程安全的连接管理来创建HttpClient
ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);
customerHttpClient = new DefaultHttpClient(conMgr, params);
}
return customerHttpClient;
}
use of org.apache.http.conn.ClientConnectionManager in project Libraries-for-Android-Developers by eoecn.
the class MySSLSocketFactory method getNewHttpClient.
/**
* Gets a DefaultHttpClient which trusts a set of certificates specified by the KeyStore
*
* @param keyStore
* @return
*/
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.ClientConnectionManager in project oxAuth by GluuFederation.
the class HttpService method getHttpsClientTrustAll.
public HttpClient getHttpsClientTrustAll() {
try {
SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
}, new AllowAllHostnameVerifier());
PlainSocketFactory psf = PlainSocketFactory.getSocketFactory();
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", 80, psf));
registry.register(new Scheme("https", 443, sf));
ClientConnectionManager ccm = new PoolingClientConnectionManager(registry);
return new DefaultHttpClient(ccm);
} catch (Exception ex) {
log.error("Failed to create TrustAll https client", ex);
return new DefaultHttpClient();
}
}
use of org.apache.http.conn.ClientConnectionManager in project musiccabinet by hakko.
the class ArtistTopTagsServiceTest method getArtistTopTagsClient.
@SuppressWarnings("unchecked")
private ArtistTopTagsClient getArtistTopTagsClient(WebserviceHistoryService historyService) throws IOException {
// create a HTTP client that always returns Cher top tracks
HttpClient httpClient = mock(HttpClient.class);
ClientConnectionManager connectionManager = mock(ClientConnectionManager.class);
when(httpClient.getConnectionManager()).thenReturn(connectionManager);
String httpResponse = new ResourceUtil(CHER_TOP_TAGS).getContent();
when(httpClient.execute(Mockito.any(HttpUriRequest.class), Mockito.any(ResponseHandler.class))).thenReturn(httpResponse);
// create a throttling service that allows calls at any rate
ThrottleService throttleService = mock(ThrottleService.class);
// create a client based on mocked HTTP client
ArtistTopTagsClient attClient = new ArtistTopTagsClient();
attClient.setWebserviceHistoryService(historyService);
attClient.setHttpClient(httpClient);
attClient.setThrottleService(throttleService);
return attClient;
}
Aggregations