Example usage for org.apache.commons.httpclient.params HttpClientParams CONNECTION_MANAGER_TIMEOUT

List of usage examples for org.apache.commons.httpclient.params HttpClientParams CONNECTION_MANAGER_TIMEOUT

Introduction

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

Prototype

String CONNECTION_MANAGER_TIMEOUT

To view the source code for org.apache.commons.httpclient.params HttpClientParams CONNECTION_MANAGER_TIMEOUT.

Click Source Link

Usage

From source file:it.geosolutions.geostore.services.rest.security.WebServiceTokenAuthenticationFilter.java

@Override
protected Authentication checkToken(String token) {
    String webServiceUrl = url.replace("{token}", token);
    HttpClient client = getHttpClient();
    client.getParams().setParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT, connectTimeout * 1000l);
    client.getParams().setParameter(HttpClientParams.SO_TIMEOUT, readTimeout * 1000);
    HttpMethod method = null;// w ww.  jav a2 s  .  c  om
    try {
        LOGGER.debug("Issuing request to webservice: " + url);
        method = new GetMethod(webServiceUrl);
        int statusCode = client.executeMethod(method);

        if (statusCode == HttpStatus.SC_OK) {
            // get response content as a single string, without new lines
            // so that is simpler to apply an extraction regular expression
            String response = method.getResponseBodyAsString().replace("\r", "").replace("\n", "");
            if (response != null) {
                if (searchUserRegex == null) {
                    return createAuthenticationForUser(response, null, "");
                } else {
                    Matcher matcher = searchUserRegex.matcher(response);
                    if (matcher.find()) {
                        return createAuthenticationForUser(matcher.group(1), null, response);
                    } else {
                        LOGGER.warn(
                                "Error in getting username from webservice response cannot find userName in response");
                    }
                }
            } else {
                LOGGER.error("No response received from webservice: " + url);
            }
        }
    } catch (HttpException e) {
        LOGGER.error("Error contacting webservice: " + url, e);
    } catch (IOException e) {
        LOGGER.error("Error reading data from webservice: " + url, e);
    } finally {
        if (method != null) {
            method.releaseConnection();
        }
    }
    return null;

}

From source file:com.google.enterprise.connector.sharepoint.wsclient.soap.SPClientFactory.java

private HttpClient createHttpClient(Credentials credentials) {
    HttpClient httpClientToUse = new HttpClient();

    HttpClientParams params = httpClientToUse.getParams();
    // Fix for the Issue[5408782] SharePoint connector fails to traverse a site,
    // circular redirect exception is observed.
    params.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
    // If ALLOW_CIRCULAR_REDIRECTS is set to true, HttpClient throws an
    // exception if a series of redirects includes the same resources more than
    // once. MAX_REDIRECTS allows you to specify a maximum number of redirects
    // to follow.
    params.setIntParameter(HttpClientParams.MAX_REDIRECTS, 10);

    params.setLongParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT, HTTP_CLIENT_TIMEOUT_SECONDS * 1000);
    params.setIntParameter(HttpClientParams.SO_TIMEOUT, HTTP_CLIENT_TIMEOUT_SECONDS * 1000);
    httpClientToUse.getState().setCredentials(AuthScope.ANY, credentials);
    return httpClientToUse;
}

From source file:com.bigdata.rdf.sail.remoting.GraphRepositoryClient.java

private HttpClient getHttpClient() {
    if (httpClient == null) {
        httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());

        httpClient.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, new Integer(300000));
        // httpClient.getParams().setParameter(HttpMethodParams.HEAD_BODY_CHECK_TIMEOUT,
        // new Integer(300000));
        httpClient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new NeverRetryHandler());

        httpClient.getParams().setParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT, new Long(300000));

        httpClient.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, new Integer(300000));
        httpClient.getParams().setParameter(HttpConnectionParams.SO_TIMEOUT, new Integer(300000));
    }//from www . j  av a  2  s  .  c  o m
    if (proxyHost != null) {
        httpClient.getHostConfiguration().setProxyHost(proxyHost);
    }
    return httpClient;
}

From source file:org.apache.abdera.protocol.client.AbderaClient.java

/**
 * Sets the timeout in milliseconds used when retrieving an HTTP connection from the HTTP connection manager.
 *///from   w  w w .j a v  a2 s .com
public void setConnectionManagerTimeout(long timeout) {
    client.getParams().setLongParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT, timeout);
}

From source file:org.apache.abdera.protocol.client.AbderaClient.java

/**
 * Returns the timeout in milliseconds used when retrieving an HTTP connection from the HTTP connection manager.
 *///from w  ww . j av a  2  s . com
public long getConnectionManagerTimeout() {
    return client.getParams().getLongParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT, 0);
}

From source file:org.kuali.mobility.athletics.service.AthleticsServiceImpl.java

private InputStream getInputStreamFromGetMethod(GetMethod get) throws Exception {
    get.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false));
    HttpClient httpClient = new HttpClient();
    httpClient.getParams().setParameter(HttpClientParams.SO_TIMEOUT, new Integer(socketTimeout));
    httpClient.getParams().setParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT,
            new Long(connectionManagerTimeout));
    httpClient.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT,
            new Integer(connectionTimeout));
    int status = httpClient.executeMethod(get);
    if (status == HttpStatus.SC_OK) {
        return get.getResponseBodyAsStream();
    }//from ww w. j a v  a  2  s  .c o m
    return null;
}

From source file:org.kuali.mobility.knowledgebase.service.KnowledgeBaseServiceImpl.java

private String callKnowledgeBase(String url, RequestEntity requestEntity, boolean isPost) throws Exception {
    String output = null;/*from w w  w  . j a  v  a2s. c o  m*/
    //      Document doc = null;
    //      SAXBuilder builder = new SAXBuilder();
    //      BufferedReader in = null;

    HttpClient client = null;
    client = new HttpClient();
    Credentials defaultcreds = new UsernamePasswordCredentials(this.username, this.password);
    client.getState().setCredentials(new AuthScope("remote.kb.iu.edu", 80, AuthScope.ANY_REALM), defaultcreds);
    HttpMethodBase method = null;
    if (isPost) {
        method = preparePostMethod(url, requestEntity);
    } else {
        method = new GetMethod(url);
    }
    method.setDoAuthentication(true);

    //      int timeout = getSocketTimeout(Constants.RSS_SOCKET_TIMEOUT_SECONDS, Constants.RSS_SOCKET_DEFAULT_TIMEOUT);
    int timeout = getSocketTimeout("blah", 5000);
    client.getParams().setParameter(HttpClientParams.SO_TIMEOUT, new Integer(timeout));
    client.getParams().setParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT, new Long(timeout));
    client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, new Integer(timeout));
    try {
        int status = client.executeMethod(method);
        //            System.out.println(status + "\n" + get.getResponseBodyAsString());
        //            in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
        //            doc = builder.build(in);
        output = this.inputStreamToString(method.getResponseBodyAsStream());
    } finally {
        method.releaseConnection();
    }

    return output;
}

From source file:org.kuali.mobility.maps.controllers.MapsController.java

private InputStream getInputStreamFromGetMethod(GetMethod get, int timeout) throws Exception {
    get.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false));
    HttpClient httpClient = new HttpClient();
    httpClient.getParams().setParameter(HttpClientParams.SO_TIMEOUT, new Integer(timeout));
    httpClient.getParams().setParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT, new Long(timeout));
    httpClient.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, new Integer(timeout));
    int status = httpClient.executeMethod(get);
    if (status == HttpStatus.OK.value()) {
        return get.getResponseBodyAsStream();
    }/*from   w  ww.  j  ava2  s . c o m*/
    return null;
}

From source file:org.kuali.rice.kew.config.ThinClientResourceLoader.java

protected void initializeHttpClientParams() {
    httpClientParams = new HttpClientParams();
    configureDefaultHttpClientParams(httpClientParams);
    Properties configProps = ConfigContext.getCurrentContextConfig().getProperties();
    for (Iterator iterator = configProps.keySet().iterator(); iterator.hasNext();) {
        String paramName = (String) iterator.next();
        if (paramName.startsWith("http.")) {
            HttpClientHelper.setParameter(httpClientParams, paramName, (String) configProps.get(paramName));
        }/*from  w ww .ja  va2  s . c o m*/
    }

    String maxConnectionsValue = configProps.getProperty(MAX_CONNECTIONS);
    if (!StringUtils.isEmpty(maxConnectionsValue)) {
        Integer maxConnections = new Integer(maxConnectionsValue);
        Map<HostConfiguration, Integer> maxHostConnectionsMap = new HashMap<HostConfiguration, Integer>();
        maxHostConnectionsMap.put(HostConfiguration.ANY_HOST_CONFIGURATION, maxConnections);
        httpClientParams.setParameter(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, maxHostConnectionsMap);
        httpClientParams.setIntParameter(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, maxConnections);
    }

    String connectionManagerTimeoutValue = configProps.getProperty(CONNECTION_MANAGER_TIMEOUT);
    if (!StringUtils.isEmpty(connectionManagerTimeoutValue)) {
        httpClientParams.setLongParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT,
                new Long(connectionManagerTimeoutValue));
    }

    String connectionTimeoutValue = configProps.getProperty(CONNECTION_TIMEOUT);
    if (!StringUtils.isEmpty(connectionTimeoutValue)) {
        httpClientParams.setIntParameter(HttpConnectionManagerParams.CONNECTION_TIMEOUT,
                new Integer(connectionTimeoutValue));
    }
}

From source file:org.kuali.rice.kew.config.ThinClientResourceLoader.java

protected void configureDefaultHttpClientParams(HttpParams params) {
    params.setParameter(HttpClientParams.CONNECTION_MANAGER_CLASS, MultiThreadedHttpConnectionManager.class);
    params.setParameter(HttpMethodParams.COOKIE_POLICY, CookiePolicy.RFC_2109);
    params.setLongParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT,
            new Long(DEFAULT_CONNECTION_MANAGER_TIMEOUT));
    Map<HostConfiguration, Integer> maxHostConnectionsMap = new HashMap<HostConfiguration, Integer>();
    maxHostConnectionsMap.put(HostConfiguration.ANY_HOST_CONFIGURATION, new Integer(DEFAULT_MAX_CONNECTIONS));
    params.setParameter(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, maxHostConnectionsMap);
    params.setIntParameter(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS,
            new Integer(DEFAULT_MAX_CONNECTIONS));
    params.setIntParameter(HttpConnectionManagerParams.CONNECTION_TIMEOUT,
            new Integer(DEFAULT_CONNECTION_TIMEOUT));

    boolean retrySocketException = new Boolean(
            ConfigContext.getCurrentContextConfig().getProperty(RETRY_SOCKET_EXCEPTION_PROPERTY));
    if (retrySocketException) {
        LOG.info("Installing custom HTTP retry handler to retry requests in face of SocketExceptions");
        params.setParameter(HttpMethodParams.RETRY_HANDLER, new CustomHttpMethodRetryHandler());
    }//  w ww.  j  a  v a  2  s.co m
}