Search in sources :

Example 26 with PoolingClientConnectionManager

use of org.apache.http.impl.conn.PoolingClientConnectionManager in project oxCore by GluuFederation.

the class SslDefaultHttpClient method createClientConnectionManager.

@Override
protected ClientConnectionManager createClientConnectionManager() {
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    // Register for port 443 our SSLSocketFactory with our keystore to the
    // ConnectionManager
    registry.register(new Scheme("https", 443, newSslSocketFactory()));
    return new PoolingClientConnectionManager(registry);
}
Also used : PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) Scheme(org.apache.http.conn.scheme.Scheme) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry)

Example 27 with PoolingClientConnectionManager

use of org.apache.http.impl.conn.PoolingClientConnectionManager in project liferay-ide by liferay.

the class RemoteConnection method _getHttpClient.

private HttpClient _getHttpClient() {
    if (_httpClient != null) {
        return _httpClient;
    }
    DefaultHttpClient newDefaultHttpClient = null;
    if ((getUsername() != null) || (getPassword() != null)) {
        try {
            IProxyService proxyService = LiferayCore.getProxyService();
            URI uri = new URI("http://" + getHost() + ":" + getHttpPort());
            IProxyData[] proxyDataForHost = proxyService.select(uri);
            for (IProxyData data : proxyDataForHost) {
                if ((data.getHost() == null) || (data.getPort() == 0)) {
                    continue;
                }
                SchemeRegistry schemeRegistry = new SchemeRegistry();
                schemeRegistry.register(new Scheme("http", data.getPort(), PlainSocketFactory.getSocketFactory()));
                PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
                cm.setMaxTotal(200);
                cm.setDefaultMaxPerRoute(20);
                DefaultHttpClient newHttpClient = new DefaultHttpClient(cm);
                HttpHost proxy = new HttpHost(data.getHost(), data.getPort());
                newHttpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
                newDefaultHttpClient = newHttpClient;
                break;
            }
            if (newDefaultHttpClient == null) {
                uri = new URI("SOCKS://" + getHost() + ":" + getHttpPort());
                proxyDataForHost = proxyService.select(uri);
                for (IProxyData data : proxyDataForHost) {
                    if (data.getHost() == null) {
                        continue;
                    }
                    DefaultHttpClient newHttpClient = new DefaultHttpClient();
                    newHttpClient.getParams().setParameter("socks.host", data.getHost());
                    newHttpClient.getParams().setParameter("socks.port", data.getPort());
                    SchemeRegistry registry = newHttpClient.getConnectionManager().getSchemeRegistry();
                    Scheme scheme = new Scheme("socks", data.getPort(), PlainSocketFactory.getSocketFactory());
                    registry.register(scheme);
                    newDefaultHttpClient = newHttpClient;
                    break;
                }
            }
        } catch (URISyntaxException urise) {
            LiferayCore.logError("Unable to read proxy data", urise);
        }
        if (newDefaultHttpClient == null) {
            newDefaultHttpClient = new DefaultHttpClient();
        }
        _httpClient = newDefaultHttpClient;
    } else {
        _httpClient = new DefaultHttpClient();
    }
    return _httpClient;
}
Also used : PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) IProxyData(org.eclipse.core.net.proxy.IProxyData) Scheme(org.apache.http.conn.scheme.Scheme) HttpHost(org.apache.http.HttpHost) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) IProxyService(org.eclipse.core.net.proxy.IProxyService)

Example 28 with PoolingClientConnectionManager

use of org.apache.http.impl.conn.PoolingClientConnectionManager in project ovirt-engine-sdk-java by oVirt.

the class ConnectionBuilder42 method createHttpClient.

/**
 * Creates HttpClient
 */
@Override
protected HttpClient createHttpClient() {
    int port = getPort();
    Credentials credentials = null;
    AuthSchemeRegistry schemeRegistry = new AuthSchemeRegistry();
    AuthScope authScope = new AuthScope(getHost(), port, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME);
    // Create credentials:
    if (user != null && user.length() > 0) {
        schemeRegistry.register(AuthPolicy.BASIC, new BasicSchemeFactory());
        credentials = new UsernamePasswordCredentials(user, password);
    } else if (kerberos) {
        schemeRegistry.register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
        credentials = new Credentials() {

            @Override
            public Principal getUserPrincipal() {
                return null;
            }

            @Override
            public String getPassword() {
                return null;
            }
        };
    }
    // Create http client:
    DefaultHttpClient client = new DefaultHttpClient(new PoolingClientConnectionManager(createConnectionSocketFactoryRegistry()));
    client.setAuthSchemes(schemeRegistry);
    client.getCredentialsProvider().setCredentials(authScope, credentials);
    client.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES);
    // Set request timeout:
    if (timeout != -1) {
        HttpConnectionParams.setSoTimeout(client.getParams(), timeout);
    }
    // Compress/decompress entities if compressing enabled:
    if (compress) {
        return new HttpClient42(new DecompressingHttpClient(client));
    }
    return new HttpClient42(client);
}
Also used : PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) BasicSchemeFactory(org.apache.http.impl.auth.BasicSchemeFactory) AuthSchemeRegistry(org.apache.http.auth.AuthSchemeRegistry) AuthScope(org.apache.http.auth.AuthScope) SPNegoSchemeFactory(org.apache.http.impl.auth.SPNegoSchemeFactory) DecompressingHttpClient(org.apache.http.impl.client.DecompressingHttpClient) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 29 with PoolingClientConnectionManager

use of org.apache.http.impl.conn.PoolingClientConnectionManager in project wildfly by wildfly.

the class BeanValidationCdiIntegrationTestCase method testValidRequest.

@Test
public void testValidRequest() throws Exception {
    DefaultHttpClient client = new DefaultHttpClient(new PoolingClientConnectionManager());
    HttpGet get = new HttpGet(url + "myjaxrs/order/5");
    HttpResponse result = client.execute(get);
    Assert.assertEquals(200, result.getStatusLine().getStatusCode());
    Assert.assertEquals("OrderModel{id=5}", EntityUtils.toString(result.getEntity()));
}
Also used : PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) Test(org.junit.Test)

Example 30 with PoolingClientConnectionManager

use of org.apache.http.impl.conn.PoolingClientConnectionManager in project wildfly by wildfly.

the class BeanValidationCdiIntegrationTestCase method testInvalidRequest.

@Test
public void testInvalidRequest() throws Exception {
    DefaultHttpClient client = new DefaultHttpClient(new PoolingClientConnectionManager());
    HttpGet get = new HttpGet(url + "myjaxrs/order/11");
    HttpResponse result = client.execute(get);
    result = client.execute(get);
    Assert.assertEquals("Parameter constraint violated", 400, result.getStatusLine().getStatusCode());
}
Also used : PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) Test(org.junit.Test)

Aggregations

PoolingClientConnectionManager (org.apache.http.impl.conn.PoolingClientConnectionManager)30 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)24 Scheme (org.apache.http.conn.scheme.Scheme)12 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)11 HttpResponse (org.apache.http.HttpResponse)10 HttpGet (org.apache.http.client.methods.HttpGet)10 Test (org.junit.Test)10 ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)9 SSLSocketFactory (org.apache.http.conn.ssl.SSLSocketFactory)9 IOException (java.io.IOException)7 CertificateException (java.security.cert.CertificateException)5 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)5 TrustStrategy (org.apache.http.conn.ssl.TrustStrategy)5 X509Certificate (java.security.cert.X509Certificate)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)3 SSLContext (javax.net.ssl.SSLContext)3 HttpHost (org.apache.http.HttpHost)3 Credentials (org.apache.http.auth.Credentials)3