Search in sources :

Example 56 with PoolingHttpClientConnectionManager

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;
}
Also used : HttpClient(org.apache.http.client.HttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Example 57 with PoolingHttpClientConnectionManager

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);
}
Also used : PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Example 58 with PoolingHttpClientConnectionManager

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);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) AuthCache(org.apache.http.client.AuthCache) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) SPNegoSchemeFactory(org.apache.http.impl.auth.SPNegoSchemeFactory) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) HttpHost(org.apache.http.HttpHost) AuthSchemeProvider(org.apache.http.auth.AuthSchemeProvider) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) HttpClientConnectionManager(org.apache.http.conn.HttpClientConnectionManager) Pair(org.apache.hadoop.hbase.util.Pair)

Example 59 with PoolingHttpClientConnectionManager

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));
}
Also used : GSSName(org.ietf.jgss.GSSName) KerberosTicket(javax.security.auth.kerberos.KerberosTicket) AvaticaCommonsHttpClientImpl(org.apache.calcite.avatica.remote.AvaticaCommonsHttpClientImpl) Oid(org.ietf.jgss.Oid) Properties(java.util.Properties) Subject(javax.security.auth.Subject) KrbException(org.apache.kerby.kerberos.kerb.KrbException) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) ConnectionConfigImpl(org.apache.calcite.avatica.ConnectionConfigImpl) GSSCredential(org.ietf.jgss.GSSCredential) GSSManager(org.ietf.jgss.GSSManager) Principal(java.security.Principal) ConnectionConfig(org.apache.calcite.avatica.ConnectionConfig) Test(org.junit.Test)

Example 60 with PoolingHttpClientConnectionManager

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();
    }
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) SocketConfig(org.apache.http.config.SocketConfig) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) Before(org.junit.Before)

Aggregations

PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)180 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)63 ConnectionSocketFactory (org.apache.http.conn.socket.ConnectionSocketFactory)62 PlainConnectionSocketFactory (org.apache.http.conn.socket.PlainConnectionSocketFactory)54 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)52 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)42 SSLContext (javax.net.ssl.SSLContext)36 RequestConfig (org.apache.http.client.config.RequestConfig)31 IOException (java.io.IOException)29 Test (org.junit.Test)27 HttpHost (org.apache.http.HttpHost)21 HttpGet (org.apache.http.client.methods.HttpGet)18 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)17 AuthScope (org.apache.http.auth.AuthScope)16 SSLContextBuilder (org.apache.http.ssl.SSLContextBuilder)16 HttpResponse (org.apache.http.HttpResponse)15 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)14 CredentialsProvider (org.apache.http.client.CredentialsProvider)14 HostnameVerifier (javax.net.ssl.HostnameVerifier)13 HttpClient (org.apache.http.client.HttpClient)12