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

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

Introduction

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

Prototype

public void setMaxTotal(final int max) 

Source Link

Usage

From source file:org.kaaproject.kaa.server.verifiers.gplus.verifier.GplusUserVerifier.java

@Override
public void start() {
    LOG.info("user verifier started");
    threadPool = new ThreadPoolExecutor(configuration.getMinParallelConnections(),
            configuration.getMaxParallelConnections(), configuration.getKeepAliveTimeMilliseconds(),
            TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
    PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
    connectionManager.setMaxTotal(configuration.getMaxParallelConnections());
    httpClient = HttpClients.custom().setConnectionManager(connectionManager).build();
}

From source file:dal.arris.RequestArrisAlter.java

public RequestArrisAlter(Integer deviceId, Autenticacao autenticacao, String frequency)
        throws UnsupportedEncodingException, IOException {
    Autenticacao a = AuthFactory.getEnd();
    String auth = a.getUser() + ":" + a.getPassword();
    String url = a.getLink() + "capability/execute?capability="
            + URLEncoder.encode("\"getLanWiFiInfo\"", "UTF-8") + "&deviceId=" + deviceId + "&input="
            + URLEncoder.encode(frequency, "UTF-8");

    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setMaxTotal(1);
    cm.setDefaultMaxPerRoute(1);// w  ww.  j  a  v  a  2 s. c  om
    HttpHost localhost = new HttpHost("10.200.6.150", 80);
    cm.setMaxPerRoute(new HttpRoute(localhost), 50);

    // Cookies
    RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.DEFAULT).build();

    CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(cm)
            .setDefaultRequestConfig(globalConfig).build();

    byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("UTF-8")));
    String authHeader = "Basic " + new String(encodedAuth);

    //        CloseableHttpClient httpclient = HttpClients.createDefault();
    try {
        HttpGet httpget = new HttpGet(url);
        httpget.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
        httpget.setHeader(HttpHeaders.CONTENT_TYPE, "text/html");
        httpget.setHeader("Cookie", "JSESSIONID=aaazqNDcHoduPbavRvVUv; AX-CARE-AGENTS-20480=HECDMIAKJABP");

        RequestConfig localConfig = RequestConfig.copy(globalConfig).setCookieSpec(CookieSpecs.STANDARD_STRICT)
                .build();

        HttpGet httpGet = new HttpGet("/");
        httpGet.setConfig(localConfig);

        //            httpget.setHeader(n);
        System.out.println("Executing request " + httpget.getRequestLine());
        CloseableHttpResponse response = httpclient.execute(httpget);

        try {
            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());

            // Get hold of the response entity
            HttpEntity entity = response.getEntity();

            // If the response does not enclose an entity, there is no need
            // to bother about connection release
            if (entity != null) {
                InputStream instream = entity.getContent();
                try {
                    instream.read();
                    BufferedReader rd = new BufferedReader(
                            new InputStreamReader(response.getEntity().getContent()));
                    String line = "";
                    while ((line = rd.readLine()) != null) {
                        System.out.println(line);
                    }
                    // do something useful with the response
                } catch (IOException ex) {
                    // In case of an IOException the connection will be released
                    // back to the connection manager automatically
                    throw ex;
                } finally {
                    // Closing the input stream will trigger connection release
                    instream.close();
                }
            }
        } finally {
            response.close();
            for (Header allHeader : response.getAllHeaders()) {
                System.out.println("Nome: " + allHeader.getName() + " Valor: " + allHeader.getValue());
            }
        }
    } finally {
        httpclient.close();
    }
    httpclient.close();
}

From source file:gobblin.writer.http.AbstractHttpWriterBuilder.java

public B fromConfig(Config config) {
    config = config.withFallback(FALLBACK);
    RequestConfig requestConfig = RequestConfig.copy(RequestConfig.DEFAULT)
            .setSocketTimeout(config.getInt(REQUEST_TIME_OUT_MS_KEY))
            .setConnectTimeout(config.getInt(CONNECTION_TIME_OUT_MS_KEY))
            .setConnectionRequestTimeout(config.getInt(CONNECTION_TIME_OUT_MS_KEY)).build();

    getHttpClientBuilder().setDefaultRequestConfig(requestConfig);

    if (config.hasPath(STATIC_SVC_ENDPOINT)) {
        try {//  w  w w  . j a  va 2s  .c  o  m
            svcEndpoint = Optional.of(new URI(config.getString(AbstractHttpWriterBuilder.STATIC_SVC_ENDPOINT)));
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
    }

    String connMgrStr = config.getString(HTTP_CONN_MANAGER);
    switch (ConnManager.valueOf(connMgrStr.toUpperCase())) {
    case BASIC:
        httpConnManager = new BasicHttpClientConnectionManager();
        break;
    case POOLING:
        PoolingHttpClientConnectionManager poolingConnMgr = new PoolingHttpClientConnectionManager();
        poolingConnMgr.setMaxTotal(config.getInt(POOLING_CONN_MANAGER_MAX_TOTAL_CONN));
        poolingConnMgr.setDefaultMaxPerRoute(config.getInt(POOLING_CONN_MANAGER_MAX_PER_CONN));
        httpConnManager = poolingConnMgr;
        break;
    default:
        throw new IllegalArgumentException(connMgrStr + " is not supported");
    }
    LOG.info("Using " + httpConnManager.getClass().getSimpleName());
    return typedSelf();
}

From source file:eu.over9000.cathode.Dispatcher.java

Dispatcher(final String clientID, final String authToken) {
    undocumented = new UndocumentedDispatcher();

    final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
    connectionManager.setMaxTotal(CONNECTION_COUNT);
    connectionManager.setDefaultMaxPerRoute(CONNECTION_COUNT);

    final List<Header> headers = new ArrayList<>();
    headers.add(new BasicHeader(HttpHeaders.ACCEPT, "application/vnd.twitchtv.v3+json"));
    headers.add(new BasicHeader("Client-ID", clientID));
    if (authToken != null) {
        headers.add(new BasicHeader("Authorization", "OAuth " + authToken));
    }/*w  w w .  jav a2 s  .co m*/

    HTTP_CLIENT = HttpClients.custom().setDefaultHeaders(headers).setConnectionManager(connectionManager)
            .build();
}

From source file:org.elasticsearch.client.SSLSocketFactoryHttpConfigCallback.java

@Override
public void customizeHttpClient(HttpClientBuilder httpClientBuilder) {
    Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
            .register("http", PlainConnectionSocketFactory.getSocketFactory())
            .register("https", sslSocketFactory).build();
    PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(
            socketFactoryRegistry);/* w w  w  . jav  a 2  s . c o m*/
    //default settings may be too constraining
    connectionManager.setDefaultMaxPerRoute(10);
    connectionManager.setMaxTotal(30);
    httpClientBuilder.setConnectionManager(connectionManager);
}

From source file:org.squashtest.tm.plugin.testautomation.jenkins.internal.net.HttpClientProvider.java

public HttpClientProvider() {
    PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager();
    manager.setMaxTotal(25);

    client = HttpClients.custom().setConnectionManager(manager)
            .addInterceptorFirst(new PreemptiveAuthInterceptor())
            .setDefaultCredentialsProvider(credentialsProvider).build();

    requestFactory = new HttpComponentsClientHttpRequestFactory(client);
}

From source file:org.wso2.carbon.bpmn.extensions.rest.SyncInvokeTask.java

public SyncInvokeTask() {

    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setDefaultMaxPerRoute(200);/*from w  w w  .j av a  2s.c  o  m*/
    cm.setMaxTotal(200);
    client = HttpClients.custom().setConnectionManager(cm).build();
}

From source file:monasca.api.infrastructure.persistence.influxdb.InfluxV9RepoReader.java

@Inject
public InfluxV9RepoReader(final ApiConfig config) {

    this.influxName = config.influxDB.getName();
    logger.debug("Influxdb database name: {}", this.influxName);

    this.influxUrl = config.influxDB.getUrl() + "/query";
    logger.debug("Influxdb URL: {}", this.influxUrl);

    this.influxUser = config.influxDB.getUser();
    this.influxPass = config.influxDB.getPassword();
    this.influxCreds = this.influxUser + ":" + this.influxPass;

    this.gzip = config.influxDB.getGzip();
    logger.debug("Influxdb gzip responses: {}", this.gzip);

    logger.debug("Setting up basic Base64 authentication");
    this.baseAuthHeader = "Basic " + new String(Base64.encodeBase64(this.influxCreds.getBytes()));

    // We inject InfluxV9RepoReader as a singleton. So, we must share connections safely.
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setMaxTotal(config.influxDB.getMaxHttpConnections());

    if (this.gzip) {

        logger.debug("Setting up gzip responses from Influxdb");

        this.httpClient = HttpClients.custom().setConnectionManager(cm)
                .addInterceptorFirst(new HttpRequestInterceptor() {

                    public void process(final HttpRequest request, final HttpContext context)
                            throws HttpException, IOException {
                        if (!request.containsHeader("Accept-Encoding")) {
                            request.addHeader("Accept-Encoding", "gzip");
                        }/*  www.j  av a  2s  . c  om*/
                    }
                }).addInterceptorFirst(new HttpResponseInterceptor() {

                    public void process(final HttpResponse response, final HttpContext context)
                            throws HttpException, IOException {
                        HttpEntity entity = response.getEntity();
                        if (entity != null) {
                            Header ceheader = entity.getContentEncoding();
                            if (ceheader != null) {
                                HeaderElement[] codecs = ceheader.getElements();
                                for (int i = 0; i < codecs.length; i++) {
                                    if (codecs[i].getName().equalsIgnoreCase("gzip")) {
                                        response.setEntity(new GzipDecompressingEntity(response.getEntity()));
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }).build();

    } else {

        logger.debug("Setting up non-gzip responses from Influxdb");

        this.httpClient = HttpClients.custom().setConnectionManager(cm).build();

    }
}

From source file:org.geosdi.geoplatform.experimental.openam.support.config.connector.secure.OpenAMAuthorizedConnector.java

protected OpenAMAuthorizedConnector(GPConnectorSettings theOpenAMConnectorSettings) {
    Preconditions.checkNotNull(theOpenAMConnectorSettings, "The OpenAMConnectorSettings must not be null.");
    this.openAMConnectorSettings = theOpenAMConnectorSettings;
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setMaxTotal(this.openAMConnectorSettings.getMaxTotalConnections());
    cm.setDefaultMaxPerRoute(this.openAMConnectorSettings.getDefaultMaxPerRoute());
    this.httpClient = HttpClients.custom().setConnectionManager(cm)
            .setRetryHandler(new OpenAMHttpRequestRetryHandler(5)).build();
}

From source file:com.hp.octane.integrations.services.rest.SSCRestClientImpl.java

SSCRestClientImpl(OctaneSDK.SDKServicesConfigurer configurer) {
    if (configurer == null || configurer.pluginServices == null) {
        throw new IllegalArgumentException("invalid configurer");
    }/*from  ww  w  .j  a v a2  s  .  c  o m*/

    SSLContext sslContext = SSLContexts.createSystemDefault();
    HostnameVerifier hostnameVerifier = new OctaneRestClientImpl.CustomHostnameVerifier();
    SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
    Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
            .register("http", PlainConnectionSocketFactory.getSocketFactory())
            .register("https", sslSocketFactory).build();
    PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(
            socketFactoryRegistry);
    connectionManager.setMaxTotal(MAX_TOTAL_CONNECTIONS);
    connectionManager.setDefaultMaxPerRoute(MAX_TOTAL_CONNECTIONS);

    HttpClientBuilder clientBuilder = HttpClients.custom().setConnectionManager(connectionManager);

    httpClient = clientBuilder.build();
}