Search in sources :

Example 31 with HttpClientConnectionManager

use of org.apache.http.conn.HttpClientConnectionManager in project ats-framework by Axway.

the class RestClient method constructApacheConnectorInvocationBuilder.

private void constructApacheConnectorInvocationBuilder(String descriptionToken, boolean suppressHttpComplianceValidation) {
    // create the client config object
    ClientConfig clientConfig = createClientConfig(suppressHttpComplianceValidation);
    // check if user had specified custom connection manager and custom connection factory
    boolean hasConnectionManager = this.clientConfigurator.getConnectionManager() != null;
    boolean hasConnectionFactory = this.clientConfigurator.getConnectionFactory() != null;
    // handle HTTPS requests
    Registry registry = null;
    if (isHttps()) {
        // configure Trust-all SSL context
        if (!hasConnectionManager) {
        }
        registry = constructRegistry();
    }
    HttpClientConnectionManager connectionManager = null;
    HttpConnectionFactory connectionFactory = null;
    if (hasConnectionManager) {
        connectionManager = this.clientConfigurator.getConnectionManager();
        if (hasConnectionFactory) {
            connectionFactory = this.clientConfigurator.getConnectionFactory();
        } else {
            throw new RuntimeException("Connection manager was specified, but connection factory was not. " + "Provide both if you want to use custom connection manager");
        }
    } else {
        if (hasConnectionFactory) {
            connectionFactory = this.clientConfigurator.getConnectionFactory();
        } else {
            connectionFactory = new ManagedHttpClientConnectionFactory();
        }
        if (registry != null) {
            if (usePooling) {
                connectionManager = new PoolingHttpClientConnectionManager(registry, connectionFactory);
            } else {
                connectionManager = new BasicHttpClientConnectionManager(registry, connectionFactory);
            }
        } else {
            if (usePooling) {
                connectionManager = new PoolingHttpClientConnectionManager(connectionFactory);
            } else {
                connectionManager = new BasicHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", SSLConnectionSocketFactory.getSocketFactory()).build(), connectionFactory);
            }
        }
    }
    if (connectionManager != null && connectionManager instanceof PoolingHttpClientConnectionManager) {
        // 10 sec
        ((PoolingHttpClientConnectionManager) connectionManager).setValidateAfterInactivity(10 * 1000);
    }
    try {
        Class<?> apacheClientProperties = Class.forName(RestClient.APACHE_CLIENT_PROPERTIES_CLASSNAME);
        clientConfig.property((String) apacheClientProperties.getDeclaredField("CONNECTION_MANAGER").get(null), connectionManager);
    } catch (Exception e) {
        throw new RuntimeException("Could not set validity timeinterval for '" + connectionManager.getClass().getName() + "'", e);
    }
    // create the client builder
    ClientBuilder clientBuilder = ClientBuilder.newBuilder().withConfig(clientConfig);
    // now create the client
    createClient(clientBuilder);
    createInvocationBuilder(descriptionToken);
}
Also used : HttpConnectionFactory(org.apache.http.conn.HttpConnectionFactory) ManagedHttpClientConnectionFactory(org.apache.http.impl.conn.ManagedHttpClientConnectionFactory) Registry(org.apache.http.config.Registry) ClientConfig(org.glassfish.jersey.client.ClientConfig) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) HttpClientConnectionManager(org.apache.http.conn.HttpClientConnectionManager) BasicHttpClientConnectionManager(org.apache.http.impl.conn.BasicHttpClientConnectionManager) BasicHttpClientConnectionManager(org.apache.http.impl.conn.BasicHttpClientConnectionManager) RestException(com.axway.ats.action.exceptions.RestException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) ClientBuilder(javax.ws.rs.client.ClientBuilder)

Example 32 with HttpClientConnectionManager

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

the class DruidJerseyClient method connect.

@Override
public void connect() throws ConnectionException {
    try {
        if (jerseyConfig == null) {
            HttpClientConnectionManager connectionManager = createConnectionManager();
            this.jerseyConfig = new ClientConfig();
            this.jerseyConfig.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager);
            this.jerseyConfig.connectorProvider(new ApacheConnectorProvider());
        }
        this.client = ClientBuilder.newClient(this.jerseyConfig);
        this.queryWebTarget = this.client.target(this.druidUrl);
    } catch (Exception e) {
        throw new ConnectionException(e);
    }
}
Also used : ApacheConnectorProvider(org.glassfish.jersey.apache.connector.ApacheConnectorProvider) HttpClientConnectionManager(org.apache.http.conn.HttpClientConnectionManager) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) ClientConfig(org.glassfish.jersey.client.ClientConfig) ConnectionException(in.zapr.druid.druidry.client.exception.ConnectionException) QueryException(in.zapr.druid.druidry.client.exception.QueryException) ConnectionException(in.zapr.druid.druidry.client.exception.ConnectionException)

Example 33 with HttpClientConnectionManager

use of org.apache.http.conn.HttpClientConnectionManager in project codeforces-commons by Codeforces.

the class HttpClientUtil method internalNewHttpClient.

private static CloseableHttpClient internalNewHttpClient(int connectionTimeoutMillis, int socketTimeoutMillis, HttpClientConnectionManagerBuilder connectionManagerBuilder) {
    SocketConfig socketConfig = getSocketConfig(socketTimeoutMillis);
    RequestConfig requestConfig = getRequestConfig(connectionTimeoutMillis, socketTimeoutMillis);
    HttpClientConnectionManager connectionManager = connectionManagerBuilder.build(socketConfig);
    return internalNewHttpClient(socketConfig, requestConfig, connectionManager);
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) SocketConfig(org.apache.http.config.SocketConfig) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) HttpClientConnectionManager(org.apache.http.conn.HttpClientConnectionManager) BasicHttpClientConnectionManager(org.apache.http.impl.conn.BasicHttpClientConnectionManager)

Example 34 with HttpClientConnectionManager

use of org.apache.http.conn.HttpClientConnectionManager in project codeforces-commons by Codeforces.

the class HttpClientUtil method internalNewHttpClient.

private static CloseableHttpClient internalNewHttpClient(HttpClientConnectionManagerBuilder connectionManagerBuilder) {
    SocketConfig socketConfig = getSocketConfig();
    RequestConfig requestConfig = getRequestConfig();
    HttpClientConnectionManager connectionManager = connectionManagerBuilder.build(socketConfig);
    return internalNewHttpClient(socketConfig, requestConfig, connectionManager);
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) SocketConfig(org.apache.http.config.SocketConfig) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) HttpClientConnectionManager(org.apache.http.conn.HttpClientConnectionManager) BasicHttpClientConnectionManager(org.apache.http.impl.conn.BasicHttpClientConnectionManager)

Example 35 with HttpClientConnectionManager

use of org.apache.http.conn.HttpClientConnectionManager in project scout.rt by eclipse.

the class ApacheHttpTransportFactory method newHttpTransport.

@Override
public HttpTransport newHttpTransport(IHttpTransportManager manager) {
    HttpClientBuilder builder = HttpClients.custom();
    installConfigurableProxySelector(builder);
    installMultiSessionCookieStore(builder);
    setConnectionKeepAliveAndRetrySettings(builder);
    HttpClientConnectionManager cm = getConfiguredConnectionManager();
    if (cm != null) {
        builder.setConnectionManager(cm);
    }
    interceptNewHttpTransport(builder, manager);
    manager.interceptNewHttpTransport(new ApacheHttpTransportBuilder(builder, cm));
    return new ApacheHttpTransport(builder.build());
}
Also used : HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) HttpClientConnectionManager(org.apache.http.conn.HttpClientConnectionManager) ApacheHttpTransport(org.eclipse.scout.rt.shared.http.transport.ApacheHttpTransport)

Aggregations

HttpClientConnectionManager (org.apache.http.conn.HttpClientConnectionManager)35 BasicHttpClientConnectionManager (org.apache.http.impl.conn.BasicHttpClientConnectionManager)23 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)19 IOException (java.io.IOException)16 HttpResponse (org.apache.http.HttpResponse)14 HttpClient (org.apache.http.client.HttpClient)11 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)11 ConnectionSocketFactory (org.apache.http.conn.socket.ConnectionSocketFactory)9 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)9 SSLContext (javax.net.ssl.SSLContext)8 RequestConfig (org.apache.http.client.config.RequestConfig)8 CertificateException (java.security.cert.CertificateException)7 HttpGet (org.apache.http.client.methods.HttpGet)6 HttpPost (org.apache.http.client.methods.HttpPost)6 PlainConnectionSocketFactory (org.apache.http.conn.socket.PlainConnectionSocketFactory)5 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)5 KeyManagementException (java.security.KeyManagementException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)4 NoopHostnameVerifier (org.apache.http.conn.ssl.NoopHostnameVerifier)4