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:ua.at.tsvetkov.data_processor.requests.GetRequest.java

@Override
public InputStream getInputStream() throws IOException {
    if (!isBuild()) {
        throw new IllegalArgumentException(REQUEST_IS_NOT_BUILDED);
    }//from ww w .  j a v a  2 s.  c o m
    startTime = System.currentTimeMillis();

    HttpConnectionParams.setConnectionTimeout(httpParameters, configuration.getTimeout());
    HttpConnectionParams.setSoTimeout(httpParameters, configuration.getTimeout());

    HttpGet httpPost = new HttpGet(toString());
    httpPost.setParams(httpParameters);
    if (header != null) {
        httpPost.addHeader(header);
    }

    printToLogUrl();

    return getResponce(httpPost);
}

From source file:ua.at.tsvetkov.data_processor.requests.PutRequest.java

@Override
public InputStream getInputStream() throws IOException {
    if (!isBuild()) {
        throw new IllegalArgumentException(REQUEST_IS_NOT_BUILDED);
    }//from   w w w  .  j  a v  a  2s.co m
    startTime = System.currentTimeMillis();

    HttpConnectionParams.setConnectionTimeout(httpParameters, configuration.getTimeout());
    HttpConnectionParams.setSoTimeout(httpParameters, configuration.getTimeout());

    HttpPut httpPost = new HttpPut(toString());
    httpPost.setParams(httpParameters);
    if (header != null) {
        httpPost.addHeader(header);
    }

    printToLogUrl();

    return getResponce(httpPost);
}

From source file:com.snda.mymarket.providers.downloads.HttpClientStack.java

@Override
public HttpResponse performRequest(HttpUriRequest httpRequest) throws IOException {
    HttpParams httpParams = httpRequest.getParams();
    // TODO: Reevaluate this connection timeout based on more wide-scale
    // data collection and possibly different for wifi vs. 3G.
    HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MSECONDES);
    HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MSECONDES);

    return mClient.execute(httpRequest);
}

From source file:com.guess.license.plate.Network.ThreadSafeHttpClientFactory.java

private HttpClient createHttpClient() {
    HttpParams httpParams = new BasicHttpParams();
    HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(httpParams, HTTP.DEFAULT_CONTENT_CHARSET);

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    Scheme httpScheme = new Scheme(HTTP_SCHEMA, PlainSocketFactory.getSocketFactory(), HTTP_PORT);
    schemeRegistry.register(httpScheme);

    Scheme httpsScheme = new Scheme(HTTPS_SCHEMA, PlainSocketFactory.getSocketFactory(), HTTPS_PORT);
    schemeRegistry.register(httpsScheme);

    ClientConnectionManager tsConnManager = new ThreadSafeClientConnManager(httpParams, schemeRegistry);
    HttpClient tmpClient = new DefaultHttpClient(tsConnManager, httpParams);

    HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT);
    HttpConnectionParams.setConnectionTimeout(tmpClient.getParams(), TIMEOUT);
    addUserAgent(tmpClient);/*from   w  w w  .  java2s.c  o  m*/

    return tmpClient;
}

From source file:net.alchemiestick.katana.winehqappdb.WineSearch.java

@Override
protected void onPreExecute() {
    String str = "Starting to get data from server";
    tvlist.clear();/*from  w w  w  . j av  a2s  .com*/
    tvlist.add(new str_link(str, ""));
    try {
        httpClient = AndroidHttpClient.newInstance("WineHQ/1.0 App Browser");
        HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), TIMEOUT_MS);
        HttpConnectionParams.setSoTimeout(httpClient.getParams(), TIMEOUT_MS);
    } catch (Exception e) {
        str = "Couldn't set Params0";
        tvlist.add(new str_link(str, ""));
    }
}

From source file:org.bfr.querytools.spectrumbridge.SpectrumBridgeQuery.java

private static HttpClient createClient() {
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
    HttpProtocolParams.setUseExpectContinue(params, true);

    HttpClient client = new DefaultHttpClient(params);

    HttpConnectionParams.setConnectionTimeout(client.getParams(), 10 * 1000);
    HttpConnectionParams.setSoTimeout(client.getParams(), 10 * 1000);

    return client;
}

From source file:nl.coralic.beta.sms.utils.http.HttpHandler.java

private static HttpClient getHttpClient() {
    HttpParams httpParameters = new BasicHttpParams();
    int timeoutConnection = 28000;
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
    int timeoutSocket = 28000;
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
    return new DefaultHttpClient(httpParameters);
}

From source file:com.msopentech.thali.utilities.universal.CreateClientBuilder.java

/**
 *
 * @param host/* ww w. ja v  a 2s .  c  o m*/
 * @param port
 * @param serverPublicKey If null then the server won't be validated
 * @return
 */
public HttpClient CreateApacheClient(String host, int port, PublicKey serverPublicKey, KeyStore clientKeyStore,
        char[] clientKeyStorePassPhrase, Proxy proxy)
        throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
    //  sslSocketFactory
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setUseExpectContinue(params, false); // Work around for bug in TJWS, it doesn't properly
                                                            // support ExpectContinue
    HttpConnectionParams.setSoTimeout(params, timeout);
    HttpConnectionParams.setConnectionTimeout(params, timeout);
    HttpConnectionParams.setTcpNoDelay(params, Boolean.TRUE);
    params.setParameter(ClientPNames.DEFAULT_HOST, new HttpHost(host, port, "https"));

    HttpKeyHttpClient httpKeyHttpClient = new HttpKeyHttpClient(serverPublicKey, clientKeyStore,
            clientKeyStorePassPhrase, proxy, params);
    return httpKeyHttpClient;
}

From source file:fr.eoidb.util.AndroidUrlDownloader.java

@Override
public InputStream urlToInputStream(Context context, String url) throws DownloadException {

    if (!isNetworkAvailable(context)) {
        throw new DownloadException("No internet connection!");
    }/*from   w  w  w  .j a  v  a2s. c  o  m*/

    try {
        HttpParams httpParameters = new BasicHttpParams();
        // Set the timeout in milliseconds until a connection is established.
        // The default value is zero, that means the timeout is not used.
        int timeoutConnection = 3000;
        HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
        // Set the default socket timeout (SO_TIMEOUT)
        // in milliseconds which is the timeout for waiting for data.
        int timeoutSocket = 5000;
        HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

        HttpClient httpclient = new DefaultHttpClient(httpParameters);

        HttpGet httpget = new HttpGet(url);
        httpget.addHeader("Accept-Encoding", "gzip");

        HttpResponse response;

        response = httpclient.execute(httpget);
        Log.v(LOG_TAG, response.getStatusLine().toString());

        HttpEntity entity = response.getEntity();

        final int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            String message = "Error " + statusCode + " while retrieving url " + url;
            Log.w("AndroidUrlDownloader", message);
            throw new DownloadException(message);
        }

        if (entity != null) {

            InputStream instream = entity.getContent();
            Header contentEncoding = response.getFirstHeader("Content-Encoding");
            if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
                Log.v(LOG_TAG, "Accepting gzip for url : " + url);
                instream = new GZIPInputStream(instream);
            }

            return instream;
        }

    } catch (IllegalStateException e) {
        throw new DownloadException(e);
    } catch (IOException e) {
        throw new DownloadException(e);
    }

    return null;
}

From source file:com.geeksville.location.LeonardoUpload.java

/**
 * Upload a flight to Leonardo// ww w .  ja v  a 2  s. c om
 * 
 * @param username
 * @param password
 * @param postURL
 * @param shortFilename
 * @param igcFile
 *            we will take care of closing this stram
 * @return null for success, otherwise a string description of the problem
 * @throws IOException
 */
public static String upload(String username, String password, String postURL, int competitionClass,
        String shortFilename, String igcFile, int connectionTimeout, int operationTimeout) throws IOException {

    // Strip off extension (leonado docs say they don't want it
    int i = shortFilename.lastIndexOf('.');
    if (i >= 1)
        shortFilename = shortFilename.substring(0, i);
    String sCompetitionClass = String.valueOf(competitionClass);
    HttpParams httpParameters = new BasicHttpParams();
    // Set the timeout in milliseconds until a connection is established.
    HttpConnectionParams.setConnectionTimeout(httpParameters, connectionTimeout);
    // Set the default socket timeout (SO_TIMEOUT) 
    // in milliseconds which is the timeout for waiting for data.
    HttpConnectionParams.setSoTimeout(httpParameters, operationTimeout);

    HttpClient httpclient = new DefaultHttpClient(httpParameters);
    httpclient.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
    HttpPost httppost = new HttpPost(postURL);
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("user", username));
    nameValuePairs.add(new BasicNameValuePair("pass", password));
    nameValuePairs.add(new BasicNameValuePair("igcfn", shortFilename));
    nameValuePairs.add(new BasicNameValuePair("Klasse", sCompetitionClass));
    nameValuePairs.add(new BasicNameValuePair("IGCigcIGC", igcFile));
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

    HttpResponse response = httpclient.execute(httppost);
    HttpEntity entity = response.getEntity();

    String resp = EntityUtils.toString(entity);

    // An error looks like:
    // <html><body>problem<br>This is not a valid .igc
    // file</body></html>

    // Check for success
    if (resp.contains("flight scored"))
        resp = null;
    else {
        int bodLoc = resp.indexOf("<body>");
        if (bodLoc >= 0)
            resp = resp.substring(bodLoc + 6);
        int probLoc = resp.indexOf("problem");
        if (probLoc >= 0)
            resp = resp.substring(probLoc + 7);
        if (resp.startsWith("<br>"))
            resp = resp.substring(4);
        int markLoc = resp.indexOf('<');
        if (markLoc >= 0)
            resp = resp.substring(0, markLoc);
        resp = resp.trim();
    }

    return resp;
}