use of org.apache.http.conn.ClientConnectionManager in project oxAuth by GluuFederation.
the class UmaMultithreadTest method before.
@BeforeClass
public void before() {
ClientConnectionManager connectoinManager = new PoolingClientConnectionManager();
final DefaultHttpClient defaultHttpClient = new DefaultHttpClient(connectoinManager);
final ApacheHttpClient4Executor clientExecutor = new ApacheHttpClient4Executor(defaultHttpClient);
String url = serverUri + "/oxauth/seam/resource/restv1/oxauth/uma-configuration";
service = UmaClientFactory.instance().createMetaDataConfigurationService(url, clientExecutor);
}
use of org.apache.http.conn.ClientConnectionManager in project oxAuth by GluuFederation.
the class HttpService method getHttpsClientTrustAll.
public HttpClient getHttpsClientTrustAll() {
try {
SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
}, new AllowAllHostnameVerifier());
PlainSocketFactory psf = PlainSocketFactory.getSocketFactory();
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", 80, psf));
registry.register(new Scheme("https", 443, sf));
ClientConnectionManager ccm = new PoolingClientConnectionManager(registry);
return new DefaultHttpClient(ccm);
} catch (Exception ex) {
log.error("Failed to create TrustAll https client", ex);
return new DefaultHttpClient();
}
}
use of org.apache.http.conn.ClientConnectionManager in project XobotOS by xamarin.
the class SingleClientConnManager method releaseConnection.
// non-javadoc, see interface ClientConnectionManager
public void releaseConnection(ManagedClientConnection conn, long validDuration, TimeUnit timeUnit) {
assertStillUp();
if (!(conn instanceof ConnAdapter)) {
throw new IllegalArgumentException("Connection class mismatch, " + "connection not obtained from this manager.");
}
if (log.isDebugEnabled()) {
log.debug("Releasing connection " + conn);
}
ConnAdapter sca = (ConnAdapter) conn;
if (sca.poolEntry == null)
// already released
return;
ClientConnectionManager manager = sca.getManager();
if (manager != null && manager != this) {
throw new IllegalArgumentException("Connection not obtained from this manager.");
}
try {
// BEGIN android-changed
// When recycling a Socket, we un-tag it to avoid collecting
// statistics from future users.
final Socket socket = uniquePoolEntry.connection.getSocket();
if (socket != null) {
SocketTagger.get().untag(socket);
}
// make sure that the response has been read completely
if (sca.isOpen() && (this.alwaysShutDown || !sca.isMarkedReusable())) {
if (log.isDebugEnabled()) {
log.debug("Released connection open but not reusable.");
}
// make sure this connection will not be re-used
// we might have gotten here because of a shutdown trigger
// shutdown of the adapter also clears the tracked route
sca.shutdown();
}
} catch (IOException iox) {
//@@@ log as warning? let pass?
if (log.isDebugEnabled())
log.debug("Exception shutting down released connection.", iox);
} finally {
sca.detach();
managedConn = null;
lastReleaseTime = System.currentTimeMillis();
if (validDuration > 0)
connectionExpiresTime = timeUnit.toMillis(validDuration) + lastReleaseTime;
else
connectionExpiresTime = Long.MAX_VALUE;
}
}
use of org.apache.http.conn.ClientConnectionManager in project coprhd-controller by CoprHD.
the class RenderProxy method createClientConnectionManager.
private static ClientConnectionManager createClientConnectionManager() {
SchemeRegistry schemeRegistry = SchemeRegistryFactory.createDefault();
SSLSocketFactory sf;
if (StorageOsPlugin.isEnabled()) {
try {
// initialize an SSLContext with the vipr keystore and trustmanager.
// This is basically a dup of most of the ViPRSSLSocketFactory constructor,
// and could be extracted
X509TrustManager[] trustManagers = { BourneUtil.getTrustManager() };
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(BourneUtil.getKeyStore(), "".toCharArray());
SSLContext context = SSLContext.getInstance("TLS");
context.init(kmf.getKeyManagers(), trustManagers, new SecureRandom());
sf = new SSLSocketFactory(context, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
} catch (Exception e) {
throw new RuntimeException("Unable to initialize the ViPRX509TrustManager for RenderProxy", e);
}
} else {
sf = new SSLSocketFactory(SSLUtil.getTrustAllContext(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
}
Scheme httpsScheme = new Scheme("https", 443, sf);
schemeRegistry.register(httpsScheme);
ClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
return connectionManager;
}
use of org.apache.http.conn.ClientConnectionManager in project coprhd-controller by CoprHD.
the class BaseHttpClientFactory method createRawHTTPClient.
/**
* Create a HTTPClient using the factories configuration without Credentials
*
* @param useConnectionTimeout - allows override of the the default connectionTimeout
* @param useConnectionReadTimeout - allows override of the default connectionReadTimeout
* @throws AuthenticationException, GeneralSecurityException, RuntimeException
*/
protected AbstractHttpClient createRawHTTPClient(int useConnectionTimeout, int useConnectionReadTimeout) throws AuthenticationException, GeneralSecurityException, RuntimeException {
// select the appropriate connection manager and set options as appropriate
ClientConnectionManager cm = null;
if (threadSafeClients) {
ThreadSafeClientConnManager tscm = new ThreadSafeClientConnManager();
tscm.setMaxTotal(maxConnections);
tscm.setDefaultMaxPerRoute(maxConnectionsPerHost);
cm = tscm;
} else {
cm = new SingleClientConnManager();
}
// construct a client instance with the connection manager embedded
AbstractHttpClient httpClient = new DefaultHttpClient(cm);
if (relaxSSL) {
// !!!WARNING: This effectively turns off the authentication component of SSL, leaving only encryption
// can throw GeneralSecurityException
SSLHelper.configurePermissiveSSL(httpClient);
} else if (isSecureSSL()) {
SSLHelper.configureSSLWithTrustManger(httpClient, coordinator);
}
// see org.apache.http.client.params.AllClientPNames for a collected
// list of the available client parameters
HttpParams clientParams = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(clientParams, useConnectionTimeout);
HttpConnectionParams.setSoTimeout(clientParams, useConnectionReadTimeout);
// consider turning off the use of the Expect: 100-Continue response if
// your posts/puts tend to be relatively small
HttpProtocolParams.setUseExpectContinue(clientParams, false);
// TODO: reconsider this setting
// by default the client auto-retries on failures - turn that off so we can handle it manually
httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
return httpClient;
}
Aggregations