Search in sources :

Example 6 with ClientConnectionManager

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);
}
Also used : PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) ApacheHttpClient4Executor(org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) BeforeClass(org.testng.annotations.BeforeClass)

Example 7 with ClientConnectionManager

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();
    }
}
Also used : TrustStrategy(org.apache.http.conn.ssl.TrustStrategy) PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) Scheme(org.apache.http.conn.scheme.Scheme) AllowAllHostnameVerifier(org.apache.http.conn.ssl.AllowAllHostnameVerifier) CertificateException(java.security.cert.CertificateException) PlainSocketFactory(org.apache.http.conn.scheme.PlainSocketFactory) PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) X509Certificate(java.security.cert.X509Certificate) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) SslDefaultHttpClient(org.xdi.net.SslDefaultHttpClient) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory)

Example 8 with ClientConnectionManager

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;
    }
}
Also used : IOException(java.io.IOException) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) Socket(java.net.Socket)

Example 9 with ClientConnectionManager

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;
}
Also used : PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) Scheme(org.apache.http.conn.scheme.Scheme) X509TrustManager(javax.net.ssl.X509TrustManager) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) SecureRandom(java.security.SecureRandom) SSLContext(javax.net.ssl.SSLContext) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory) PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) IOException(java.io.IOException) UnexpectedException(play.exceptions.UnexpectedException) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 10 with ClientConnectionManager

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;
}
Also used : AbstractHttpClient(org.apache.http.impl.client.AbstractHttpClient) HttpParams(org.apache.http.params.HttpParams) ThreadSafeClientConnManager(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) SingleClientConnManager(org.apache.http.impl.conn.SingleClientConnManager) DefaultHttpRequestRetryHandler(org.apache.http.impl.client.DefaultHttpRequestRetryHandler) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Aggregations

ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)74 Scheme (org.apache.http.conn.scheme.Scheme)51 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)48 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)39 HttpParams (org.apache.http.params.HttpParams)37 SSLSocketFactory (org.apache.http.conn.ssl.SSLSocketFactory)35 BasicHttpParams (org.apache.http.params.BasicHttpParams)28 ThreadSafeClientConnManager (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)26 IOException (java.io.IOException)21 Test (org.junit.Test)15 CertificateException (java.security.cert.CertificateException)14 HttpClient (org.apache.http.client.HttpClient)14 KeyManagementException (java.security.KeyManagementException)13 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)13 SSLContext (javax.net.ssl.SSLContext)12 HttpResponse (org.apache.http.HttpResponse)11 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)11 KeyStoreException (java.security.KeyStoreException)10 PoolingClientConnectionManager (org.apache.http.impl.conn.PoolingClientConnectionManager)10 UnrecoverableKeyException (java.security.UnrecoverableKeyException)9