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

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

Introduction

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

Prototype

public static void setConnectionTimeout(HttpParams httpParams, int i) 

Source Link

Usage

From source file:com.thistech.spotlink.util.HttpClientFactory.java

public HttpClient newInstance() {
    HttpClient client = new DefaultHttpClient();
    HttpParams httpParams = client.getParams();
    HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);

    if (this.properties.containsKey("httpclient.timeout")) {
        int timeout = Integer.parseInt(this.properties.getProperty("httpclient.timeout"));
        HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
        HttpConnectionParams.setSoTimeout(httpParams, timeout);
    }/*w w  w  .ja  va 2  s  .  c o  m*/

    ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRoute() {
        public int getMaxForRoute(HttpRoute route) {
            return Integer.parseInt(properties.getProperty("httpclient.conn-per-route", "5"));
        }
    });

    int totalConnections = Integer.parseInt(this.properties.getProperty("httpclient.total-connections", "100"));
    ConnManagerParams.setMaxTotalConnections(httpParams, totalConnections);

    String userAgent = this.properties.getProperty("httpclient.user-agent", "Mozilla/5.0");
    HttpProtocolParams.setUserAgent(httpParams, userAgent);

    String charset = this.properties.getProperty("httpclient.content-charset", "UTF-8");
    HttpProtocolParams.setContentCharset(httpParams, charset);

    ClientConnectionManager mgr = client.getConnectionManager();
    SchemeRegistry schemeRegistry = mgr.getSchemeRegistry();
    client = new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, schemeRegistry), httpParams);
    return client;
}

From source file:org.apache.olingo.samples.client.core.http.ParametersHttpClientFactory.java

@Override
public DefaultHttpClient create(final HttpMethod method, final URI uri) {
    final DefaultHttpClient httpClient = super.create(method, uri);

    httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
    httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8");

    final int timeout = 1000;
    HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), timeout);
    HttpConnectionParams.setSoTimeout(httpClient.getParams(), timeout);

    return httpClient;
}

From source file:com.google.resting.rest.client.HttpContext.java

public HttpContext setConnectionTimeout(int connectionTimeout) {
    HttpConnectionParams.setConnectionTimeout(httpParams, connectionTimeout);
    return this;
}

From source file:com.intel.cosbench.client.http.HttpClientUtil.java

private static HttpParams createDefaultHttpParams(int timeout) {
    HttpParams params = new BasicHttpParams();
    /* default HTTP parameters */
    DefaultHttpClient.setDefaultHttpParams(params);
    /* connection/socket timeouts */
    HttpConnectionParams.setSoTimeout(params, timeout);
    HttpConnectionParams.setConnectionTimeout(params, timeout);
    /* user agent */
    HttpProtocolParams.setUserAgent(params, "cosbench/2.0");
    return params;
}

From source file:com.aikidonord.utils.HttpRequest.java

public HttpRequest() {
    HttpParams myParams = new BasicHttpParams();

    HttpConnectionParams.setConnectionTimeout(myParams, 10000);
    HttpConnectionParams.setSoTimeout(myParams, 10000);
    httpClient = new DefaultHttpClient(myParams);
    localContext = new BasicHttpContext();
}

From source file:ro.razius.vianet.LoginTask.java

@Override
protected Void doInBackground(String... params) {
    // set the connection and socket timeouts
    HttpParams httpParameters = new BasicHttpParams();
    int timeoutConnection = 3000;
    int timeoutSocket = 5000;
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

    // build out GET URL
    List<NameValuePair> postParams = new LinkedList<NameValuePair>();
    postParams.add(new BasicNameValuePair(userParam, params[0]));
    postParams.add(new BasicNameValuePair(passParam, params[1]));

    HttpPost httppost = new HttpPost(authURL);

    // finally do the GET request to login to the ISA Server
    DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
    try {// w  w w. j a  v a  2 s  .  co m
        Log.d(TAG, "Trying to auth with: " + authURL);
        httppost.setEntity(new UrlEncodedFormEntity(postParams));
        HttpResponse response = httpClient.execute(httppost);
        Log.d(TAG, "HTTP Response: " + response.getStatusLine().toString());
    } catch (Exception e) {
        Log.d(TAG, e.toString()); // no use for errors
    }
    return null;
}

From source file:ru.altruix.commons.android.WebServiceTaskHelper.java

@Override
public HttpParams getHttpParams() {

    final HttpParams htpp = new BasicHttpParams();

    HttpConnectionParams.setConnectionTimeout(htpp, CONN_TIMEOUT);
    HttpConnectionParams.setSoTimeout(htpp, SOCKET_TIMEOUT);

    return htpp;/*w ww. java 2 s. c om*/
}

From source file:com.wareninja.opensource.gravatar4android.common.Utils.java

public static String downloadProfile(String profileUrl) throws GenericException {

    String response = "";

    HttpParams myParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(myParams, TIMEOUT);
    HttpConnectionParams.setSoTimeout(myParams, TIMEOUT);

    DefaultHttpClient httpClient = new DefaultHttpClient(myParams);

    HttpGet httpGet = new HttpGet(profileUrl);
    if (CONSTANTS.DEBUG)
        Log.d(TAG, "WebGetURL: " + profileUrl);

    HttpResponse httpResponse = null;//from  w w w. j  a v  a 2  s . c om
    try {
        httpResponse = httpClient.execute(httpGet);

        response = EntityUtils.toString(httpResponse.getEntity());
    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
        throw new GenericException(e);
    }

    return response;
}

From source file:com.entertailion.android.dial.HttpRequestHelper.java

public static DefaultHttpClient createHttpClient() {
    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, 20000);
    HttpConnectionParams.setSoTimeout(params, 20000);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);

    SchemeRegistry schReg = new SchemeRegistry();
    schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);

    return new DefaultHttpClient(conMgr, params);
}

From source file:ch.tatool.core.module.creator.FileDownloadWorker.java

/** Loads the module file from the data server using the provided code. */
public void loadFile(String url, int timeout) {
    // give it a timeout to ensure the user does not wait forever in case of connectivity problems
    HttpParams params = new BasicHttpParams();
    if (timeout > 0) {
        HttpConnectionParams.setConnectionTimeout(params, timeout);
        HttpConnectionParams.setSoTimeout(params, timeout);
    }//from ww  w. j a v a2 s. com

    // remove whitespaces since they are not allowed
    url = url.replaceAll("\\s+", "").trim();

    // create a http client
    DefaultHttpClient httpclient = new DefaultHttpClient(params);
    HttpGet httpGet = new HttpGet(url);

    errorTitle = null;
    errorText = null;
    file = null;
    try {
        HttpResponse response = httpclient.execute(httpGet);
        if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            errorTitle = messages.getString("General.errorMessage.windowTitle.error");
            errorText = messages.getString("DataExportError.online.http");
            errorText += "\n" + response.getStatusLine().getReasonPhrase() + " ("
                    + response.getStatusLine().getStatusCode() + ")";
        } else {
            // copy the response into a temporary file
            HttpEntity entity = response.getEntity();
            byte[] data = EntityUtils.toByteArray(entity);
            File tmpFile = File.createTempFile("tatool_module", "tmp");
            FileUtils.writeByteArrayToFile(tmpFile, data);
            tmpFile.deleteOnExit();
            this.file = tmpFile;
        }
    } catch (IOException ioe) {
        errorTitle = messages.getString("General.errorMessage.windowTitle.error");
        errorText = messages.getString("DataExportError.online.http");
    } finally {
        // make sure we close the connection manager
        httpclient.getConnectionManager().shutdown();
    }
}