Example usage for org.apache.http.impl.conn PoolingClientConnectionManager setDefaultMaxPerRoute

List of usage examples for org.apache.http.impl.conn PoolingClientConnectionManager setDefaultMaxPerRoute

Introduction

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

Prototype

public void setDefaultMaxPerRoute(final int max) 

Source Link

Usage

From source file:org.graphity.core.util.jena.HttpOp.java

/** Create an HttpClient that performs connection pooling.  This can be used
 * with {@link #setDefaultHttpClient} or provided in the HttpOp calls.
 *//*from  ww  w .jav a2  s  .co  m*/
public static HttpClient createCachingHttpClient() {
    return new SystemDefaultHttpClient() {
        /** See SystemDefaultHttpClient (4.2).  This version always sets the connection cache */
        @Override
        protected ClientConnectionManager createClientConnectionManager() {
            PoolingClientConnectionManager connmgr = new PoolingClientConnectionManager(
                    SchemeRegistryFactory.createSystemDefault());
            String s = System.getProperty("http.maxConnections", "5");
            int max = Integer.parseInt(s);
            connmgr.setDefaultMaxPerRoute(max);
            connmgr.setMaxTotal(2 * max);
            return connmgr;
        }
    };
}

From source file:gov.nrel.bacnet.consumer.DatabusSender.java

public DatabusSender(String username, String key, ExecutorService recorderSvc, String host, int port,
        boolean isSecure) {
    log.info("username=" + username + " key=" + key + " port=" + port);
    this.port = port;

    PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
    mgr.setDefaultMaxPerRoute(30);
    mgr.setMaxTotal(30);//w  w w . ja  v  a2 s . c  om
    this.username = username;
    this.key = key;
    this.host = host;
    this.port = port;
    this.mode = "https";

    if (!isSecure)
        mode = "http";
    this.hostUrl = mode + "://" + host + ":" + port;
    if (isSecure) {
        httpclient = createSecureOne(mgr);
    } else {
        httpclient = new DefaultHttpClient(mgr);
    }
    HttpParams params = httpclient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, 60000);
    HttpConnectionParams.setSoTimeout(params, 60000);
    log.info("hostUrl=" + hostUrl);
}

From source file:org.springframework.remoting.httpinvoker.HttpComponentsHttpInvokerRequestExecutor.java

/**
 * Create a new instance of the HttpComponentsHttpInvokerRequestExecutor with a default
 * {@link HttpClient} that uses a default {@link org.apache.http.impl.conn.PoolingClientConnectionManager}.
 *//*from   w w w.  j  a  v a  2 s  . c  o m*/
public HttpComponentsHttpInvokerRequestExecutor() {
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));

    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
    connectionManager.setMaxTotal(DEFAULT_MAX_TOTAL_CONNECTIONS);
    connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_CONNECTIONS_PER_ROUTE);

    this.httpClient = new DefaultHttpClient(connectionManager);
    setReadTimeout(DEFAULT_READ_TIMEOUT_MILLISECONDS);
}

From source file:spring.test.web.HttpComponentsHttpInvokerRequestExecutor.java

/**
* Create a new instance of the HttpComponentsHttpInvokerRequestExecutor with a default
* {@link HttpClient} that uses a default {@link org.apache.http.impl.conn.PoolingClientConnectionManager}.
*///w  ww  .  j av  a  2  s  . com
public HttpComponentsHttpInvokerRequestExecutor() {
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));

    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
    connectionManager.setMaxTotal(DEFAULT_MAX_TOTAL_CONNECTIONS);
    connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_CONNECTIONS_PER_ROUTE);
    this.httpClient = new DefaultHttpClient(connectionManager);
    setReadTimeout(DEFAULT_READ_TIMEOUT_MILLISECONDS);
}

From source file:com.autonomy.aci.client.transport.impl.HttpClientFactory.java

/**
 * Creates an instance of <tt>DefaultHttpClient</tt> with a <tt>ThreadSafeClientConnManager</tt>.
 * @return an implementation of the <tt>HttpClient</tt> interface.
 *///from   w  w  w  .jav  a 2  s  . c  o m
public HttpClient createInstance() {
    LOGGER.debug("Creating a new instance of DefaultHttpClient with configuration -> {}", toString());

    // Create the connection manager which will be default create the necessary schema registry stuff...
    final PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
    connectionManager.setMaxTotal(maxTotalConnections);
    connectionManager.setDefaultMaxPerRoute(maxConnectionsPerRoute);

    // Set the HTTP connection parameters (These are in the HttpCore JavaDocs, NOT the HttpClient ones)...
    final HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, connectionTimeout);
    HttpConnectionParams.setLinger(params, linger);
    HttpConnectionParams.setSocketBufferSize(params, socketBufferSize);
    HttpConnectionParams.setSoKeepalive(params, soKeepAlive);
    HttpConnectionParams.setSoReuseaddr(params, soReuseAddr);
    HttpConnectionParams.setSoTimeout(params, soTimeout);
    HttpConnectionParams.setStaleCheckingEnabled(params, staleCheckingEnabled);
    HttpConnectionParams.setTcpNoDelay(params, tcpNoDelay);

    // Create the HttpClient and configure the compression interceptors if required...
    final DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager, params);

    if (useCompression) {
        httpClient.addRequestInterceptor(new RequestAcceptEncoding());
        httpClient.addResponseInterceptor(new DeflateContentEncoding());
    }

    return httpClient;
}

From source file:ch.cyberduck.core.http.HttpSession.java

protected AbstractHttpClient http(final String hostname) {
    if (!clients.containsKey(hostname)) {
        final HttpParams params = new BasicHttpParams();

        HttpProtocolParams.setVersion(params, org.apache.http.HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, getEncoding());
        HttpProtocolParams.setUserAgent(params, getUserAgent());

        AuthParams.setCredentialCharset(params, Preferences.instance().getProperty("http.credentials.charset"));

        HttpConnectionParams.setTcpNoDelay(params, true);
        HttpConnectionParams.setSoTimeout(params, timeout());
        HttpConnectionParams.setConnectionTimeout(params, timeout());
        HttpConnectionParams.setSocketBufferSize(params,
                Preferences.instance().getInteger("http.socket.buffer"));
        HttpConnectionParams.setStaleCheckingEnabled(params, true);

        HttpClientParams.setRedirecting(params, true);
        HttpClientParams.setAuthenticating(params, true);
        HttpClientParams.setCookiePolicy(params, CookiePolicy.BEST_MATCH);

        // Sets the timeout in milliseconds used when retrieving a connection from the ClientConnectionManager
        HttpClientParams.setConnectionManagerTimeout(params,
                Preferences.instance().getLong("http.manager.timeout"));

        SchemeRegistry registry = new SchemeRegistry();
        // Always register HTTP for possible use with proxy
        registry.register(new Scheme(ch.cyberduck.core.Scheme.http.toString(), host.getPort(),
                PlainSocketFactory.getSocketFactory()));
        registry.register(new Scheme(ch.cyberduck.core.Scheme.https.toString(), host.getPort(),
                new SSLSocketFactory(
                        new CustomTrustSSLProtocolSocketFactory(this.getTrustManager()).getSSLContext(),
                        new X509HostnameVerifier() {
                            @Override
                            public void verify(String host, SSLSocket ssl) throws IOException {
                                log.warn("Hostname verification disabled for:" + host);
                            }/*from   www  .  j a  va  2 s.  co m*/

                            @Override
                            public void verify(String host, X509Certificate cert) throws SSLException {
                                log.warn("Hostname verification disabled for:" + host);
                            }

                            @Override
                            public void verify(String host, String[] cns, String[] subjectAlts)
                                    throws SSLException {
                                log.warn("Hostname verification disabled for:" + host);
                            }

                            @Override
                            public boolean verify(String s, javax.net.ssl.SSLSession sslSession) {
                                log.warn("Hostname verification disabled for:" + s);
                                return true;
                            }
                        })));
        if (Preferences.instance().getBoolean("connection.proxy.enable")) {
            final Proxy proxy = ProxyFactory.get();
            if (ch.cyberduck.core.Scheme.https.equals(this.getHost().getProtocol().getScheme())) {
                if (proxy.isHTTPSProxyEnabled(host)) {
                    ConnRouteParams.setDefaultProxy(params,
                            new HttpHost(proxy.getHTTPSProxyHost(host), proxy.getHTTPSProxyPort(host)));
                }
            }
            if (ch.cyberduck.core.Scheme.http.equals(this.getHost().getProtocol().getScheme())) {
                if (proxy.isHTTPProxyEnabled(host)) {
                    ConnRouteParams.setDefaultProxy(params,
                            new HttpHost(proxy.getHTTPProxyHost(host), proxy.getHTTPProxyPort(host)));
                }
            }
        }
        PoolingClientConnectionManager manager = new PoolingClientConnectionManager(registry);
        manager.setMaxTotal(Preferences.instance().getInteger("http.connections.total"));
        manager.setDefaultMaxPerRoute(Preferences.instance().getInteger("http.connections.route"));
        AbstractHttpClient http = new DefaultHttpClient(manager, params);
        this.configure(http);
        clients.put(hostname, http);
    }
    return clients.get(hostname);
}

From source file:org.hupo.psi.mi.psicquic.ws.legacy.SolrBasedPsicquicRestService10.java

private HttpClient createHttpClient() {
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));

    PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
    cm.setMaxTotal(SolrBasedPsicquicService.maxTotalConnections);
    cm.setDefaultMaxPerRoute(SolrBasedPsicquicService.defaultMaxConnectionsPerHost);

    HttpClient httpClient = new DefaultHttpClient(cm);

    String proxyHost = config.getProxyHost();
    String proxyPort = config.getProxyPort();

    if (isValueSet(proxyHost) && proxyHost.trim().length() > 0 && isValueSet(proxyPort)
            && proxyPort.trim().length() > 0) {
        try {//  ww  w.j  a v  a  2s  .  c om
            HttpHost proxy = new HttpHost(proxyHost, Integer.parseInt(proxyPort));
            httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        } catch (Exception e) {
            logger.error("Impossible to create proxy host:" + proxyHost + ", port:" + proxyPort, e);
        }
    }

    return httpClient;
}

From source file:com.ngdata.hbaseindexer.mr.HBaseIndexerMapper.java

private DirectSolrClassicInputDocumentWriter createClassicSolrWriter(Context context,
        Map<String, String> indexConnectionParams) throws IOException {
    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
    connectionManager.setDefaultMaxPerRoute(getSolrMaxConnectionsPerRoute(indexConnectionParams));
    connectionManager.setMaxTotal(getSolrMaxConnectionsTotal(indexConnectionParams));

    HttpClient httpClient = new DefaultHttpClient(connectionManager);
    List<SolrServer> solrServers = createHttpSolrServers(indexConnectionParams, httpClient);

    return new DirectSolrClassicInputDocumentWriter(context.getConfiguration().get(INDEX_NAME_CONF_KEY),
            solrServers);/*from w  w w .j  av  a2  s. c om*/
}

From source file:com.kurento.kmf.content.internal.StreamingProxy.java

/**
 * After constructor method; it created the HTTP client using configuration
 * parameters {@link ContentApiConfiguration}.
 * /*ww  w  .j  a v  a 2s .  c o  m*/
 * @see ContentApiConfiguration
 */
@PostConstruct
public void afterPropertiesSet() {
    HttpParams params = new BasicHttpParams();
    params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, configuration.getProxyConnectionTimeout());
    params.setParameter(CoreConnectionPNames.SO_TIMEOUT, configuration.getProxySocketTimeout());

    // Thread-safe configuration (using PoolingClientConnectionManager)
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
    PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
    cm.setMaxTotal(configuration.getProxyMaxConnections());
    cm.setDefaultMaxPerRoute(configuration.getProxyMaxConnectionsPerRoute());

    httpClient = new DefaultHttpClient(cm, params);
}