Example usage for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager

List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager

Introduction

In this page you can find the example usage for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager.

Prototype

public MultiThreadedHttpConnectionManager() 

Source Link

Usage

From source file:com.smartitengineering.util.rest.client.jersey.cache.HttpCache4jResolverBasedCacheableClientTest.java

protected Client getClient() {
    ClientConfig config = new DefaultClientConfig();
    config.getClasses().add(Resources.HeaderWriter.class);
    HttpClient lClient = new HttpClient(new MultiThreadedHttpConnectionManager());
    HTTPClientResponseResolver responseResolver = new HTTPClientResponseResolver(lClient);
    CacheableClientHandler handler = new CacheableClientHandler(new MemoryCacheStorage(), responseResolver);
    Client c = CacheableClient.create(config, handler, null);
    return c;/*  w  w w  . j a  va 2s  .c  o m*/
}

From source file:com.moss.jaxwslite.ServiceFactory.java

public ServiceFactory() {

    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    client = new HttpClient(connectionManager);

    setConnectionTimeout(30000);//  www  .  j ava 2s.c  o m
}

From source file:com.rometools.propono.atom.client.ClientAtomService.java

private Document getAtomServiceDocument() throws ProponoException {
    GetMethod method = null;//from ww  w  . ja  va  2s. c o m
    final int code = -1;
    try {
        httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
        // TODO: make connection timeout configurable
        httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000);

        method = new GetMethod(uri);
        authStrategy.addAuthentication(httpClient, method);
        httpClient.executeMethod(method);

        final SAXBuilder builder = new SAXBuilder();
        final String doc = method.getResponseBodyAsString();
        LOG.debug(doc);
        return builder.build(method.getResponseBodyAsStream());

    } catch (final Throwable t) {
        final String msg = "ERROR retrieving Atom Service Document, code: " + code;
        LOG.debug(msg, t);
        throw new ProponoException(msg, t);
    } finally {
        if (method != null) {
            method.releaseConnection();
        }
    }
}

From source file:com.linkedin.pinot.common.http.MultiGetRequestTest.java

@Test
public void testMultiGet() {
    MultiGetRequest mget = new MultiGetRequest(Executors.newCachedThreadPool(),
            new MultiThreadedHttpConnectionManager());
    List<String> urls = Arrays.asList("http://localhost:" + String.valueOf(portStart) + URI_PATH,
            "http://localhost:" + String.valueOf(portStart + 1) + URI_PATH,
            "http://localhost:" + String.valueOf(portStart + 2) + URI_PATH,
            // 2nd request to the same server
            "http://localhost:" + String.valueOf(portStart) + URI_PATH);
    // timeout value needs to be less than 5000ms set above for
    // third server
    final int requestTimeoutMs = 1000;
    CompletionService<GetMethod> completionService = mget.execute(urls, requestTimeoutMs);
    int success = 0;
    int errors = 0;
    int timeouts = 0;
    for (int i = 0; i < urls.size(); i++) {
        GetMethod getMethod = null;/*  w  w  w  .  j a  va 2  s .c  o m*/
        try {
            getMethod = completionService.take().get();
            if (getMethod.getStatusCode() >= 300) {
                ++errors;
                Assert.assertEquals(getMethod.getResponseBodyAsString(), ERROR_MSG);
            } else {
                ++success;
                Assert.assertEquals(getMethod.getResponseBodyAsString(), SUCCESS_MSG);
            }

        } catch (InterruptedException e) {
            LOGGER.error("Interrupted", e);
            ++errors;
        } catch (ExecutionException e) {
            if (Throwables.getRootCause(e) instanceof SocketTimeoutException) {
                LOGGER.debug("Timeout");
                ++timeouts;
            } else {
                LOGGER.error("Error", e);
                ++errors;
            }
        } catch (IOException e) {
            ++errors;
        }
    }

    Assert.assertEquals(2, success);
    Assert.assertEquals(1, errors);
    Assert.assertEquals(1, timeouts);
}

From source file:edu.ucsb.eucalyptus.transport.util.Defaults.java

public static MultiThreadedHttpConnectionManager getDefaultHttpManager() {
    MultiThreadedHttpConnectionManager httpConnMgr = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = httpConnMgr.getParams();
    params.setDefaultMaxConnectionsPerHost(16);
    params.setMaxTotalConnections(16);//from   w  w  w. j av a 2s.  com
    params.setTcpNoDelay(true);
    params.setConnectionTimeout(120 * 1000);
    //    params.setReceiveBufferSize( 8388608 );
    //    params.setSendBufferSize( 8388608 );
    params.setStaleCheckingEnabled(true);
    params.setSoTimeout(120 * 1000);
    //    params.setLinger( -1 );
    return httpConnMgr;
}

From source file:edu.ku.brc.helpers.HTTPGetter.java

/**
 * Performs a "generic" HTTP request and fill member variable with results
 * use "getDigirResultsetStr" to get the results as a String
 *
 * @param url URL to be executaed/*from   ww  w . j a  v  a  2 s . co m*/
 * @return returns the input stream for the body
 */
public InputStream beginHTTPRequest(final String url) throws Exception {
    status = ErrorCode.NoError;

    // Create an HttpClient with the MultiThreadedHttpConnectionManager.
    // This connection manager must be used if more than one thread will
    // be using the HttpClient.
    httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());

    GetMethod mthod = new GetMethod(url);
    //method.setQueryString("q=xxx");

    log.debug("getting " + mthod.getURI()); //$NON-NLS-1$
    // execute the method
    httpClient.executeMethod(mthod);

    log.debug("Len: " + mthod.getResponseContentLength()); //$NON-NLS-1$
    return iStream = mthod.getResponseBodyAsStream();
}

From source file:com.gisgraphy.domain.geoloc.service.fulltextsearch.FulltextSearchEngineTest.java

@Test
public void testIsAlive() {
    assertTrue(fullTextSearchEngine.isAlive());
    FullTextSearchEngine fullTextSearchEngineTobadUrl = new FullTextSearchEngine(
            new MultiThreadedHttpConnectionManager());
    IsolrClient mockSolClient = EasyMock.createMock(IsolrClient.class);
    EasyMock.expect(mockSolClient.isServerAlive()).andReturn(false);
    EasyMock.replay(mockSolClient);/*  w w  w . j  a  va2 s  . co  m*/
    fullTextSearchEngineTobadUrl.setSolrClient(mockSolClient);

    assertFalse(fullTextSearchEngineTobadUrl.isAlive());
    EasyMock.verify(mockSolClient);

    FullTextSearchEngine fullTextSearchEngineWithNullSolrClient = new FullTextSearchEngine(
            new MultiThreadedHttpConnectionManager());
    fullTextSearchEngineWithNullSolrClient.setSolrClient(null);
    assertFalse(fullTextSearchEngineWithNullSolrClient.isAlive());
}

From source file:de.juwimm.cms.common.http.HttpClientWrapper.java

protected HttpClientWrapper() {
    // Protocol.registerProtocol("https", new Protocol("https", new
    // EasySSLProtocolSocketFactory(), 443));
    Protocol.registerProtocol("https",
            new Protocol("https", (ProtocolSocketFactory) new SSLProtocolSocketFactory(), 443));
    System.setProperty("java.protocol.handler.pkgs", "org.apache.commons.httpclient");

    connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.getParams().setDefaultMaxConnectionsPerHost(20);
    connectionManager.getParams().setMaxTotalConnections(40);
    connectionManager.getParams().setStaleCheckingEnabled(true);

    setHttpProxyHost(System.getProperty("https.proxyHost"));
    setHttpProxyPort(System.getProperty("https.proxyPort"));
    if (propFile.exists()) {
        try {//ww  w.  j  av a2s . c o m
            FileInputStream fis = new FileInputStream(propFile);
            fileProp = new Properties();
            fileProp.load(fis);
            fis.close();
            setHttpProxyUser(fileProp.getProperty("http.proxyUser", "").toString());
            // setHttpProxyPassword(fileProp.getProperty("http.proxyPassword",
            // "").toString());
            setHttpProxyPassword(fileProp.getProperty(HttpClientWrapper.CQ_HTTP_PPROXY_PASSWORD_ENCRYPTED, "no")
                    .equalsIgnoreCase("no") ? fileProp.getProperty("http.proxyPassword").toString()
                            : new ClientDesEncrypter().decrypt(fileProp.getProperty("http.proxyPassword")));
        } catch (Exception exe) {
            log.error("Could not update the localuser properties from the .tizzit file", exe);
        }
    }

}

From source file:com.funambol.json.dao.AuthenticatorDAOImpl.java

/**
 * @param server the server name. For example: jsonservice.com
 * @param port the server port//from w  ww. jav a2  s . c  o  m
 * @param schema http or https
 */
public AuthenticatorDAOImpl(String serverUrl) {
    super();
    this.serverUrl = serverUrl;

    HttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
    this.httpClient = new HttpClient(httpConnectionManager);
}

From source file:com.linkedin.pinot.controller.helix.SegmentStatusChecker.java

/**
 * Constructs the segment status checker.
 * @param pinotHelixResourceManager The resource checker used to interact with Helix
 * @param config The controller configuration object
 *///from   www  .j a  va2 s  .co  m
public SegmentStatusChecker(PinotHelixResourceManager pinotHelixResourceManager, ControllerConf config,
        ControllerMetrics metricsRegistry) {
    _pinotHelixResourceManager = pinotHelixResourceManager;
    _helixAdmin = pinotHelixResourceManager.getHelixAdmin();
    _config = config;
    _segmentStatusIntervalSeconds = config.getStatusCheckerFrequencyInSeconds();
    _waitForPushTimeSeconds = config.getStatusCheckerWaitForPushTimeInSeconds();
    _metricsRegistry = metricsRegistry;
    HttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
    _tableSizeReader = new TableSizeReader(Executors.newCachedThreadPool(), httpConnectionManager,
            _pinotHelixResourceManager);
}