Search in sources :

Example 36 with ThreadSafeClientConnManager

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);
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) Scheme(org.apache.http.conn.scheme.Scheme) ThreadSafeClientConnManager(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) BasicHttpParams(org.apache.http.params.BasicHttpParams) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager)

Example 37 with ThreadSafeClientConnManager

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();
    }
}
Also used : Scheme(org.apache.http.conn.scheme.Scheme) GeneralSecurityException(java.security.GeneralSecurityException) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) ThreadSafeClientConnManager(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory) BasicHttpParams(org.apache.http.params.BasicHttpParams)

Aggregations

ThreadSafeClientConnManager (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)37 Scheme (org.apache.http.conn.scheme.Scheme)30 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)29 BasicHttpParams (org.apache.http.params.BasicHttpParams)29 HttpParams (org.apache.http.params.HttpParams)28 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)27 ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)24 SSLSocketFactory (org.apache.http.conn.ssl.SSLSocketFactory)11 IOException (java.io.IOException)8 ConnPerRouteBean (org.apache.http.conn.params.ConnPerRouteBean)7 KeyManagementException (java.security.KeyManagementException)6 KeyStoreException (java.security.KeyStoreException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 UnrecoverableKeyException (java.security.UnrecoverableKeyException)6 UnknownHostException (java.net.UnknownHostException)5 CertificateException (java.security.cert.CertificateException)5 HttpHost (org.apache.http.HttpHost)5 KeyStore (java.security.KeyStore)4 SSLSessionCache (android.net.SSLSessionCache)3 GeneralSecurityException (java.security.GeneralSecurityException)2