Example usage for org.apache.commons.httpclient.params HttpConnectionParams setSoTimeout

List of usage examples for org.apache.commons.httpclient.params HttpConnectionParams setSoTimeout

Introduction

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

Prototype

public void setSoTimeout(int paramInt) 

Source Link

Usage

From source file:edu.internet2.middleware.shibboleth.idp.profile.saml2.SLOProfileHandler.java

/**
 * Creates Http connection./*from  w w  w . j ava 2  s .c om*/
 *
 * @param serviceLogoutInfo
 * @param endpoint
 * @return
 * @throws URIException
 * @throws GeneralSecurityException
 * @throws IOException
 */
private HttpConnection createHttpConnection(LogoutInformation serviceLogoutInfo, Endpoint endpoint)
        throws URIException, GeneralSecurityException, IOException {

    HttpClientBuilder httpClientBuilder = new HttpClientBuilder();
    httpClientBuilder.setContentCharSet("UTF-8");
    SecureProtocolSocketFactory sf = new EasySSLProtocolSocketFactory();
    httpClientBuilder.setHttpsProtocolSocketFactory(sf);

    //build http connection
    HttpClient httpClient = httpClientBuilder.buildClient();

    HostConfiguration hostConfig = new HostConfiguration();
    URI location = new URI(endpoint.getLocation());
    hostConfig.setHost(location);

    LogoutRequestConfiguration config = (LogoutRequestConfiguration) getProfileConfiguration(
            serviceLogoutInfo.getEntityID(), getProfileId());
    if (log.isDebugEnabled()) {
        log.debug("Creating new HTTP connection with the following timeouts:");
        log.debug("Maximum waiting time for the connection pool is {}",
                config.getBackChannelConnectionPoolTimeout());
        log.debug("Timeout for connection establishment is {}", config.getBackChannelConnectionTimeout());
        log.debug("Timeout for soap response is {}", config.getBackChannelResponseTimeout());
    }
    HttpConnection httpConn = null;
    try {
        httpConn = httpClient.getHttpConnectionManager().getConnectionWithTimeout(hostConfig,
                config.getBackChannelConnectionPoolTimeout());
    } catch (ConnectionPoolTimeoutException e) {
        return null;
    }

    HttpConnectionParams params = new HttpConnectionParams();
    params.setConnectionTimeout(config.getBackChannelConnectionTimeout());
    params.setSoTimeout(config.getBackChannelResponseTimeout());
    httpConn.setParams(params);

    return httpConn;
}

From source file:org.olat.core.util.httpclient.HttpClientFactory.java

/**
 * A HttpClient with basic authentication and no host or port setting. Can only be used to retrieve absolute URLs
 * /*from  w w w . j  a v a2s.  c o m*/
 * @param user can be NULL
 * @param password can be NULL
 * @return HttpClient
 */
public static HttpClient getHttpClientInstance(String user, String password) {
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionParams params = connectionManager.getParams();
    // wait max 10 seconds to establish connection
    params.setConnectionTimeout(10000);
    // a read() call on the InputStream associated with this Socket
    // will block for only this amount
    params.setSoTimeout(10000);
    HttpClient c = new HttpClient(connectionManager);

    // use basic authentication if available
    if (user != null && user.length() > 0) {
        AuthScope authScope = new AuthScope(null, -1, null);
        Credentials credentials = new UsernamePasswordCredentials(user, password);
        c.getState().setCredentials(authScope, credentials);
    }
    return c;
}