Search in sources :

Example 21 with PoolingHttpClientConnectionManager

use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project incubator-gobblin by apache.

the class AbstractHttpWriterBuilder method fromConfig.

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 {
            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();
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) BasicHttpClientConnectionManager(org.apache.http.impl.conn.BasicHttpClientConnectionManager) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Example 22 with PoolingHttpClientConnectionManager

use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project incubator-gobblin by apache.

the class ApacheHttpClient method getHttpConnManager.

private HttpClientConnectionManager getHttpConnManager(Config config) {
    HttpClientConnectionManager httpConnManager;
    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 httpConnManager;
}
Also used : HttpClientConnectionManager(org.apache.http.conn.HttpClientConnectionManager) BasicHttpClientConnectionManager(org.apache.http.impl.conn.BasicHttpClientConnectionManager) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) BasicHttpClientConnectionManager(org.apache.http.impl.conn.BasicHttpClientConnectionManager) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Example 23 with PoolingHttpClientConnectionManager

use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project iaf by ibissource.

the class HttpSenderBase method open.

public void open() throws SenderException {
    connectionManager = new PoolingHttpClientConnectionManager();
    connectionManager.setMaxTotal(getMaxConnections());
    log.debug(getLogPrefix() + "set up connectionManager, inactivity checking [" + connectionManager.getValidateAfterInactivity() + "]");
    boolean staleChecking = (connectionManager.getValidateAfterInactivity() >= 0);
    if (staleChecking != isStaleChecking()) {
        log.info(getLogPrefix() + "set up connectionManager, setting stale checking [" + isStaleChecking() + "]");
        connectionManager.setValidateAfterInactivity(getStaleTimeout());
    }
    httpClientBuilder.useSystemProperties();
    httpClientBuilder.disableAuthCaching();
    httpClientBuilder.setConnectionManager(connectionManager);
    if (transformerPool != null) {
        try {
            transformerPool.open();
        } catch (Exception e) {
            throw new SenderException(getLogPrefix() + "cannot start TransformerPool", e);
        }
    }
}
Also used : SenderException(nl.nn.adapterframework.core.SenderException) URISyntaxException(java.net.URISyntaxException) SenderException(nl.nn.adapterframework.core.SenderException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ClientProtocolException(org.apache.http.client.ClientProtocolException) SocketTimeoutException(java.net.SocketTimeoutException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) MethodNotSupportedException(org.apache.http.MethodNotSupportedException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) ParameterException(nl.nn.adapterframework.core.ParameterException) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Example 24 with PoolingHttpClientConnectionManager

use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project spring-boot by Linda-Tan.

the class RestTemplateConfig method httpClient.

@Bean
public HttpClient httpClient() throws KeyManagementException, NoSuchAlgorithmException {
    Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", new SSLConnectionSocketFactory(createIgnoreVerifySSL())).build();
    PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry);
    connectionManager.setMaxTotal(5);
    connectionManager.setDefaultMaxPerRoute(5);
    RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(8000).setConnectTimeout(8000).setConnectionRequestTimeout(8000).build();
    return HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).setConnectionManager(connectionManager).build();
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) PlainConnectionSocketFactory(org.apache.http.conn.socket.PlainConnectionSocketFactory) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 25 with PoolingHttpClientConnectionManager

use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project druidry by zapr-oss.

the class DruidJerseyClient method createConnectionManager.

private HttpClientConnectionManager createConnectionManager() {
    PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
    int numberOfConnectionsInPool = DEFAULT_CONNECTION_POOL_LIMIT;
    if (this.druidConfiguration.getConcurrentConnectionsRequired() != null) {
        numberOfConnectionsInPool = this.druidConfiguration.getConcurrentConnectionsRequired();
    }
    connectionManager.setDefaultMaxPerRoute(numberOfConnectionsInPool);
    return connectionManager;
}
Also used : PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Aggregations

PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)180 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)63 ConnectionSocketFactory (org.apache.http.conn.socket.ConnectionSocketFactory)62 PlainConnectionSocketFactory (org.apache.http.conn.socket.PlainConnectionSocketFactory)54 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)52 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)42 SSLContext (javax.net.ssl.SSLContext)36 RequestConfig (org.apache.http.client.config.RequestConfig)31 IOException (java.io.IOException)29 Test (org.junit.Test)27 HttpHost (org.apache.http.HttpHost)21 HttpGet (org.apache.http.client.methods.HttpGet)18 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)17 AuthScope (org.apache.http.auth.AuthScope)16 SSLContextBuilder (org.apache.http.ssl.SSLContextBuilder)16 HttpResponse (org.apache.http.HttpResponse)15 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)14 CredentialsProvider (org.apache.http.client.CredentialsProvider)14 HostnameVerifier (javax.net.ssl.HostnameVerifier)13 HttpClient (org.apache.http.client.HttpClient)12