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);
}
Aggregations