Example usage for org.apache.http.impl.conn PoolingHttpClientConnectionManager PoolingHttpClientConnectionManager

List of usage examples for org.apache.http.impl.conn PoolingHttpClientConnectionManager PoolingHttpClientConnectionManager

Introduction

In this page you can find the example usage for org.apache.http.impl.conn PoolingHttpClientConnectionManager PoolingHttpClientConnectionManager.

Prototype

public PoolingHttpClientConnectionManager() 

Source Link

Usage

From source file:edu.ucsb.nceas.ezid.EZIDService.java

/**
 * Generate an HTTP Client for communicating with web services that is
 * thread safe and can be used in the context of a multi-threaded application.
 * @return DefaultHttpClient/*w  w  w . ja v a2  s. c  o m*/
 */
private static CloseableHttpClient createThreadSafeClient() {
    BasicCookieStore cookieStore = new BasicCookieStore();

    PoolingHttpClientConnectionManager poolingConnManager = new PoolingHttpClientConnectionManager();
    CloseableHttpClient client = HttpClients.custom().setConnectionManager(poolingConnManager)
            .setDefaultCookieStore(cookieStore).build();
    poolingConnManager.setMaxTotal(5);
    poolingConnManager.setDefaultMaxPerRoute(CONNECTIONS_PER_ROUTE);
    return client;
}

From source file:de.dtag.tlabs.cbclient.CBClient.java

public CBClient() {
    cm = new PoolingHttpClientConnectionManager();
    httpClient = HttpClients.custom().setConnectionManager(cm).build();

    System.out.println("CM: " + cm);
    System.out.println("httpClient: " + httpClient);

}

From source file:org.apache.manifoldcf.crawler.connectors.sharepoint.SharePointRepository.java

/** Set up a session */
protected void getSession() throws ManifoldCFException {
    if (proxy == null) {
        String serverVersion = params.getParameter(SharePointConfig.PARAM_SERVERVERSION);
        if (serverVersion == null)
            serverVersion = "4.0";
        supportsItemSecurity = !serverVersion.equals("2.0");
        dspStsWorks = serverVersion.equals("2.0") || serverVersion.equals("3.0");
        attachmentsSupported = !serverVersion.equals("2.0");

        String authorityType = params.getParameter(SharePointConfig.PARAM_AUTHORITYTYPE);
        if (authorityType == null)
            authorityType = "ActiveDirectory";

        activeDirectoryAuthority = authorityType.equals("ActiveDirectory");

        serverProtocol = params.getParameter(SharePointConfig.PARAM_SERVERPROTOCOL);
        if (serverProtocol == null)
            serverProtocol = "http";
        try {// w w w . j  a v a2s  .  c om
            String serverPort = params.getParameter(SharePointConfig.PARAM_SERVERPORT);
            if (serverPort == null || serverPort.length() == 0) {
                if (serverProtocol.equals("https"))
                    this.serverPort = 443;
                else
                    this.serverPort = 80;
            } else
                this.serverPort = Integer.parseInt(serverPort);
        } catch (NumberFormatException e) {
            throw new ManifoldCFException(e.getMessage(), e);
        }
        serverLocation = params.getParameter(SharePointConfig.PARAM_SERVERLOCATION);
        if (serverLocation == null)
            serverLocation = "";
        if (serverLocation.endsWith("/"))
            serverLocation = serverLocation.substring(0, serverLocation.length() - 1);
        if (serverLocation.length() > 0 && !serverLocation.startsWith("/"))
            serverLocation = "/" + serverLocation;
        encodedServerLocation = serverLocation;
        serverLocation = decodePath(serverLocation);

        userName = params.getParameter(SharePointConfig.PARAM_SERVERUSERNAME);
        password = params.getObfuscatedParameter(SharePointConfig.PARAM_SERVERPASSWORD);
        int index = userName.indexOf("\\");
        if (index != -1) {
            strippedUserName = userName.substring(index + 1);
            ntlmDomain = userName.substring(0, index);
        } else {
            strippedUserName = null;
            ntlmDomain = null;
        }

        String proxyHost = params.getParameter(SharePointConfig.PARAM_PROXYHOST);
        String proxyPortString = params.getParameter(SharePointConfig.PARAM_PROXYPORT);
        int proxyPort = 8080;
        if (proxyPortString != null && proxyPortString.length() > 0) {
            try {
                proxyPort = Integer.parseInt(proxyPortString);
            } catch (NumberFormatException e) {
                throw new ManifoldCFException(e.getMessage(), e);
            }
        }
        String proxyUsername = params.getParameter(SharePointConfig.PARAM_PROXYUSER);
        String proxyPassword = params.getParameter(SharePointConfig.PARAM_PROXYPASSWORD);
        String proxyDomain = params.getParameter(SharePointConfig.PARAM_PROXYDOMAIN);

        serverUrl = serverProtocol + "://" + serverName;
        if (serverProtocol.equals("https")) {
            if (serverPort != 443)
                serverUrl += ":" + Integer.toString(serverPort);
        } else {
            if (serverPort != 80)
                serverUrl += ":" + Integer.toString(serverPort);
        }

        fileBaseUrl = serverUrl + encodedServerLocation;

        // Set up ssl if indicated
        keystoreData = params.getParameter(SharePointConfig.PARAM_SERVERKEYSTORE);

        int connectionTimeout = 60000;
        int socketTimeout = 900000;

        connectionManager = new PoolingHttpClientConnectionManager();

        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();

        SSLConnectionSocketFactory myFactory = null;
        if (keystoreData != null) {
            keystoreManager = KeystoreManagerFactory.make("", keystoreData);
            myFactory = new SSLConnectionSocketFactory(keystoreManager.getSecureSocketFactory(),
                    new BrowserCompatHostnameVerifier());
        }

        if (strippedUserName != null) {
            credentialsProvider.setCredentials(new AuthScope(serverName, serverPort),
                    new NTCredentials(strippedUserName, password, currentHost, ntlmDomain));
        }

        RequestConfig.Builder requestBuilder = RequestConfig.custom().setCircularRedirectsAllowed(true)
                .setSocketTimeout(socketTimeout).setStaleConnectionCheckEnabled(true)
                .setExpectContinueEnabled(false).setConnectTimeout(connectionTimeout)
                .setConnectionRequestTimeout(socketTimeout);

        // If there's a proxy, set that too.
        if (proxyHost != null && proxyHost.length() > 0) {

            // Configure proxy authentication
            if (proxyUsername != null && proxyUsername.length() > 0) {
                if (proxyPassword == null)
                    proxyPassword = "";
                if (proxyDomain == null)
                    proxyDomain = "";

                credentialsProvider.setCredentials(new AuthScope(proxyHost, proxyPort),
                        new NTCredentials(proxyUsername, proxyPassword, currentHost, proxyDomain));
            }

            HttpHost proxy = new HttpHost(proxyHost, proxyPort);

            requestBuilder.setProxy(proxy);
        }

        HttpClientBuilder builder = HttpClients.custom().setConnectionManager(connectionManager)
                .setMaxConnTotal(1).disableAutomaticRetries().setDefaultRequestConfig(requestBuilder.build())
                .setDefaultSocketConfig(
                        SocketConfig.custom().setTcpNoDelay(true).setSoTimeout(socketTimeout).build())
                .setDefaultCredentialsProvider(credentialsProvider);
        if (myFactory != null)
            builder.setSSLSocketFactory(myFactory);
        builder.setRequestExecutor(new HttpRequestExecutor(socketTimeout))
                .setRedirectStrategy(new DefaultRedirectStrategy());
        httpClient = builder.build();

        proxy = new SPSProxyHelper(serverUrl, encodedServerLocation, serverLocation, userName, password,
                org.apache.manifoldcf.connectorcommon.common.CommonsHTTPSender.class, "client-config.wsdd",
                httpClient);

    }
    sessionTimeout = System.currentTimeMillis() + sessionExpirationInterval;
}

From source file:org.frontcache.FrontCacheEngine.java

private PoolingHttpClientConnectionManager newConnectionManager() {
    try {//from  w  w  w  . jav  a 2  s  .  co m
        //              KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        //              trustStore.load(new FileInputStream(keyStorePath), keyStorePassword.toCharArray());

        //              MySSLSocketFactory sf = new MySSLSocketFactory(trustStore);
        //              sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        //         final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
        //               .register("http", PlainConnectionSocketFactory.INSTANCE)
        //               .register("https", sf)
        //               .build();

        //         connectionManager = new PoolingHttpClientConnectionManager(registry);
        connectionManager = new PoolingHttpClientConnectionManager();

        connectionManager.setMaxTotal(fcConnectionsMaxTotal);
        connectionManager.setDefaultMaxPerRoute(fcConnectionsMaxPerRoute);

        return connectionManager;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:org.apache.archiva.admin.repository.admin.DefaultArchivaAdministration.java

protected void setupWagon(NetworkConfiguration networkConfiguration) {
    if (networkConfiguration == null) {
        // back to default values
        HttpWagon.setPersistentPool(true);
        poolingClientConnectionManager = new PoolingHttpClientConnectionManager();
        poolingClientConnectionManager.setDefaultMaxPerRoute(30);
        poolingClientConnectionManager.setMaxTotal(30);
        HttpWagon.setPoolingHttpClientConnectionManager(poolingClientConnectionManager);

    } else {/*  w ww  .ja v a2 s . c o m*/
        HttpWagon.setPersistentPool(networkConfiguration.isUsePooling());
        poolingClientConnectionManager = new PoolingHttpClientConnectionManager();
        poolingClientConnectionManager.setDefaultMaxPerRoute(networkConfiguration.getMaxTotalPerHost());
        poolingClientConnectionManager.setMaxTotal(networkConfiguration.getMaxTotal());
        HttpWagon.setPoolingHttpClientConnectionManager(poolingClientConnectionManager);
    }
}

From source file:com.cognitivemedicine.nifi.http.PostAdvancedHTTP.java

private Config getConfig(final String url, final ProcessContext context) {
    final String baseUrl = getBaseUrl(url);
    Config config = configMap.get(baseUrl);
    if (config != null) {
        return config;
    }/*w ww. ja  v  a 2s .  c o m*/

    final PoolingHttpClientConnectionManager conMan;
    final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE)
            .asControllerService(SSLContextService.class);
    if (sslContextService == null) {
        conMan = new PoolingHttpClientConnectionManager();
    } else {
        final SSLContext sslContext;
        try {
            sslContext = createSSLContext(sslContextService);
        } catch (final Exception e) {
            throw new ProcessException(e);
        }

        final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext,
                new String[] { "TLSv1" }, null,
                SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);

        final Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
                .<ConnectionSocketFactory>create().register("https", sslsf).build();

        conMan = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
    }

    conMan.setDefaultMaxPerRoute(context.getMaxConcurrentTasks());
    conMan.setMaxTotal(context.getMaxConcurrentTasks());
    config = new Config(conMan);
    final Config existingConfig = configMap.putIfAbsent(baseUrl, config);

    return (existingConfig == null) ? config : existingConfig;
}

From source file:com.unboundid.scim.sdk.SCIMService.java

/**
 * Create a new ClientConfig with the default settings.
 *
 * @return A new ClientConfig with the default settings.
 *///w  w w  .  j a v a  2 s  .  c o  m
private static ClientConfig createDefaultClientConfig() {
    final PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
    mgr.setMaxTotal(100);
    mgr.setDefaultMaxPerRoute(100);

    ClientConfig jerseyConfig = new ClientConfig();
    ApacheConnectorProvider connectorProvider = new ApacheConnectorProvider();
    jerseyConfig.connectorProvider(connectorProvider);
    return jerseyConfig;
}

From source file:org.hupo.psi.mi.psicquic.ws.SolrBasedPsicquicRestService.java

protected HttpClient createHttpClient() {
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setMaxTotal(SolrBasedPsicquicService.maxTotalConnections);
    cm.setDefaultMaxPerRoute(SolrBasedPsicquicService.defaultMaxConnectionsPerHost);

    RequestConfig.Builder requestBuilder = RequestConfig.custom();
    requestBuilder = requestBuilder.setConnectTimeout(SolrBasedPsicquicService.connectionTimeOut);
    requestBuilder = requestBuilder.setSocketTimeout(SolrBasedPsicquicService.soTimeOut);

    HttpClientBuilder builder = HttpClientBuilder.create();
    builder.setDefaultRequestConfig(requestBuilder.build());
    builder.setConnectionManager(cm);/*  w w w  .  ja v  a 2 s  .  c o  m*/

    return builder.build();
}

From source file:org.apache.sling.etcd.client.impl.EtcdClientImplTest.java

private void buildEtcdClient(int port) throws Exception {
    connectionManager = new PoolingHttpClientConnectionManager();
    final RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(10000).setConnectTimeout(10000)
            .setRedirectsEnabled(true).setStaleConnectionCheckEnabled(true).build();
    httpClient = HttpClients.custom().setConnectionManager(connectionManager)
            .setDefaultRequestConfig(requestConfig).build();
    etcdClient = new EtcdClientImpl(httpClient, new URI("http://localhost:" + port));
}

From source file:prodoc.DriverRemote.java

static synchronized private PoolingHttpClientConnectionManager GenPool() {
    if (cm == null) {
        cm = new PoolingHttpClientConnectionManager();
        cm.setMaxTotal(100);/*from   w  ww  .j a va  2  s .  co m*/
        ConnectionConfig connectionConfig = ConnectionConfig.custom().setCharset(Consts.UTF_8).build();
        cm.setDefaultConnectionConfig(connectionConfig);
    }
    return (cm);
}