use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project oxAuth by GluuFederation.
the class BaseTest method createClient.
private static HttpClient createClient(SSLConnectionSocketFactory connectionFactory) {
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
HttpClientBuilder httClientBuilder = HttpClients.custom();
if (connectionFactory != null) {
httClientBuilder = httClientBuilder.setSSLSocketFactory(connectionFactory);
}
HttpClient httpClient = httClientBuilder.setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build()).setConnectionManager(cm).build();
// Increase max total connection to 200
cm.setMaxTotal(200);
// Increase default max connection per route to 20
cm.setDefaultMaxPerRoute(20);
return httpClient;
}
use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project cdap-ingest by caskdata.
the class RestStreamClient method createWriter.
@Override
public StreamWriter createWriter(String stream) throws IOException {
// get the Stream TTL for check does the requested Stream exist
long ttl = getTTL(stream);
LOG.debug("The Stream with id {} exists. Got the current Stream TTL value {} successfully.", stream, ttl);
PoolingHttpClientConnectionManager connectionManager = createConnectionManager();
connectionManager.setMaxTotal(writerPoolSize);
connectionManager.setDefaultMaxPerRoute(writerPoolSize);
RestClient writerRestClient = new RestClient(config, connectionManager);
return new RestStreamWriter(writerRestClient, writerPoolSize, stream);
}
use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project hbase by apache.
the class TestSecureRESTServer method getClient.
private Pair<CloseableHttpClient, HttpClientContext> getClient() {
HttpClientConnectionManager pool = new PoolingHttpClientConnectionManager();
HttpHost host = new HttpHost("localhost", REST_TEST.getServletPort());
Registry<AuthSchemeProvider> authRegistry = RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true, true)).build();
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, EmptyCredentials.INSTANCE);
AuthCache authCache = new BasicAuthCache();
CloseableHttpClient client = HttpClients.custom().setDefaultAuthSchemeRegistry(authRegistry).setConnectionManager(pool).build();
HttpClientContext context = HttpClientContext.create();
context.setTargetHost(host);
context.setCredentialsProvider(credentialsProvider);
context.setAuthSchemeRegistry(authRegistry);
context.setAuthCache(authCache);
return new Pair<>(client, context);
}
use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project calcite-avatica by apache.
the class HttpServerSpnegoWithoutJaasTest method testAuthenticatedClientsAllowed.
@Test
public void testAuthenticatedClientsAllowed() throws Exception {
// Create the subject for the client
final Subject clientSubject = AvaticaJaasKrbUtil.loginUsingKeytab(SpnegoTestUtil.CLIENT_PRINCIPAL, clientKeytab);
final Set<Principal> clientPrincipals = clientSubject.getPrincipals();
// Make sure the subject has a principal
assertFalse(clientPrincipals.isEmpty());
// Get a TGT for the subject (might have many, different encryption types). The first should
// be the default encryption type.
Set<KerberosTicket> privateCredentials = clientSubject.getPrivateCredentials(KerberosTicket.class);
assertFalse(privateCredentials.isEmpty());
KerberosTicket tgt = privateCredentials.iterator().next();
assertNotNull(tgt);
LOG.info("Using TGT with etype: {}", tgt.getSessionKey().getAlgorithm());
// The name of the principal
final String principalName = clientPrincipals.iterator().next().getName();
// Run this code, logged in as the subject (the client)
byte[] response = Subject.doAs(clientSubject, new PrivilegedExceptionAction<byte[]>() {
@Override
public byte[] run() throws Exception {
// Logs in with Kerberos via GSS
GSSManager gssManager = GSSManager.getInstance();
Oid oid = new Oid(SpnegoTestUtil.JGSS_KERBEROS_TICKET_OID);
GSSName gssClient = gssManager.createName(principalName, GSSName.NT_USER_NAME);
GSSCredential credential = gssManager.createCredential(gssClient, GSSCredential.DEFAULT_LIFETIME, oid, GSSCredential.INITIATE_ONLY);
Properties props = new Properties();
ConnectionConfig config = new ConnectionConfigImpl(props);
PoolingHttpClientConnectionManager pool = CommonsHttpClientPoolCache.getPool(config);
// Passes the GSSCredential into the HTTP client implementation
final AvaticaCommonsHttpClientImpl httpClient = new AvaticaCommonsHttpClientImpl(httpServerUrl);
httpClient.setGSSCredential(credential);
httpClient.setHttpClientPool(pool);
return httpClient.send(new byte[0]);
}
});
// We should get a response which is "OK" with our client's name
assertNotNull(response);
assertEquals("OK " + SpnegoTestUtil.CLIENT_NAME, new String(response, StandardCharsets.UTF_8));
}
use of org.apache.http.impl.conn.PoolingHttpClientConnectionManager in project stanbol by apache.
the class MultiThreadedTestBase method initialiseHttpClient.
@Before
public void initialiseHttpClient() {
if (this.pooledHttpClient == null) {
// init for the first test
RequestConfig requestConfig = RequestConfig.custom().setRedirectsEnabled(true).setMaxRedirects(3).build();
SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(true).build();
connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setDefaultSocketConfig(socketConfig);
connectionManager.setMaxTotal(20);
connectionManager.setDefaultMaxPerRoute(20);
pooledHttpClient = HttpClientBuilder.create().setUserAgent("Stanbol Integration Test").setConnectionManager(connectionManager).setDefaultRequestConfig(requestConfig).build();
}
}
Aggregations