Example usage for org.apache.http.impl.client AbstractHttpClient setParams

List of usage examples for org.apache.http.impl.client AbstractHttpClient setParams

Introduction

In this page you can find the example usage for org.apache.http.impl.client AbstractHttpClient setParams.

Prototype

public synchronized void setParams(final HttpParams params) 

Source Link

Document

Replaces the parameters.

Usage

From source file:org.jasig.portlet.proxy.service.web.MultiRequestHttpClientServiceImpl.java

private AbstractHttpClient setHttpClientTimeouts(PortletRequest request, AbstractHttpClient client) {
    PortletPreferences prefs = request.getPreferences();
    HttpParams params = client.getParams();
    if (params == null) {
        params = new BasicHttpParams();
        client.setParams(params);
    }// w w  w.  ja  v a2s.  co  m
    /*
     * The connection is attempted 5 times prior to stopping
     * so the actual time before failure will be 5 times this setting.
     * Suggested way of testing Connection Timeout is by hitting a
     * domain with a port that is firewalled:
     * ie. http://www.google.com:81
     */
    int httpClientConnectionTimeout = Integer.parseInt(prefs.getValue(HTTP_CLIENT_CONNECTION_TIMEOUT,
            String.valueOf(DEFAULT_HTTP_CLIENT_CONNECTION_TIMEOUT)));
    /*
     * Suggested way of testing Socket Timeout is by using a tool locally to connect
     * but not respond.  Example tool: bane
     * http://blog.danielwellman.com/2010/09/introducing-bane-a-test-harness-for-server-connections.html
     * usage: $bane 10010 NeverRespond
     * ie. http://localhost:10010
     */
    int httpClientSocketTimeout = Integer.parseInt(
            prefs.getValue(HTTP_CLIENT_SOCKET_TIMEOUT, String.valueOf(DEFAULT_HTTP_CLIENT_SOCKET_TIMEOUT)));
    HttpConnectionParams.setConnectionTimeout(params, httpClientConnectionTimeout);
    HttpConnectionParams.setSoTimeout(params, httpClientSocketTimeout);
    return client;
}