Example usage for org.apache.http.impl.conn SchemeRegistryFactory createDefault

List of usage examples for org.apache.http.impl.conn SchemeRegistryFactory createDefault

Introduction

In this page you can find the example usage for org.apache.http.impl.conn SchemeRegistryFactory createDefault.

Prototype

public static SchemeRegistry createDefault() 

Source Link

Document

Initializes default scheme registry based on JSSE defaults.

Usage

From source file:it.staiger.jmeter.protocol.http.sampler.HTTPHC4DynamicFilePost.java

private HttpClient setupClient(URL url, SampleResult res) {

    Map<HttpClientKey, HttpClient> mapHttpClientPerHttpClientKey = HTTPCLIENTS_CACHE_PER_THREAD_AND_HTTPCLIENTKEY
            .get();/*from   w  ww . java  2 s .  co  m*/

    final String host = url.getHost();
    final String proxyHost = getProxyHost();
    final int proxyPort = getProxyPortInt();

    boolean useStaticProxy = isStaticProxy(host);
    boolean useDynamicProxy = isDynamicProxy(proxyHost, proxyPort);

    // Lookup key - must agree with all the values used to create the HttpClient.
    HttpClientKey key = new HttpClientKey(url, (useStaticProxy || useDynamicProxy),
            useDynamicProxy ? proxyHost : PROXY_HOST, useDynamicProxy ? proxyPort : PROXY_PORT,
            useDynamicProxy ? getProxyUser() : PROXY_USER, useDynamicProxy ? getProxyPass() : PROXY_PASS);

    HttpClient httpClient = mapHttpClientPerHttpClientKey.get(key);

    if (httpClient != null && resetSSLContext
            && HTTPConstants.PROTOCOL_HTTPS.equalsIgnoreCase(url.getProtocol())) {
        ((AbstractHttpClient) httpClient).clearRequestInterceptors();
        ((AbstractHttpClient) httpClient).clearResponseInterceptors();
        httpClient.getConnectionManager().closeIdleConnections(1L, TimeUnit.MICROSECONDS);
        httpClient = null;
        JsseSSLManager sslMgr = (JsseSSLManager) SSLManager.getInstance();
        sslMgr.resetContext();
        resetSSLContext = false;
    }

    if (httpClient == null) { // One-time init for this client

        HttpParams clientParams = new DefaultedHttpParams(new BasicHttpParams(), DEFAULT_HTTP_PARAMS);

        DnsResolver resolver = this.testElement.getDNSResolver();
        if (resolver == null) {
            resolver = new SystemDefaultDnsResolver();
        }
        ClientConnectionManager connManager = new MeasuringConnectionManager(
                SchemeRegistryFactory.createDefault(), resolver);

        httpClient = new DefaultHttpClient(connManager, clientParams) {
            @Override
            protected HttpRequestRetryHandler createHttpRequestRetryHandler() {
                return new DefaultHttpRequestRetryHandler(RETRY_COUNT, false); // set retry count
            }
        };
        if (IDLE_TIMEOUT > 0) {
            ((AbstractHttpClient) httpClient).setKeepAliveStrategy(IDLE_STRATEGY);
        }
        ((AbstractHttpClient) httpClient).addResponseInterceptor(new ResponseContentEncoding());
        ((AbstractHttpClient) httpClient).addResponseInterceptor(METRICS_SAVER); // HACK
        ((AbstractHttpClient) httpClient).addRequestInterceptor(METRICS_RESETTER);

        // Override the defualt schemes as necessary
        SchemeRegistry schemeRegistry = httpClient.getConnectionManager().getSchemeRegistry();

        if (SLOW_HTTP != null) {
            schemeRegistry.register(SLOW_HTTP);
        }

        if (HTTPS_SCHEME != null) {
            schemeRegistry.register(HTTPS_SCHEME);
        }

        // Set up proxy details
        if (useDynamicProxy) {
            HttpHost proxy = new HttpHost(proxyHost, proxyPort);
            clientParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
            String proxyUser = getProxyUser();

            if (proxyUser.length() > 0) {
                ((AbstractHttpClient) httpClient).getCredentialsProvider().setCredentials(
                        new AuthScope(proxyHost, proxyPort),
                        new NTCredentials(proxyUser, getProxyPass(), localHost, PROXY_DOMAIN));
            }
        } else if (useStaticProxy) {
            HttpHost proxy = new HttpHost(PROXY_HOST, PROXY_PORT);
            clientParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
            if (PROXY_USER.length() > 0) {
                ((AbstractHttpClient) httpClient).getCredentialsProvider().setCredentials(
                        new AuthScope(PROXY_HOST, PROXY_PORT),
                        new NTCredentials(PROXY_USER, PROXY_PASS, localHost, PROXY_DOMAIN));
            }
        }

        // Bug 52126 - we do our own cookie handling
        clientParams.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES);

        if (log.isDebugEnabled()) {
            log.debug("Created new HttpClient: @" + System.identityHashCode(httpClient) + " " + key.toString());
        }

        mapHttpClientPerHttpClientKey.put(key, httpClient); // save the agent for next time round
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Reusing the HttpClient: @" + System.identityHashCode(httpClient) + " " + key.toString());
        }
    }

    MeasuringConnectionManager connectionManager = (MeasuringConnectionManager) httpClient
            .getConnectionManager();
    connectionManager.setSample(res);

    // TODO - should this be done when the client is created?
    // If so, then the details need to be added as part of HttpClientKey
    setConnectionAuthorization(httpClient, url, getAuthManager(), key);

    return httpClient;
}

From source file:org.apache.http.impl.client.AbstractHttpClient.java

protected ClientConnectionManager createClientConnectionManager() {
    final SchemeRegistry registry = SchemeRegistryFactory.createDefault();

    ClientConnectionManager connManager = null;
    final HttpParams params = getParams();

    ClientConnectionManagerFactory factory = null;

    final String className = (String) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME);
    if (className != null) {
        try {//from  w w  w.j  a  va  2s .com
            final Class<?> clazz = Class.forName(className);
            factory = (ClientConnectionManagerFactory) clazz.newInstance();
        } catch (final ClassNotFoundException ex) {
            throw new IllegalStateException("Invalid class name: " + className);
        } catch (final IllegalAccessException ex) {
            throw new IllegalAccessError(ex.getMessage());
        } catch (final InstantiationException ex) {
            throw new InstantiationError(ex.getMessage());
        }
    }
    if (factory != null) {
        connManager = factory.newInstance(params, registry);
    } else {
        connManager = new BasicClientConnectionManager(registry);
    }

    return connManager;
}

From source file:org.apache.http.impl.client.AbstractStatisticsGatheringHttpClient.java

protected ClientConnectionManager createClientConnectionManager() {
    SchemeRegistry registry = SchemeRegistryFactory.createDefault();

    ClientConnectionManager connManager = null;
    HttpParams params = getParams();//from   ww w  .j  a  v a2 s. c o m

    ClientConnectionManagerFactory factory = null;

    String className = (String) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME);
    if (className != null) {
        try {
            Class<?> clazz = Class.forName(className);
            factory = (ClientConnectionManagerFactory) clazz.newInstance();
        } catch (ClassNotFoundException ex) {
            throw new IllegalStateException("Invalid class name: " + className);
        } catch (IllegalAccessException ex) {
            throw new IllegalAccessError(ex.getMessage());
        } catch (InstantiationException ex) {
            throw new InstantiationError(ex.getMessage());
        }
    }
    if (factory != null) {
        connManager = factory.newInstance(params, registry);
    } else {
        connManager = new SingleClientConnManager(registry);
    }

    return connManager;
}

From source file:org.apache.http.impl.conn.BasicClientConnectionManager.java

public BasicClientConnectionManager() {
    this(SchemeRegistryFactory.createDefault());
}

From source file:org.apache.http.impl.conn.ConnPoolBench.java

public static void newPool(int c, long reps) throws Exception {
    Log log = LogFactory.getLog(ConnPoolBench.class);

    DefaultClientConnectionOperator connOperator = new DefaultClientConnectionOperator(
            SchemeRegistryFactory.createDefault());
    HttpConnPool pool = new HttpConnPool(log, connOperator, c, c * 10, -1, TimeUnit.MILLISECONDS);

    WorkerThread1[] workers = new WorkerThread1[c];
    for (int i = 0; i < workers.length; i++) {
        workers[i] = new WorkerThread1(pool, reps);
    }//from www .j  a v  a2 s .c om
    long start = System.currentTimeMillis();
    for (int i = 0; i < workers.length; i++) {
        workers[i].start();
    }
    for (int i = 0; i < workers.length; i++) {
        workers[i].join();
    }
    long finish = System.currentTimeMillis();
    float totalTimeSec = (float) (finish - start) / 1000;
    System.out.print("Concurrency level:\t");
    System.out.println(c);
    System.out.print("Total operations:\t");
    System.out.println(c * reps);
    System.out.print("Time taken for tests:\t");
    System.out.print(totalTimeSec);
    System.out.println(" seconds");
}

From source file:org.apache.http.impl.conn.ConnPoolBench.java

static void oldPool(int c, long reps) throws Exception {
    ClientConnectionOperator operator = new DefaultClientConnectionOperator(
            SchemeRegistryFactory.createDefault());
    ConnPerRoute connPerRoute = new ConnPerRouteBean(c);
    ConnPoolByRoute pool = new ConnPoolByRoute(operator, connPerRoute, c * 10);

    WorkerThread2[] workers = new WorkerThread2[c];
    for (int i = 0; i < workers.length; i++) {
        workers[i] = new WorkerThread2(pool, reps);
    }//from   www. ja  v a2s. c  o  m
    long start = System.currentTimeMillis();
    for (int i = 0; i < workers.length; i++) {
        workers[i].start();
    }
    for (int i = 0; i < workers.length; i++) {
        workers[i].join();
    }
    long finish = System.currentTimeMillis();
    float totalTimeSec = (float) (finish - start) / 1000;
    System.out.print("Concurrency level:\t");
    System.out.println(c);
    System.out.print("Total operations:\t");
    System.out.println(c * reps);
    System.out.print("Time taken for tests:\t");
    System.out.print(totalTimeSec);
    System.out.println(" seconds");
}

From source file:org.apache.http.impl.conn.FixedPoolingClientConnectionManager.java

public FixedPoolingClientConnectionManager() {
    this(SchemeRegistryFactory.createDefault());
}

From source file:org.apache.http.impl.conn.JMeterPoolingClientConnectionManager.java

public JMeterPoolingClientConnectionManager() {
    this(SchemeRegistryFactory.createDefault());
}

From source file:org.apache.http.impl.conn.PoolingClientConnectionManager.java

public PoolingClientConnectionManager() {
    this(SchemeRegistryFactory.createDefault());
}

From source file:org.apache.http.impl.conn.SingleClientConnManager.java

/**
 * @since 4.1
 */
public SingleClientConnManager() {
    this(SchemeRegistryFactory.createDefault());
}