use of org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager in project newsrob by marianokamp.
the class CountingInputStream method newInstance.
public static NewsRobHttpClient newInstance(boolean followRedirects, Context ctx) {
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setStaleCheckingEnabled(params, true);
HttpConnectionParams.setConnectionTimeout(params, 45 * 1000);
HttpConnectionParams.setSoTimeout(params, 45 * 1000);
HttpConnectionParams.setSocketBufferSize(params, 8192);
// HttpConnectionParams.setTcpNoDelay(params, true);
// Don't handle redirects -- return them to the caller. Our code
// often wants to re-POST after a redirect, which we must do ourselves.
// HttpClientParams.setRedirecting(params, false);
HttpClientParams.setRedirecting(params, followRedirects);
if (followRedirects)
params.setIntParameter(ClientPNames.MAX_REDIRECTS, 10);
// Set the specified user agent and register standard protocols.
HttpProtocolParams.setUserAgent(params, USER_AGENT);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);
// parameters without the funny call-a-static-method dance.
return new NewsRobHttpClient(manager, params, ctx);
}
use of org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager in project java-chassis by ServiceComb.
the class HttpsClient method getHttpsClient.
public static HttpClient getHttpsClient(HttpsConfigInfoBean configBean) {
try {
SSLContext sslContext = createSSLContext(configBean);
SSLSocketFactory sf = new SSLSocketFactory(sslContext);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, SO_TIMEOUT);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), PORT_80));
registry.register(new Scheme("https", sf, PORT_443));
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
return new DefaultHttpClient(ccm, params);
} catch (RuntimeException e) {
LOGGER.error("Get https client runtime exception: {}", FortifyUtils.getErrorInfo(e));
return new DefaultHttpClient();
} catch (GeneralSecurityException | IOException e) {
LOGGER.error("Get https client exception: {}", FortifyUtils.getErrorInfo(e));
return new DefaultHttpClient();
}
}
Aggregations