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.gisgraphy.domain.geoloc.service.fulltextsearch.SolrClientTest.java

@Test
public void testSetSolRLogLevel() throws Exception {
    IsolrClient client = new SolrClient(AbstractIntegrationHttpSolrTestCase.fulltextSearchUrlBinded,
            new MultiThreadedHttpConnectionManager());
    assertTrue(client.isServerAlive());/*from w ww.ja  v  a  2 s .c o  m*/
    client.setSolRLogLevel(Level.CONFIG);
    client.setSolRLogLevel(Level.FINE);
    client.setSolRLogLevel(Level.FINER);
    client.setSolRLogLevel(Level.FINEST);
    client.setSolRLogLevel(Level.INFO);
    client.setSolRLogLevel(Level.SEVERE);
    client.setSolRLogLevel(Level.WARNING);
    client.setSolRLogLevel(Level.ALL);
    client.setSolRLogLevel(Level.OFF);
}

From source file:com.legstar.test.cixs.AbstractHttpClientTester.java

/**
 * Setup the static http connection pool.
 * /*from w  w w.  j a v  a  2 s.c  om*/
 * @return an http client instance
 */
protected static HttpClient createHttpClient() {

    HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams();

    connectionManagerParams.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
    connectionManagerParams.setDefaultMaxConnectionsPerHost(DEFAULT_MAX_CONNECTIONS_PER_HOST);
    connectionManagerParams.setTcpNoDelay(TCP_NO_DELAY);
    connectionManagerParams.setSoTimeout(SOCKET_TIMEOUT);
    connectionManagerParams.setConnectionTimeout(CONNECT_TIMEOUT);

    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(connectionManagerParams);
    connectionManager.closeIdleConnections(IDLE_CONNECTION_TIMEOUT);
    return new HttpClient(connectionManager);
}

From source file:net.sf.sail.webapp.domain.webservice.http.impl.HttpRestTransportImpl.java

/**
 * Constructs a newly allocated HttpRestTransportImpl object.
 *///from w ww.j a v  a2  s  .c o  m
public HttpRestTransportImpl() {
    // Must manually release the connection by calling releaseConnection()
    // on the method, otherwise there will be a resource leak. Refer to
    // http://jakarta.apache.org/commons/httpclient/threading.html
    this.client = new HttpClient(new MultiThreadedHttpConnectionManager());
    this.logger = LogFactory.getLog(this.getClass());
}

From source file:com.creditease.bdp.axis2.transport.http.HTTPSender.java

@Override
protected HttpClient getHttpClient(MessageContext msgContext) {
    ConfigurationContext configContext = msgContext.getConfigurationContext();

    HttpClient httpClient = (HttpClient) msgContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT);

    if (httpClient == null) {
        httpClient = (HttpClient) configContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT);
    }/*www . j av  a2s . c o m*/

    if (httpClient != null) {
        return httpClient;
    }

    synchronized (this) {
        httpClient = (HttpClient) msgContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT);

        if (httpClient == null) {
            httpClient = (HttpClient) configContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT);
        }

        if (httpClient != null) {
            return httpClient;
        }

        HttpConnectionManager connManager = (HttpConnectionManager) msgContext
                .getProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER);
        if (connManager == null) {
            connManager = (HttpConnectionManager) msgContext
                    .getProperty(HTTPConstants.MUTTITHREAD_HTTP_CONNECTION_MANAGER);
        }
        if (connManager == null) {
            // reuse HttpConnectionManager
            synchronized (configContext) {
                connManager = (HttpConnectionManager) configContext
                        .getProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER);
                if (connManager == null) {
                    log.trace("Making new ConnectionManager");
                    connManager = new MultiThreadedHttpConnectionManager();
                    // NOTE: Added by CJ
                    Integer maxConnectionPerHostConf = (Integer) msgContext
                            .getProperty(Constants.MAX_CONNECTIONS_PER_HOST);
                    Integer maxConnectionTotalConf = (Integer) msgContext
                            .getProperty(Constants.MAX_CONNECTIONS_TOTAL);
                    if (maxConnectionPerHostConf != null || maxConnectionTotalConf != null) {
                        HttpConnectionManagerParams param = new HttpConnectionManagerParams();
                        if (maxConnectionPerHostConf != null) {
                            param.setDefaultMaxConnectionsPerHost(maxConnectionPerHostConf);
                        }
                        if (maxConnectionTotalConf != null) {
                            param.setMaxTotalConnections(maxConnectionTotalConf);
                        }
                        connManager.setParams(param);
                    }
                    configContext.setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER, connManager);
                }
            }
        }
        /*
         * Create a new instance of HttpClient since the way
         * it is used here it's not fully thread-safe.
         */
        httpClient = new HttpClient(connManager);

        // Set the default timeout in case we have a connection pool starvation to 30sec
        httpClient.getParams().setConnectionManagerTimeout(30000);

        // Get the timeout values set in the runtime
        initializeTimeouts(msgContext, httpClient);

        return httpClient;
    }
}

From source file:de.fuberlin.wiwiss.marbles.loading.SemanticWebClient.java

/**
 * Constructs a new <code>SemanticWebClient</code>
 * //  w w  w .  jav  a 2 s.  c  om
 * @param cacheController
 * @param spongerProvider
 * @param dataProviders
 */
public SemanticWebClient(CacheController cacheController, SpongerProvider spongerProvider,
        Collection<DataProvider> dataProviders) {
    this.cacheController = cacheController;
    this.dataProviders = dataProviders;

    /* Set connection parameters */
    HttpConnectionManagerParams httpManagerParams = new HttpConnectionManagerParams();
    httpManagerParams.setConnectionTimeout(CONNECTION_TIMEOUT * 1000);
    httpManagerParams.setTcpNoDelay(true);
    httpManagerParams.setStaleCheckingEnabled(true);

    MultiThreadedHttpConnectionManager httpManager = new MultiThreadedHttpConnectionManager();
    httpManager.setParams(httpManagerParams);

    httpClient = new HttpClient(httpManager);
    uriQueue = new DereferencingTaskQueue(httpClient, spongerProvider, 10 /* maxThreads */,
            500 * 1024 /* maxFileSize */);
}

From source file:com.tasktop.c2c.server.web.proxy.HttpProxy.java

public HttpProxy() {
    httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
    httpClient.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
    httpClient.getHttpConnectionManager().getParams().setSoTimeout(60 * 1000);
    httpClient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(0, false));
}

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

protected Client getAuthClient() {
    ClientConfig config = new DefaultClientConfig();
    config.getProperties().put(CacheableClientConfigProps.USERNAME, "name");
    config.getProperties().put(CacheableClientConfigProps.PASSWORD, "password");
    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;/*from   w  ww. ja  v a  2s . co m*/
}

From source file:fr.aliasource.webmail.server.calendar.CalendarProxyImpl.java

private HttpClient createHttpClient() {
    HttpClient ret = new HttpClient(new MultiThreadedHttpConnectionManager());
    HttpConnectionManagerParams mp = ret.getHttpConnectionManager().getParams();
    mp.setDefaultMaxConnectionsPerHost(4);
    mp.setMaxTotalConnections(8);//from  www  . ja  va 2 s.  c o m
    return ret;
}

From source file:com.sun.socialsite.util.ImageUtil.java

/**
 * Public constructor.//from   w  ww . java2 s .  c om
 */
public ImageUtil(int timeout) {

    httpConnectionManager = new MultiThreadedHttpConnectionManager();
    httpConnectionManager.getParams().setConnectionTimeout(timeout);
    httpConnectionManager.getParams().setSoTimeout(timeout);

    // This allows us to accept self-signed certs
    // TODO: make this configurable, or at least stop setting default for all HttpClients
    ProtocolSocketFactory protocolSocketFactory = new LeniantSSLProtocolSocketFactory();
    httpsProtocol = new Protocol("https", protocolSocketFactory, 443);
    Protocol.registerProtocol("https", httpsProtocol);
}

From source file:com.sa.npopa.samples.hbase.rest.client.Client.java

private void initialize(Cluster cluster, boolean sslEnabled) {
    this.cluster = cluster;
    this.sslEnabled = sslEnabled;
    MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams managerParams = manager.getParams();
    managerParams.setConnectionTimeout(2000); // 2 s
    managerParams.setDefaultMaxConnectionsPerHost(10);
    managerParams.setMaxTotalConnections(100);
    extraHeaders = new ConcurrentHashMap<String, String>();
    this.httpClient = new HttpClient(manager);
    HttpClientParams clientParams = httpClient.getParams();
    clientParams.setVersion(HttpVersion.HTTP_1_1);

}