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