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