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:com.olacabs.fabric.processors.httpwriter.HttpWriter.java

/**
 * Starts the HttpClient and Manager.//from   w  ww  .  j  a  v  a  2  s . c om
 */
protected void start(AuthConfiguration authConfiguration, Boolean authEnabledParam)
        throws InitializationException {
    this.manager = new PoolingHttpClientConnectionManager();
    manager.setMaxTotal(poolSize);
    manager.setDefaultMaxPerRoute(poolSize);
    //client = HttpClients.custom().setConnectionManager(manager).build();
    httpClientBuilder = HttpClients.custom();
    httpClientBuilder.setConnectionManager(manager);
    if (authEnabledParam) {
        setAuth(authConfiguration, httpClientBuilder);
    }
    client = httpClientBuilder.build();
}

From source file:org.glassfish.jersey.examples.sseitemstore.ItemStoreResourceTest.java

@Override
protected void configureClient(ClientConfig config) {
    // using AHC as a test client connector to avoid issues with HttpUrlConnection socket management.
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();

    // adjusting max. connections just to be safe - the testEventSourceReconnect is quite greedy...
    cm.setMaxTotal(MAX_LISTENERS * MAX_ITEMS);
    cm.setDefaultMaxPerRoute(MAX_LISTENERS * MAX_ITEMS);

    config.register(SseFeature.class).property(ApacheClientProperties.CONNECTION_MANAGER, cm)
            .property(ClientProperties.READ_TIMEOUT, 2000).connectorProvider(new ApacheConnectorProvider());
}

From source file:org.muhia.app.psi.integ.config.ke.crba.CreditReferenceBureauAuthorityClientConfiguration.java

@Bean(name = "transunionHttpClient")
public CloseableHttpClient httpClient() {

    RequestConfig config = RequestConfig.custom()
            .setConnectTimeout(properties.getCrbaTransportConnectionTimeout())
            .setConnectionRequestTimeout(properties.getCrbaTransportConnectionRequestTimeout())
            .setSocketTimeout(properties.getCrbaTransportReadTimeout()).build();
    CredentialsProvider provider = new BasicCredentialsProvider();
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(
            properties.getCrbaTransunionTransportUsername(), properties.getCrbaTransunionTransportPassword());
    provider.setCredentials(AuthScope.ANY, credentials);

    PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
    connManager.setMaxTotal(properties.getCrbaPoolMaxHost());
    connManager.setDefaultMaxPerRoute(properties.getCrbaPoolDefaultmaxPerhost());
    connManager.setValidateAfterInactivity(properties.getCrbaPoolValidateAfterInactivity());

    return HttpClientBuilder.create().setDefaultRequestConfig(config).setDefaultCredentialsProvider(provider)
            .setConnectionManager(connManager).evictExpiredConnections()
            .addInterceptorFirst(new RemoveHttpHeadersInterceptor()).build();

}

From source file:io.seldon.external.ExternalPredictionServer.java

@Override
public void configUpdated(String configKey, String configValue) {
    if (configValue != null && configValue.length() > 0) {
        ObjectMapper mapper = new ObjectMapper();
        try {/*from w w w .  ja  v a 2 s  . c  o m*/
            PredictionServerConfig config = mapper.readValue(configValue, PredictionServerConfig.class);
            cm = new PoolingHttpClientConnectionManager();
            cm.setMaxTotal(config.maxConnections);
            cm.setDefaultMaxPerRoute(config.maxConnections);

            RequestConfig requestConfig = RequestConfig.custom()
                    .setConnectionRequestTimeout(DEFAULT_REQ_TIMEOUT).setConnectTimeout(DEFAULT_CON_TIMEOUT)
                    .setSocketTimeout(DEFAULT_SOCKET_TIMEOUT).build();

            httpClient = HttpClients.custom().setConnectionManager(cm).setDefaultRequestConfig(requestConfig)
                    .build();
            logger.info("Updated httpclient to use " + config.maxConnections + " max connections");
        } catch (Exception e) {
            throw new RuntimeException(String.format("* Error * parsing statsd configValue[%s]", configValue),
                    e);
        }
    }

}

From source file:com.moviejukebox.tools.YamjHttpClientBuilder.java

@SuppressWarnings("resource")
private static YamjHttpClient buildHttpClient() {
    LOG.trace("Create new YAMJ http client");

    // create proxy
    HttpHost proxy = null;//w  ww . j  av a2s . c o  m
    CredentialsProvider credentialsProvider = null;

    if (StringUtils.isNotBlank(PROXY_HOST) && PROXY_PORT > 0) {
        proxy = new HttpHost(PROXY_HOST, PROXY_PORT);

        if (StringUtils.isNotBlank(PROXY_USERNAME) && StringUtils.isNotBlank(PROXY_PASSWORD)) {
            credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(new AuthScope(PROXY_HOST, PROXY_PORT),
                    new UsernamePasswordCredentials(PROXY_USERNAME, PROXY_PASSWORD));
        }
    }

    PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
    connManager.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(TIMEOUT_SOCKET).build());
    connManager.setMaxTotal(20);
    connManager.setDefaultMaxPerRoute(2);

    CacheConfig cacheConfig = CacheConfig.custom().setMaxCacheEntries(1000).setMaxObjectSize(8192).build();

    HttpClientBuilder builder = CachingHttpClientBuilder.create().setCacheConfig(cacheConfig)
            .setConnectionManager(connManager).setProxy(proxy)
            .setDefaultCredentialsProvider(credentialsProvider)
            .setDefaultRequestConfig(RequestConfig.custom().setConnectionRequestTimeout(TIMEOUT_READ)
                    .setConnectTimeout(TIMEOUT_CONNECT).setSocketTimeout(TIMEOUT_SOCKET)
                    .setCookieSpec(CookieSpecs.IGNORE_COOKIES).setProxy(proxy).build());

    // show status
    showStatus();

    // build the client
    YamjHttpClient wrapper = new YamjHttpClient(builder.build(), connManager);
    wrapper.setUserAgentSelector(new WebBrowserUserAgentSelector());
    wrapper.addGroupLimit(".*", 1); // default limit, can be overwritten

    // First we have to read/create the rules
    String maxDownloadSlots = PropertiesUtil.getProperty("mjb.MaxDownloadSlots");
    if (StringUtils.isNotBlank(maxDownloadSlots)) {
        LOG.debug("Using download limits: {}", maxDownloadSlots);

        Pattern pattern = Pattern.compile(",?\\s*([^=]+)=(\\d+)");
        Matcher matcher = pattern.matcher(maxDownloadSlots);
        while (matcher.find()) {
            String group = matcher.group(1);
            try {
                final Integer maxResults = Integer.valueOf(matcher.group(2));
                wrapper.addGroupLimit(group, maxResults);
                LOG.trace("Added download slot '{}' with max results {}", group, maxResults);
            } catch (NumberFormatException error) {
                LOG.debug("Rule '{}' is no valid regexp, ignored", group);
            }
        }
    }

    return wrapper;
}

From source file:org.yamj.core.tools.web.PoolingHttpClientBuilder.java

@SuppressWarnings("resource")
public PoolingHttpClient build() {
    // create proxy
    HttpHost proxy = null;/*from   w w  w . j a  va2  s .  c o  m*/
    CredentialsProvider credentialsProvider = null;

    if (StringUtils.isNotBlank(proxyHost) && proxyPort > 0) {
        proxy = new HttpHost(proxyHost, proxyPort);

        if (StringUtils.isNotBlank(proxyUsername) && StringUtils.isNotBlank(proxyPassword)) {
            if (systemProperties) {
                credentialsProvider = new SystemDefaultCredentialsProvider();
            } else {
                credentialsProvider = new BasicCredentialsProvider();
            }
            credentialsProvider.setCredentials(new AuthScope(proxyHost, proxyPort),
                    new UsernamePasswordCredentials(proxyUsername, proxyPassword));
        }
    }

    PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
    connManager.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(socketTimeout).build());
    connManager.setMaxTotal(connectionsMaxTotal);
    connManager.setDefaultMaxPerRoute(connectionsMaxPerRoute);

    HttpClientBuilder builder = HttpClientBuilder.create().setConnectionManager(connManager).setProxy(proxy)
            .setDefaultCredentialsProvider(credentialsProvider)
            .setDefaultRequestConfig(RequestConfig.custom()
                    .setConnectionRequestTimeout(connectionRequestTimeout).setConnectTimeout(connectionTimeout)
                    .setSocketTimeout(socketTimeout).setProxy(proxy).build());

    // use system properties
    if (systemProperties) {
        builder.useSystemProperties();
    }

    // build the client
    PoolingHttpClient wrapper = new PoolingHttpClient(builder.build(), connManager);
    wrapper.addGroupLimit(".*", 1); // default limit, can be overwritten

    if (StringUtils.isNotBlank(maxDownloadSlots)) {
        LOG.debug("Using download limits: {}", maxDownloadSlots);

        Pattern pattern = Pattern.compile(",?\\s*([^=]+)=(\\d+)");
        Matcher matcher = pattern.matcher(maxDownloadSlots);
        while (matcher.find()) {
            String group = matcher.group(1);
            try {
                final Integer maxResults = Integer.valueOf(matcher.group(2));
                wrapper.addGroupLimit(group, maxResults);
                LOG.trace("Added download slot '{}' with max results {}", group, maxResults);
            } catch (NumberFormatException error) {
                LOG.debug("Rule '{}' is no valid regexp, ignored", group);
            }
        }
    }

    return wrapper;
}

From source file:com.certivox.net.HTTPConnector.java

public HTTPConnector(String url) throws URISyntaxException {
    super();/*from   w  w  w .j  a v a 2 s  .c  o m*/
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setMaxTotal(MAX_CONNECTIONS);
    cm.setDefaultMaxPerRoute(MAX_CONNECTIONS_PER_ROUTE);
    cm.setMaxPerRoute(new HttpRoute(HttpRequestFactory.createHost(new URI(url))), MAX_COONECTIONS_FOR_HOST);
    httpClient = HttpClients.custom().setConnectionManager(cm).build();
}

From source file:com.mxhero.plugin.cloudstorage.onedrive.api.command.CommandFactory.java

/**
 * Http client connection manager./*from   w w  w  .ja v  a  2  s .  co  m*/
 *
 * @return the http client connection manager
 */
protected HttpClientConnectionManager httpClientConnectionManager() {
    PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
    return connectionManager;
}

From source file:org.apache.openmeetings.service.calendar.caldav.AppointmentManager.java

/**
 * Returns a new HttpClient with the inbuilt connection manager in this.
 *
 * @return HttpClient object that was created.
 *///from   w w w . jav  a2  s.  co  m
public HttpClient createHttpClient() {
    if (connmanager == null) {
        connmanager = new PoolingHttpClientConnectionManager();
        connmanager.setDefaultMaxPerRoute(MAX_HOST_CONNECTIONS);
        connmanager.setMaxTotal(MAX_TOTAL_CONNECTIONS);
    }

    return HttpClients.custom().setConnectionManager(connmanager).build();
}