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:org.attribyte.api.http.impl.commons.Commons3Client.java

/**
 * Creates a client with specified options.
 * @param options The options.//from   w ww  .  ja  va2s  .  co m
 */
public Commons3Client(final ClientOptions options) {
    connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(fromOptions(options));
    httpClient = new HttpClient(connectionManager);
    HostConfiguration hostConfig = new HostConfiguration();

    if (options.proxyHost != null) {
        hostConfig.setProxy(options.proxyHost, options.proxyPort);
    }
    httpClient.setHostConfiguration(hostConfig);
    userAgent = options.userAgent;
}

From source file:org.attribyte.api.http.impl.commons.Commons3Client.java

@Override
/**/*from  ww  w  .ja  va  2s  .  c om*/
 * Initializes the client from properties.
 * <p>
 *   The following properties are available. <b>Bold</b> properties are required.
 *
 *   <h2>HTTP Client</h2>
 *   <dl>  
 *     <dt><b>User-Agent</b></dt>
 *     <dd>The default User-Agent string sent with requests. Added only if
 *     request has no <code>User-Agent</code> header.</dd>
 *     <dt><b>connectionTimeoutMillis</b></dt>
 *     <dd>The HTTP connection timeout in milliseconds.</dd>
 *     <dt><b>socketTimeoutMillis</b></dt>
 *     <dd>The HTTP client socket timeout in milliseconds.</dd>
 *     <dt>proxyHost</dt>
 *     <dd>The HTTP proxy host. If specified, all client requests will use this proxy.</dd>     
 *     <dt>proxyPort</dt>
 *     <dd>The HTTP proxy port. Required when <code>proxyHost</code> is specified</dd>
 *   </dl>
 * </p>
 * @param prefix The prefix for all properties (e.g. 'client.').
 * @param props The properties.
 * @param logger The logger. If unspecified, messages are logged to the console.
 * @throws InitializationException on initialization error.
 */
public synchronized void init(String prefix, Properties props, Logger logger) throws InitializationException {

    if (isInit.compareAndSet(false, true)) {

        ClientOptions options = new ClientOptions(prefix, props);
        connectionManager = new MultiThreadedHttpConnectionManager();
        connectionManager.setParams(fromOptions(options));

        httpClient = new HttpClient(connectionManager);
        HostConfiguration hostConfig = new HostConfiguration();

        if (options.proxyHost != null) {
            hostConfig.setProxy(options.proxyHost, options.proxyPort);
        }
        httpClient.setHostConfiguration(hostConfig);

        userAgent = options.userAgent;
    }
}

From source file:org.avalonmediasystem.AvalonWorkflowListener.java

private void pingAvalon(String pid, long workflowId) {
    logger.trace("Starting to ping Avalon: " + pid + " " + workflowId);
    try {//from   ww  w . ja  v  a  2s  .co m
        String url = UrlSupport.concat(new String[] { avalonUrl, "master_files", pid });
        MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
        HttpClient client = new HttpClient(mgr);

        PutMethod put = new PutMethod(url);

        Part[] parts = { new StringPart("workflow_id", String.valueOf(workflowId)), };
        put.setRequestEntity(new MultipartRequestEntity(parts, put.getParams()));
        logger.trace("About to ping Avalon");
        int status = client.executeMethod(put);
        logger.debug("Got status: " + status);
        logger.trace("Got response body: " + put.getResponseBodyAsString());
    } catch (Exception e) {
        logger.debug("Exception pinging Avalon: " + e.getCause(), e);
    }
}

From source file:org.b5chat.crossfire.web.FaviconServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    // Create a pool of HTTP connections to use to get the favicons
    client = new HttpClient(new MultiThreadedHttpConnectionManager());
    HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams();
    params.setConnectionTimeout(2000);//from   w w  w .ja  v a 2s .  com
    params.setSoTimeout(2000);
    // Load the default favicon to use when no favicon was found of a remote host
    try {
        URL resource = config.getServletContext().getResource("/images/server_16x16.gif");
        defaultBytes = getImage(resource.toString());
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    // Initialize caches.
    missesCache = CacheFactory.createCache("Favicon Misses");
    hitsCache = CacheFactory.createCache("Favicon Hits");
}

From source file:org.bbsync.webservice.client.proxytool.ContextProxyTool.java

/**
 * After instantiating a Stub object, we need to configure how it will
 * communicate with the server-side web service.  As the name implies, 
 * this method configures various client options.  These options include
 * setting up Rampart-based security for user login, tool login and ticket
 * login./*from  w w  w .j  a  v a 2 s.  co m*/
 * 
 * @param wsStub - a newly created Stub object.  See createClientWS().
 * @return Returns a fully-configured client Stub that will be able to
 *         communicate with it's server-side counterpart.
 */
protected Stub configureClientOptions(Stub wsStub) {
    if (_httpClient == null)
        _httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
    ServiceClient client = wsStub._getServiceClient();
    Options options = client.getOptions();
    options.setProperty(HTTPConstants.AUTO_RELEASE_CONNECTION, Constants.VALUE_TRUE);
    //This is where we configure the password callback handler
    options.setProperty(WSHandlerConstants.PW_CALLBACK_REF, pwcb);
    /*
     * Setup ws-security settings.  Must use deprecated class of setting
     * up security because the SOAP response doesn't include a security
     * header. Using the deprecated OutflowConfiguration class we can
     * specify that the security header is only for the outgoing SOAP message.
     */
    OutflowConfiguration ofc = new OutflowConfiguration();
    ofc.setActionItems("UsernameToken Timestamp");
    ofc.setUser("session");
    ofc.setPasswordType("PasswordText");
    options.setProperty(WSSHandlerConstants.OUTFLOW_SECURITY, ofc.getProperty());
    //You might want to use the same HTTPClient instance for multiple 
    //invocations. This flag will notify the engine to use the same 
    //HTTPClient between invocations.
    options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE);

    //If user had requested to re-use an HTTPClient using the above 
    //property, this property can be used to set a custom HTTPClient to 
    //be re-used.
    options.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, _httpClient);
    try {
        client.engageModule("rampart");
    } catch (AxisFault e) {
        logger.error("Unable to engage the rampart security module: " + e.getMessage());
        return null;
    }
    return wsStub;
}

From source file:org.bench4Q.agent.rbe.HttpClientFactory.java

/**
 * get a HttpClient.//  w  ww.  ja v  a  2 s .co m
 * 
 * @return HttpClient
 */
public static HttpClient getInstance() {
    if (m_client == null) {
        MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
        connectionManager.setMaxConnectionsPerHost(10000);
        connectionManager.setMaxTotalConnections(10000);
        m_client = new HttpClient(connectionManager);

        DefaultMethodRetryHandler retryhandler = new DefaultMethodRetryHandler();
        retryhandler.setRetryCount(DEFAULT_RETRY_COUNT);
        m_client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryhandler);
    }
    return m_client;

}

From source file:org.codehaus.httpcache4j.client.HTTPClientResponseResolver.java

public static HTTPClientResponseResolver createMultithreadedInstance() {
    return new HTTPClientResponseResolver(new HttpClient(new MultiThreadedHttpConnectionManager()));
}

From source file:org.codehaus.httpcache4j.MemoryHTTPComponentsCacheIntegrationTest.java

@Override
protected ResponseResolver createReponseResolver() {
    return new HTTPClientResponseResolver(new HttpClient(new MultiThreadedHttpConnectionManager()));
}

From source file:org.codinjutsu.tools.jenkins.security.DefaultSecurityClient.java

DefaultSecurityClient(String crumbData) {
    this.httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
    this.crumbData = crumbData;
}

From source file:org.collectionspace.chain.csp.persistence.services.connection.ServicesConnection.java

private void initClient() {
    if (manager != null)
        return;//  ww  w  . java2 s  .  c  om
    synchronized (getClass()) {
        if (manager != null)
            return;

        // We're only connecting to one host, so set the max connections per host to be
        // the same as the max total connections.

        HttpConnectionManagerParams params = new HttpConnectionManagerParams();
        params.setMaxTotalConnections(MAX_SERVICES_CONNECTIONS);
        params.setDefaultMaxConnectionsPerHost(MAX_SERVICES_CONNECTIONS);

        manager = new MultiThreadedHttpConnectionManager();
        manager.setParams(params);
    }
}