Example usage for org.apache.commons.httpclient.params HttpConnectionManagerParams HttpConnectionManagerParams

List of usage examples for org.apache.commons.httpclient.params HttpConnectionManagerParams HttpConnectionManagerParams

Introduction

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

Prototype

HttpConnectionManagerParams

Source Link

Usage

From source file:org.xwiki.test.escaping.framework.AbstractEscapingTest.java

/**
 * Get an instance of the HTTP client to use.
 * /* www.j av  a2  s  . c  o m*/
 * @return HTTP client initialized with admin credentials
 */
protected static HttpClient getClient() {
    if (AbstractEscapingTest.client == null) {
        HttpClient adminClient = new HttpClient();

        // set up admin credentials
        Credentials defaultcreds = new UsernamePasswordCredentials("Admin", "admin");
        adminClient.getState().setCredentials(AuthScope.ANY, defaultcreds);

        // set up client parameters
        HttpClientParams clientParams = new HttpClientParams();
        clientParams.setSoTimeout(20000);
        // We need to allow circular redirects, because some templates redirect to the same location with different
        // query parameters and the check for circular redirect in HttpClient only checks the URI path without the
        // parameters.
        // Note that actual circular redirects are still aborted after following them for some fixed number of times
        clientParams.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
        adminClient.setParams(clientParams);

        // set up connections parameters
        HttpConnectionManagerParams connectionParams = new HttpConnectionManagerParams();
        connectionParams.setConnectionTimeout(30000);
        adminClient.getHttpConnectionManager().setParams(connectionParams);

        AbstractEscapingTest.client = adminClient;
    }
    return AbstractEscapingTest.client;
}

From source file:sos.scheduler.job.JobSchedulerHttpPostJob.java

public int postFile(File inputFile, String inputFileSpec, File outputFile, String contentType, String url)
        throws Exception {

    int rc = 0;/*from ww w.  ja  v a 2 s . co  m*/

    try {
        if (inputFile.isDirectory()) {
            Vector filelist = SOSFile.getFilelist(inputFile.getCanonicalPath(), inputFileSpec, 0);
            Iterator iterator = filelist.iterator();
            while (iterator.hasNext()) {
                rc = this.postFile((File) iterator.next(), inputFileSpec, outputFile, contentType, url);
            }
            return rc;
        } else {
            PostMethod post = new PostMethod(url);
            String content = SOSFile.readFile(inputFile);
            getLogger().debug9("post before replacements: " + content);
            content = mergedVariables.substitute(content);
            getLogger().debug5("Posting: " + content);
            StringRequestEntity req = new StringRequestEntity(content);
            // post.setRequestEntity(new InputStreamRequestEntity(new FileInputStream(inputFile), inputFile.length()));
            post.setRequestEntity(req);
            post.setRequestHeader("Content-type", contentType);

            HttpClient httpClient = new HttpClient();
            if (this.getTimeout() > 0) {
                HttpConnectionManager httpManager = httpClient.getHttpConnectionManager();
                HttpConnectionManagerParams httpParams = new HttpConnectionManagerParams();
                httpParams.setConnectionTimeout(this.getTimeout() * 1000);
                httpManager.setParams(httpParams);
            }
            rc = httpClient.executeMethod(post);

            if (outputFile != null)
                logResponse(inputFile, outputFile, post.getResponseBodyAsStream());
            return rc;
        }
    } catch (Exception e) {
        throw new Exception("error occurred in HTTP POST: " + e.getMessage());
    }
}

From source file:terrastore.client.connection.resteasy.HTTPConnectionFactory.java

public HTTPConnectionFactory() {
    HttpConnectionManagerParams httpParams = new HttpConnectionManagerParams();
    httpParams.setDefaultMaxConnectionsPerHost(Runtime.getRuntime().availableProcessors() * 10);
    httpParams.setMaxTotalConnections(Runtime.getRuntime().availableProcessors() * 10);
    HttpConnectionManager httpManager = new MultiThreadedHttpConnectionManager();
    httpManager.setParams(httpParams);//  ww  w  .j av a  2 s  .  c om
    this.client = new HttpClient(httpManager);
}

From source file:terrastore.integration.IntegrationTest.java

@BeforeClass
public static void setUpClass() throws Exception {
    System.err.println("Waiting " + SETUP_TIME + " millis for system to set up ...");
    Thread.sleep(SETUP_TIME);//from  ww w  .j  a v a2 s  .  co m
    //
    HttpConnectionManagerParams httpParams = new HttpConnectionManagerParams();
    httpParams.setDefaultMaxConnectionsPerHost(100);
    httpParams.setMaxTotalConnections(100);
    HttpConnectionManager httpManager = new MultiThreadedHttpConnectionManager();
    httpManager.setParams(httpParams);
    HTTP_CLIENT.setHttpConnectionManager(httpManager);
}

From source file:terrastore.metrics.PerformanceTest.java

@BeforeClass
public static void setUpClass() throws Exception {
    HTTP_CLIENT.setHttpConnectionManager(new MultiThreadedHttpConnectionManager());
    System.err.println("Waiting " + SETUP_TIME + " millis for system to set up ...");
    Thread.sleep(SETUP_TIME);/*w w w  . jav  a  2 s  .  co  m*/
    //
    HttpConnectionManagerParams httpParams = new HttpConnectionManagerParams();
    httpParams.setDefaultMaxConnectionsPerHost(100);
    httpParams.setMaxTotalConnections(100);
    HttpConnectionManager httpManager = new MultiThreadedHttpConnectionManager();
    httpManager.setParams(httpParams);
    HTTP_CLIENT.setHttpConnectionManager(httpManager);
}

From source file:webdav.ManageWebDAV.java

public void connectWebDAVServer(String strUri, int intMaxConnections, String strUserId, String strPassword) {
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost(strUri);//from   w  w  w .ja v  a 2 s  .  c  o m

    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setMaxConnectionsPerHost(hostConfig, intMaxConnections);
    connectionManager.setParams(params);

    this.client = new HttpClient(connectionManager);
    client.setHostConfiguration(hostConfig);
    Credentials creds = new UsernamePasswordCredentials(strUserId, strPassword);
    client.getState().setCredentials(AuthScope.ANY, creds);
}

From source file:webdav.ManageWebDAVContacts.java

/**
 *
 * Public Section//from  w  w w .j av a 2s . co  m
 *
 */
public void connectHTTP(String strUser, String strPass, String strHost, boolean insecure) {
    //Connect WebDAV with credentials
    hostConfig = new HostConfiguration();
    hostConfig.setHost(strHost);
    connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManagerParams = new HttpConnectionManagerParams();
    connectionManagerParams.setMaxConnectionsPerHost(hostConfig, this.intMaxConnections);
    connectionManager.setParams(connectionManagerParams);
    client = new HttpClient(connectionManager);
    creds = new UsernamePasswordCredentials(strUser, strPass);
    client.getState().setCredentials(AuthScope.ANY, creds);
    client.setHostConfiguration(hostConfig);

    if (insecure) {
        Protocol easyhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443);
        Protocol.registerProtocol("https", easyhttps);
    }

    Status.print("WebDav Connection generated");
}