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:no.api.meteo.client.DefaultMeteoClient.java

/**
 * Constructor for this Meteo Client implementation asking for the maximum number of simultaneous connections
 * allowed.//  w  ww . j a  v a 2  s. co  m
 *
 * @param maxTotalConnections
 *         The number of simultaneous connections allowed.
 */
public DefaultMeteoClient(int maxTotalConnections) {
    this.connManager = new PoolingHttpClientConnectionManager();
    init(maxTotalConnections);
}

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

public SyncInvokeTask() {

    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setDefaultMaxPerRoute(200);//from w  w w. ja v  a  2 s  .  co  m
    cm.setMaxTotal(200);
    client = HttpClients.custom().setConnectionManager(cm).build();
}

From source file:org.apache.manifoldcf.jettyrunner.ManifoldCFJettyShutdown.java

public void shutdownJetty() throws Exception {
    // Pick up shutdown token
    String shutdownToken = System.getProperty("org.apache.manifoldcf.jettyshutdowntoken");
    if (shutdownToken != null) {
        int socketTimeout = 900000;
        int connectionTimeout = 300000;

        HttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();

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

        HttpClient httpClient = HttpClients.custom().setConnectionManager(connectionManager).setMaxConnTotal(1)
                .disableAutomaticRetries().setDefaultRequestConfig(requestBuilder.build())
                .setDefaultSocketConfig(
                        SocketConfig.custom().setTcpNoDelay(true).setSoTimeout(socketTimeout).build())
                .setRequestExecutor(new HttpRequestExecutor(socketTimeout))
                .setRedirectStrategy(new DefaultRedirectStrategy()).build();

        HttpPost method = new HttpPost(
                jettyBaseURL + "/shutdown?token=" + URLEncoder.encode(shutdownToken, "UTF-8"));
        method.setEntity(new StringEntity("", ContentType.create("text/plain", StandardCharsets.UTF_8)));
        try {/*ww  w  .j a  v  a2s  .  co  m*/
            HttpResponse httpResponse = httpClient.execute(method);
            int resultCode = httpResponse.getStatusLine().getStatusCode();
            if (resultCode != 200)
                throw new Exception("Received result code " + resultCode + " from POST");
        } catch (org.apache.http.NoHttpResponseException e) {
            // This is ok and expected
        }
    } else {
        throw new Exception("No jetty shutdown token specified");
    }
}

From source file:com.flipkart.flux.client.runtime.FluxRuntimeConnectorHttpImpl.java

public FluxRuntimeConnectorHttpImpl(Long connectionTimeout, Long socketTimeout, String fluxEndpoint) {
    objectMapper = new ObjectMapper();
    this.fluxEndpoint = fluxEndpoint;
    RequestConfig clientConfig = RequestConfig.custom().setConnectTimeout((connectionTimeout).intValue())
            .setSocketTimeout((socketTimeout).intValue())
            .setConnectionRequestTimeout((socketTimeout).intValue()).build();
    PoolingHttpClientConnectionManager syncConnectionManager = new PoolingHttpClientConnectionManager();
    syncConnectionManager.setMaxTotal(MAX_TOTAL);
    syncConnectionManager.setDefaultMaxPerRoute(MAX_PER_ROUTE);

    closeableHttpClient = HttpClientBuilder.create().setDefaultRequestConfig(clientConfig)
            .setConnectionManager(syncConnectionManager).build();

    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        HttpClientUtils.closeQuietly(closeableHttpClient);
    }));/*from  w w w  .  j a  v a  2s  .c o  m*/
}

From source file:com.complexible.clearbit.Clearbit.java

public Clearbit(final String theKey, final boolean theUseStreamingAPI) {
    mKey = Preconditions.checkNotNull(theKey);
    mStreaming = theUseStreamingAPI;/*  w  w w.  jav  a2 s. com*/

    mClient = HttpClientBuilder.create().setUserAgent("clearbit.api")
            .setConnectionManager(new PoolingHttpClientConnectionManager()).build();
}

From source file:org.qucosa.camel.component.opus4.Opus4DataSource.java

private HttpClient prepareHttpClient() {
    PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
    mgr.setMaxTotal(200);// www.  j a v a2s. co  m
    mgr.setDefaultMaxPerRoute(100);
    HttpClient client = HttpClients.createMinimal(mgr);
    return client;
}

From source file:nl.knaw.huygens.alexandria.markup.client.AlexandriaMarkupClient.java

public AlexandriaMarkupClient(final URI alexandriaMarkupURI, SSLContext sslContext) {
    this.alexandriaMarkupURI = alexandriaMarkupURI;
    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.findAndRegisterModules();

    final JacksonJaxbJsonProvider jacksonProvider = new JacksonJaxbJsonProvider();
    jacksonProvider.setMapper(objectMapper);

    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setMaxTotal(50);/*from   w  w  w  .  ja v a  2  s  .  c o  m*/
    cm.setDefaultMaxPerRoute(50);

    ApacheConnectorProvider connectorProvider = new ApacheConnectorProvider();
    ClientConfig clientConfig = new ClientConfig(jacksonProvider)//
            .connectorProvider(connectorProvider)//
            .property(ApacheClientProperties.CONNECTION_MANAGER, cm)//
            .property(ClientProperties.CONNECT_TIMEOUT, 60000)//
            .property(ClientProperties.READ_TIMEOUT, 60000);

    if (sslContext == null) {
        if ("https".equals(alexandriaMarkupURI.getScheme())) {
            throw new RuntimeException(
                    "SSL connections need an SSLContext, use: new AlexandriaClient(uri, sslContext) instead.");
        }
        client = ClientBuilder.newClient(clientConfig);

    } else {
        client = ClientBuilder.newBuilder()//
                .sslContext(sslContext)//
                .withConfig(clientConfig)//
                .build();
    }
    rootTarget = client.target(alexandriaMarkupURI);
}

From source file:net.siegmar.japtproxy.fetcher.HttpClientConfigurer.java

public CloseableHttpClient build() throws InitializationException {
    final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
    connectionManager.setMaxTotal(MAX_CONNECTIONS);
    connectionManager.setDefaultMaxPerRoute(MAX_CONNECTIONS);

    final RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(connectTimeout)
            .setSocketTimeout(socketTimeout).build();

    final HttpClientBuilder httpClientBuilder = HttpClients.custom().setConnectionManager(connectionManager)
            .setDefaultRequestConfig(requestConfig);

    if (configuration.getHttpProxy() != null) {
        configureProxy(httpClientBuilder, configuration.getHttpProxy());
    }//w  ww  .  j  a v a2 s . co  m

    return httpClientBuilder.build();
}

From source file:com.feedeo.web.client.AbstractWebClient.java

protected HttpClient createHttpClient() {

    final SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(true).setTcpNoDelay(true).build();

    final ConnectionConfig connectionConfig = ConnectionConfig.custom().build();

    final RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(30000)
            .setConnectTimeout(30000).setSocketTimeout(30000).setStaleConnectionCheckEnabled(false).build();

    final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
    connectionManager.setMaxTotal(256);//from  ww  w  . j a  v a  2s.c  o m
    connectionManager.setDefaultMaxPerRoute(256);

    IdleConnectionMonitorThread staleMonitor = new IdleConnectionMonitorThread(connectionManager);
    staleMonitor.start();

    try {
        staleMonitor.join(1000);
    } catch (InterruptedException ignored) {
    }

    final ConnectionKeepAliveStrategy connectionKeepAliveStrategy = new ConnectionKeepAliveStrategy() {
        @Override
        public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
            HeaderElementIterator iterator = new BasicHeaderElementIterator(
                    response.headerIterator(CONN_KEEP_ALIVE));
            while (iterator.hasNext()) {
                HeaderElement header = iterator.nextElement();
                String param = header.getName();
                String value = header.getValue();
                if (value != null && param.equalsIgnoreCase("timeout")) {
                    return Long.parseLong(value) * 1000;
                }
            }
            return 5 * 1000;
        }
    };

    return HttpClientBuilder.create().setConnectionManager(connectionManager)
            .setDefaultRequestConfig(requestConfig).setDefaultSocketConfig(socketConfig)
            .setDefaultConnectionConfig(connectionConfig).setKeepAliveStrategy(connectionKeepAliveStrategy)
            .build();
}