use of org.apache.http.conn.scheme.SchemeRegistry in project Notes by lguipeng.
the class TEvernoteHttpClient method getHTTPClient.
@Deprecated
private DefaultHttpClient getHTTPClient() {
try {
if (mConnectionManager != null) {
mConnectionManager.closeExpiredConnections();
mConnectionManager.closeIdleConnections(1, TimeUnit.SECONDS);
} else {
BasicHttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 10000);
HttpConnectionParams.setSoTimeout(params, 20000);
ConnManagerParams.setMaxTotalConnections(params, ConnManagerParams.DEFAULT_MAX_TOTAL_CONNECTIONS);
ConnManagerParams.setTimeout(params, 10000);
// Giving 18 connections to Evernote
ConnPerRouteBean connPerRoute = new ConnPerRouteBean(18);
ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
mConnectionManager = new ThreadSafeClientConnManager(params, schemeRegistry);
DefaultHttpClient httpClient = new DefaultHttpClient(mConnectionManager, params);
httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
@Override
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
// 2 minutes in millis
return 2 * 60 * 1000;
}
});
httpClient.setReuseStrategy(new ConnectionReuseStrategy() {
@Override
public boolean keepAlive(HttpResponse response, HttpContext context) {
return true;
}
});
mHttpClient = httpClient;
}
} catch (Exception ex) {
return null;
}
return mHttpClient;
}
Aggregations