Example usage for org.apache.http.params HttpConnectionParamBean setConnectionTimeout

List of usage examples for org.apache.http.params HttpConnectionParamBean setConnectionTimeout

Introduction

In this page you can find the example usage for org.apache.http.params HttpConnectionParamBean setConnectionTimeout.

Prototype

public void setConnectionTimeout(int i) 

Source Link

Usage

From source file:org.piraso.ui.base.manager.HttpUpdateManager.java

public static HttpUpdateManager create() {
    ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager();
    manager.setDefaultMaxPerRoute(1);//from   www. j  ava2  s.co  m
    manager.setMaxTotal(1);

    HttpParams params = new BasicHttpParams();

    // set timeout
    HttpConnectionParamBean connParamBean = new HttpConnectionParamBean(params);
    connParamBean.setConnectionTimeout(3000);
    connParamBean.setSoTimeout(1000 * 60 * 120);

    HttpClient client = new DefaultHttpClient(manager, params);
    HttpContext context = new BasicHttpContext();

    return new HttpUpdateManager(client, context);
}

From source file:com.alu.e3.gateway.loadbalancer.HttpLoadBalancerProducer.java

protected HttpRequestBase createMethod(Exchange exchange) throws URISyntaxException, CamelExchangeException {
    HttpRequestBase httpRequest = super.createMethod(exchange);
    HttpParams params = httpRequest.getParams();

    Integer connectionTimeout = exchange.getProperty(ExchangeConstantKeys.E3_HTTP_CONNECTION_TIMEOUT.toString(),
            E3Constant.DEFAULT_HTTP_CONNECTION_TIMETOUT, Integer.class);
    Integer socketTimeout = exchange.getProperty(ExchangeConstantKeys.E3_HTTP_SOCKET_TIMEOUT.toString(),
            E3Constant.DEFAULT_HTTP_SOCKET_TIMEOUT, Integer.class);

    HttpConnectionParamBean httpConnectionParamBean = new HttpConnectionParamBean(params);

    httpConnectionParamBean.setConnectionTimeout(connectionTimeout);

    httpConnectionParamBean.setSoTimeout(socketTimeout);

    exchange.getIn().setHeader(HttpHeaders.HOST, httpRequest.getURI().getHost());

    return httpRequest;
}

From source file:org.piraso.io.impl.HttpEntrySource.java

private void initReader() {
    alive = false;/*from ww  w.jav a 2 s  .  c o  m*/

    ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager();
    manager.setDefaultMaxPerRoute(2);
    manager.setMaxTotal(2);

    HttpParams params = new BasicHttpParams();

    // set timeout
    HttpConnectionParamBean connParamBean = new HttpConnectionParamBean(params);
    connParamBean.setConnectionTimeout(3000);
    connParamBean.setSoTimeout(1000 * 60 * 120);

    HttpClient client = new DefaultHttpClient(manager, params);
    HttpContext context = new BasicHttpContext();

    this.reader = new HttpPirasoEntryReader(client, context);

    reader.setUri(uri);
    reader.getStartHandler().setPreferences(preferences);

    if (watchedAddr != null) {
        reader.getStartHandler().setWatchedAddr(watchedAddr);
    }
}

From source file:org.xmlsh.internal.commands.http.java

private void setOptions(DefaultHttpClient client, HttpHost host, Options opts)
        throws KeyManagementException, NoSuchAlgorithmException, UnrecoverableKeyException,
        CertificateException, FileNotFoundException, KeyStoreException, IOException {

    HttpParams params = client.getParams();
    HttpConnectionParamBean connection = new HttpConnectionParamBean(params);

    if (opts.hasOpt("connectTimeout"))
        connection.setConnectionTimeout((int) (opts.getOptDouble("connectTimeout", 0) * 1000.));

    if (opts.hasOpt("readTimeout"))
        connection.setSoTimeout((int) (opts.getOptDouble("readTimeout", 0) * 1000.));

    /*/*from  w  w  w .  j ava 2 s  .c om*/
     * if( opts.hasOpt("useCaches"))
     * client.setUseCaches( opts.getOpt("useCaches").getFlag());
     * 
     * 
     * if( opts.hasOpt("followRedirects"))
     * 
     * client.setInstanceFollowRedirects(
     * opts.getOpt("followRedirects").getFlag());
     * 
     * 
     * 
     * 
     * 
     * 
     * String disableTrustProto = opts.getOptString("disableTrust", null);
     * 
     * String keyStore = opts.getOptString("keystore", null);
     * String keyPass = opts.getOptString("keypass", null);
     * String sslProto = opts.getOptString("sslProto", "SSLv3");
     * 
     * if(disableTrustProto != null && client instanceof HttpsURLConnection )
     * disableTrust( (HttpsURLConnection) client , disableTrustProto );
     * 
     * else
     * if( keyStore != null )
     * setClient( (HttpsURLConnection) client , keyStore , keyPass , sslProto );
     * 
     */

    String disableTrustProto = opts.getOptString("disableTrust", null);

    if (disableTrustProto != null)
        disableTrust(client, disableTrustProto);

    String user = opts.getOptString("user", null);
    String pass = opts.getOptString("password", null);
    if (user != null && pass != null) {
        UsernamePasswordCredentials creds = new UsernamePasswordCredentials(user, pass);

        client.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
        /*
         * // Create AuthCache instance
         * AuthCache authCache = new BasicAuthCache();
         * // Generate DIGEST scheme object, initialize it and add it to the local
         * // auth cache
         * DigestScheme digestAuth = new DigestScheme();
         * // Suppose we already know the realm name
         * digestAuth.overrideParamter("realm", "some realm");
         * // Suppose we already know the expected nonce value
         * digestAuth.overrideParamter("nonce", "whatever");
         * authCache.put(host, digestAuth);
         * 
         * // Add AuthCache to the execution context
         * BasicHttpContext localcontext = new BasicHttpContext();
         * localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);
         */

    }

}

From source file:com.alu.e3.gateway.loadbalancer.E3HttpClientConfigurer.java

@Override
public void configureHttpClient(HttpClient httpClient) {

    ClientConnectionManager clientConnectionManager = httpClient.getConnectionManager();
    HttpParams params = httpClient.getParams();

    // set Connection Pool Manager
    if (clientConnectionManager instanceof ThreadSafeClientConnManager) {
        setThreadSafeConnectionManager(clientConnectionManager);
    } else {/*from   w w w  .  jav  a  2  s . c o  m*/
        LOGGER.error(
                "The given settings for the HttpClient connection pool will be ignored: Unsupported implementation");
    }

    // set HttpClient global setting
    HttpConnectionParamBean httpConnectionParamBean = new HttpConnectionParamBean(params);
    if (getSocketTimeOut() != null) {
        httpConnectionParamBean.setSoTimeout(getSocketTimeOut());
    }
    // set HttpClient global connection timeout      
    if (getConnectionTimeOut() != null) {
        httpConnectionParamBean.setConnectionTimeout(getConnectionTimeOut());
    }

    // set HttpClient Proxy settings
    if (getForwardProxy() != null) {
        setForwardProxy(httpClient, params);
    }
}