use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project openolat by klemens.
the class HttpClientFactory method getHttpClientInstance.
/**
* @param host For basic authentication
* @param port For basic authentication
* @param user For basic authentication
* @param password For basic authentication
* @param redirect If redirect is allowed
* @return CloseableHttpClient
*/
public static CloseableHttpClient getHttpClientInstance(String host, int port, String user, String password, boolean redirect) {
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(socketRegistry);
SocketConfig.Builder socketConfigBuilder = SocketConfig.copy(SocketConfig.DEFAULT);
socketConfigBuilder.setSoTimeout(10000);
cm.setDefaultSocketConfig(socketConfigBuilder.build());
HttpClientBuilder clientBuilder = HttpClientBuilder.create().setConnectionManager(cm).setMaxConnTotal(10).setDefaultCookieStore(new BasicCookieStore());
if (redirect) {
clientBuilder.setRedirectStrategy(new LaxRedirectStrategy());
} else {
clientBuilder.setRedirectStrategy(new NoRedirectStrategy());
}
if (user != null && user.length() > 0) {
CredentialsProvider provider = new BasicCredentialsProvider();
provider.setCredentials(new AuthScope(host, port), new UsernamePasswordCredentials(user, password));
clientBuilder.setDefaultCredentialsProvider(provider);
}
return clientBuilder.build();
}
use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project Openfire by igniterealtime.
the class FaviconServlet method init.
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
// Create a pool of HTTP connections to use to get the favicons
client = HttpClientBuilder.create().setConnectionManager(new PoolingHttpClientConnectionManager()).setRedirectStrategy(new LaxRedirectStrategy()).build();
// Load the default favicon to use when no favicon was found of a remote host
try {
defaultBytes = Files.readAllBytes(Paths.get(JiveGlobals.getHomeDirectory(), "plugins/admin/webapp/images/server_16x16.gif"));
} catch (final IOException e) {
LOGGER.warn("Unable to retrieve default favicon", e);
}
// Initialize caches.
missesCache = CacheFactory.createCache("Favicon Misses");
hitsCache = CacheFactory.createCache("Favicon Hits");
}
use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project oxTrust by GluuFederation.
the class UmaPermissionService method init.
public void init(@Observes @ApplicationInitialized(ApplicationScoped.class) ApplicationInitializedEvent init) {
try {
if (this.umaMetadata != null) {
if (appConfiguration.isRptConnectionPoolUseConnectionPooling()) {
// For more information about PoolingHttpClientConnectionManager, please see:
// http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/index.html?org/apache/http/impl/conn/PoolingHttpClientConnectionManager.html
log.debug("##### Initializing custom ClientExecutor...");
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(appConfiguration.getRptConnectionPoolMaxTotal());
connectionManager.setDefaultMaxPerRoute(appConfiguration.getRptConnectionPoolDefaultMaxPerRoute());
connectionManager.setValidateAfterInactivity(appConfiguration.getRptConnectionPoolValidateAfterInactivity() * 1000);
CloseableHttpClient client = HttpClients.custom().setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build()).setKeepAliveStrategy(connectionKeepAliveStrategy).setConnectionManager(connectionManager).build();
ApacheHttpClient43Engine engine = new ApacheHttpClient43Engine(client);
engine.setFollowRedirects(true);
this.clientHttpEngine = engine;
log.info("##### Initializing custom ClientExecutor DONE");
this.permissionService = UmaClientFactory.instance().createPermissionService(this.umaMetadata, clientHttpEngine);
this.rptStatusService = UmaClientFactory.instance().createRptStatusService(this.umaMetadata, clientHttpEngine);
} else {
this.permissionService = UmaClientFactory.instance().createPermissionService(this.umaMetadata);
this.rptStatusService = UmaClientFactory.instance().createRptStatusService(this.umaMetadata);
}
}
} catch (Exception ex) {
log.error("Failed to initialize UmaPermissionService", ex);
}
}
use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project oxTrust by GluuFederation.
the class ShibbolethReloadService method create.
@PostConstruct
public void create() {
try {
log.info(">>>>> Initializing ShibbolethReloadService");
SSLContext sslContext = SSLContextBuilder.create().loadTrustMaterial(new TrustSelfSignedStrategy()).build();
HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;
SSLConnectionSocketFactory sslConnSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("https", sslConnSocketFactory).register("http", new PlainConnectionSocketFactory()).build();
PoolingHttpClientConnectionManager poolingHttpConnMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
poolingHttpConnMgr.setMaxTotal(HTTP_DEFAULT_MAX_TOTAL_CONNECTIONS);
poolingHttpConnMgr.setDefaultMaxPerRoute(HTTP_DEFAULT_MAX_CONN_PER_ROUTE);
this.connectionManager = poolingHttpConnMgr;
log.info(">>>> ShibbolethReloadService Initialization complete");
} catch (Exception e) {
this.connectionManager = null;
log.info("Could not initialize ShibbolethReloadService", e);
}
}
use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project metacat by Netflix.
the class DruidHttpClientConfig method httpClient.
/**
* Http client.
*
* @param connectorContext connector context
* @return HttpClient
*/
@Bean
public HttpClient httpClient(final ConnectorContext connectorContext) {
final int timeout = (int) TimeUtil.toTime(connectorContext.getConfiguration().getOrDefault(DruidConfigConstants.HTTP_TIMEOUT, "5s"), TimeUnit.SECONDS, TimeUnit.MILLISECONDS);
final int poolsize = Integer.parseInt(connectorContext.getConfiguration().getOrDefault(DruidConfigConstants.POOL_SIZE, "10"));
final RequestConfig config = RequestConfig.custom().setConnectTimeout(timeout).setConnectionRequestTimeout(timeout).setSocketTimeout(timeout).setMaxRedirects(3).build();
final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(poolsize);
return HttpClientBuilder.create().setDefaultRequestConfig(config).setConnectionManager(connectionManager).build();
}
Aggregations