Example usage for org.apache.http.conn ClientConnectionManagerFactory newInstance

List of usage examples for org.apache.http.conn ClientConnectionManagerFactory newInstance

Introduction

In this page you can find the example usage for org.apache.http.conn ClientConnectionManagerFactory newInstance.

Prototype

ClientConnectionManager newInstance(HttpParams params, SchemeRegistry schemeRegistry);

Source Link

Usage

From source file:org.vietspider.net.client.impl.AnonymousHttpClient.java

@Override
protected ClientConnectionManager createClientConnectionManager() {
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

    ClientConnectionManager connManager = null;
    HttpParams params = getParams();//w  w w  . ja  v  a2  s.  co  m

    ClientConnectionManagerFactory factory = null;

    // Try first getting the factory directly as an object.
    factory = (ClientConnectionManagerFactory) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY);
    if (factory == null) { // then try getting its class name.
        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(getParams(), registry);
    }

    return connManager;
}

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 {//w w w .j  a v a  2  s .c  om
            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 w  ww  .j a va2 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;
}