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

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

Introduction

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

Prototype

public PoolingClientConnectionManager() 

Source Link

Usage

From source file:edu.ehu.galan.lite.utils.wikiminer.WikiminnerHelper.java

private WikiminnerHelper(String pPropDirs) {
    //PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    // Increase max total connection to 200
    // cm.setMaxTotal(100);
    // Increase default max connection per route to 20
    // cm.setDefaultMaxPerRoute(20);
    // Increase max connections for localhost:80 to 50
    PoolingClientConnectionManager pm = new PoolingClientConnectionManager();
    pm.setDefaultMaxPerRoute(20);//from  ww  w  .  j a v  a  2s . c  om
    pm.setMaxTotal(200);
    httpClient = new DefaultHttpClient(pm);
    //        ConnectionConfig connectionConfig = ConnectionConfig.custom()
    //                .setMalformedInputAction(CodingErrorAction.IGNORE)
    //                .setUnmappableInputAction(CodingErrorAction.IGNORE)
    //                .setCharset(Consts.UTF_8).build();
    //        cm.setDefaultConnectionConfig(connectionConfig);

    //        httpClient = HttpClients.custom()
    //                .setConnectionManager(cm)
    //                .build();
    httpClient.getParams().setParameter("http.protocol.content-charset", "UTF-8");
    cache = CacheManager.getInstance().getCache("LiteCache");
    props = new Properties();
    caches = new Caches();
    try {
        props.load(new FileInputStream(new File(pPropDirs + "lite/configs/general.conf")));
        wikiminerUrl = props.getProperty("serviceUrl");
        maxTopics = Integer.parseInt(props.getProperty("maxTopics"));
    } catch (IOException ex) {
        logger.error("Error while setting WikiminerHelper properties files, check dirs", ex);
    }
    localMode = !props.get("localMode").equals("false");
}

From source file:org.sentilo.common.rest.impl.RESTClientImpl.java

@Override
public void afterPropertiesSet() throws Exception {
    if (httpClient == null) {
        final PoolingClientConnectionManager pccm = new PoolingClientConnectionManager();
        // Increase max total connection to 400
        pccm.setMaxTotal(400);//from  ww w .j  ava  2s .  com
        // Increase default max connection per route to 50
        pccm.setDefaultMaxPerRoute(50);

        httpClient = new DefaultHttpClient(pccm);
        // Set the timeouts for read the response and create a connection
        setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT_MILLISECONDS);
        setReadTimeout(DEFAULT_READ_TIMEOUT_MILLISECONDS);
    }

    if (interceptors != null && httpClient instanceof DefaultHttpClient) {
        for (final HttpRequestInterceptor interceptor : interceptors) {
            ((DefaultHttpClient) httpClient).addRequestInterceptor(interceptor);
        }
    }

    if (credentials != null && httpClient instanceof DefaultHttpClient) {
        ((DefaultHttpClient) httpClient).getCredentialsProvider().setCredentials(authScope, credentials);

    }
}

From source file:net.netheos.pcsapi.storage.StorageBuilder.java

private static HttpClient createDefaultClient() {
    if (PcsUtils.ANDROID) {
        return android.net.http.AndroidHttpClient.newInstance("pcs-api");

    } else {/*from w  ww .  j a  v  a 2  s  . c om*/
        HttpParams params = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(params, 15000); // 15 sec
        HttpConnectionParams.setSoTimeout(params, 60000); // 1 min
        return new org.apache.http.impl.client.DefaultHttpClient(new PoolingClientConnectionManager(), params);
    }
}

From source file:nl.nn.adapterframework.http.WebServiceNtlmSender.java

public void open() {
    connectionManager = new PoolingClientConnectionManager();
    connectionManager.setMaxTotal(getMaxConnections());
}

From source file:org.yamj.api.common.http.AbstractPoolingHttpClient.java

@Override
protected ClientConnectionManager createClientConnectionManager() {
    PoolingClientConnectionManager clientManager = new PoolingClientConnectionManager();
    clientManager.setDefaultMaxPerRoute(connectionsMaxPerRoute);
    clientManager.setMaxTotal(connectionsMaxTotal);
    return clientManager;
}

From source file:nl.esciencecenter.ptk.web.WebClient.java

public boolean connect() throws WebException {
    httpClient = new DefaultHttpClient();

    if (config.isMultiThreaded()) {
        ClientConnectionManager connectionManager = new PoolingClientConnectionManager();
        httpClient = new DefaultHttpClient(connectionManager);
    }//from  w w  w  . java 2s.com

    try {

        if (config.isHTTPS()) {
            if (this.certStore == null) {
                logger.warnPrintf("Warning: HTTPS procotol with no CertificateStore\n");
            } else {
                initSSL(this.certStore, true);
            }
        }

        if ((config.getUseBasicAuthentication()) && (config.hasPassword() == false) && (this.jsessionID == null)
                && (this.hasUI())) {
            String user = getUsername();

            SecretHolder secret = new SecretHolder();
            boolean result = uiPromptPassfield(
                    "Password for user:" + user + "@" + config.getHostname() + ":" + config.getPort(), secret);

            if (result == false) {
                return false; // cancelled.
            }

            this.config.password = secret.get();
        }

        // httpClient.getCredentialsProvider().setCredentials(new
        // AuthScope(config.getHostname(), config.getPort()),
        // new UsernamePasswordCredentials(config.getUsername(), new
        // String(config.getPasswordChars())));

        if (config.useJSession()) {
            initJSession(false);
            return true;
        } else {
            // check service URI.
            HttpGet httpget = new HttpGet(serviceUri);
            logger.debugPrintf("connect(): Executing request: %s\n", httpget.getRequestLine());
            HttpResponse response = httpClient.execute(httpget);
            logger.debugPrintf("connect(): ------------ Response ----------\n");
            StringHolder textH = new StringHolder();
            this.lastHttpStatus = handleStringResponse("connect()" + serviceUri, response, textH, null);

            return true;
        }
    } catch (ClientProtocolException e) {
        throw new WebException(WebException.Reason.HTTP_CLIENTEXCEPTION, e.getMessage(), e);
    } catch (javax.net.ssl.SSLPeerUnverifiedException e) {
        throw new WebException(WebException.Reason.HTTPS_SSLEXCEPTION,
                "SSL Verification Error:" + e.getMessage(), e);
    } catch (WebException e) {
        throw (e); // pass
    } catch (IOException e) {
        throw new WebException(WebException.Reason.IOEXCEPTION, e.getMessage(), e);
    } finally {
        // check connected state...
    }
}

From source file:com.ngdata.hbaseindexer.supervisor.IndexerSupervisor.java

private void startIndexer(IndexerDefinition indexerDef) {
    IndexerHandle handle = null;/*from  w  ww .  jav  a2 s.co m*/
    SolrServer solr = null;

    String indexerProcessId = null;
    try {

        // If this is an update and the indexer failed to start, it's still in the registry as a
        // failed process
        if (indexerProcessIds.containsKey(indexerDef.getName())) {
            indexerProcessRegistry.unregisterIndexerProcess(indexerProcessIds.remove(indexerDef.getName()));
        }

        indexerProcessId = indexerProcessRegistry.registerIndexerProcess(indexerDef.getName(), hostName);
        indexerProcessIds.put(indexerDef.getName(), indexerProcessId);

        // Create and register the indexer
        IndexerComponentFactory factory = IndexerComponentFactoryUtil.getComponentFactory(
                indexerDef.getIndexerComponentFactory(),
                new ByteArrayInputStream(indexerDef.getConfiguration()), indexerDef.getConnectionParams());
        IndexerConf indexerConf = factory.createIndexerConf();

        ResultToSolrMapper mapper = factory.createMapper(indexerDef.getName());

        Sharder sharder = null;
        SolrInputDocumentWriter solrWriter;
        PoolingClientConnectionManager connectionManager = null;

        if (indexerDef.getConnectionType() == null || indexerDef.getConnectionType().equals("solr")) {
            Map<String, String> connectionParams = indexerDef.getConnectionParams();
            String solrMode = SolrConnectionParamUtil.getSolrMode(connectionParams);
            if (solrMode.equals("cloud")) {
                solrWriter = new DirectSolrInputDocumentWriter(indexerDef.getName(),
                        createCloudSolrServer(connectionParams));
            } else if (solrMode.equals("classic")) {
                connectionManager = new PoolingClientConnectionManager();
                connectionManager.setDefaultMaxPerRoute(getSolrMaxConnectionsPerRoute(connectionParams));
                connectionManager.setMaxTotal(getSolrMaxConnectionsTotal(connectionParams));

                httpClient = new DefaultHttpClient(connectionManager);
                List<SolrServer> solrServers = createHttpSolrServers(connectionParams, httpClient);
                solrWriter = new DirectSolrClassicInputDocumentWriter(indexerDef.getName(), solrServers);
                sharder = createSharder(connectionParams, solrServers.size());
            } else {
                throw new RuntimeException(
                        "Only 'cloud' and 'classic' are valid values for solr.mode, but got " + solrMode);
            }
        } else {
            throw new RuntimeException("Invalid connection type: " + indexerDef.getConnectionType()
                    + ". Only 'solr' is supported");
        }

        Indexer indexer = Indexer.createIndexer(indexerDef.getName(), indexerConf, indexerConf.getTable(),
                mapper, htablePool, sharder, solrWriter);
        IndexingEventListener eventListener = new IndexingEventListener(indexer, indexerConf.getTable());

        int threads = hbaseConf.getInt("hbaseindexer.indexer.threads", 10);
        SepConsumer sepConsumer = new SepConsumer(indexerDef.getSubscriptionId(),
                indexerDef.getSubscriptionTimestamp(), eventListener, threads, hostName, zk, hbaseConf, null);

        handle = new IndexerHandle(indexerDef, indexer, sepConsumer, solr, connectionManager);
        handle.start();

        indexers.put(indexerDef.getName(), handle);
        indexerRegistry.register(indexerDef.getName(), indexer);

        log.info("Started indexer for " + indexerDef.getName());
    } catch (Throwable t) {
        if (t instanceof InterruptedException) {
            Thread.currentThread().interrupt();
        }

        log.error("Problem starting indexer " + indexerDef.getName(), t);

        try {
            if (indexerProcessId != null) {
                indexerProcessRegistry.setErrorStatus(indexerProcessId, t);
            }
        } catch (Exception e) {
            log.error("Error setting error status on indexer process " + indexerProcessId, e);
        }

        if (handle != null) {
            // stop any listeners that might have been started
            try {
                handle.stop();
            } catch (Throwable t2) {
                if (t2 instanceof InterruptedException) {
                    Thread.currentThread().interrupt();
                }
                log.error(
                        "Problem stopping consumers for failed-to-start indexer '" + indexerDef.getName() + "'",
                        t2);
            }
        } else {
            // Might be the handle was not yet created, but the solr connection was
            Closer.close(solr);
        }
    }
}

From source file:com.barchart.netty.server.http.handlers.TestStaticResourceHandler.java

@Before
public void setUp() throws Exception {

    final ServerSocket s = new ServerSocket(0);
    port = s.getLocalPort();/*from  w w  w. j a  va 2  s .  co m*/
    s.close();

    server = Servers.createHttpServer().group(new NioEventLoopGroup())
            .requestHandler("/classpath", new StaticResourceHandler(this.getClass().getClassLoader(), "/files"))
            .requestHandler("/file", new StaticResourceHandler(
                    new File(System.getProperty("user.dir") + "/src/test/resources/files")));

    server.listen(port, "localhost");

    client = new DefaultHttpClient(new PoolingClientConnectionManager());

}