Search in sources :

Example 1 with HttpConnectionFactory

use of org.apache.http.conn.HttpConnectionFactory 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)

Aggregations

RestException (com.axway.ats.action.exceptions.RestException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 CertificateException (java.security.cert.CertificateException)1 ClientBuilder (javax.ws.rs.client.ClientBuilder)1 Registry (org.apache.http.config.Registry)1 HttpClientConnectionManager (org.apache.http.conn.HttpClientConnectionManager)1 HttpConnectionFactory (org.apache.http.conn.HttpConnectionFactory)1 BasicHttpClientConnectionManager (org.apache.http.impl.conn.BasicHttpClientConnectionManager)1 ManagedHttpClientConnectionFactory (org.apache.http.impl.conn.ManagedHttpClientConnectionFactory)1 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)1 ClientConfig (org.glassfish.jersey.client.ClientConfig)1