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

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

Introduction

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

Prototype

public static void setStaleCheckingEnabled(HttpParams httpParams, boolean z) 

Source Link

Usage

From source file:at.bitfire.davdroid.webdav.DavHttpClient.java

public static DefaultHttpClient getDefault() {
    HttpParams params = new BasicHttpParams();
    params.setParameter(CoreProtocolPNames.USER_AGENT, "DAVdroid/" + Constants.APP_VERSION);

    // use defaults of AndroidHttpClient
    HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
    HttpConnectionParams.setSoTimeout(params, 20 * 1000);
    HttpConnectionParams.setSocketBufferSize(params, 8192);
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    // don't allow redirections
    HttpClientParams.setRedirecting(params, false);

    DavHttpClient httpClient = new DavHttpClient(params);

    // use our own, SNI-capable LayeredSocketFactory for https://
    SchemeRegistry schemeRegistry = httpClient.getConnectionManager().getSchemeRegistry();
    schemeRegistry.register(new Scheme("https", new TlsSniSocketFactory(), 443));

    // allow gzip compression
    GzipDecompressingEntity.enable(httpClient);
    return httpClient;
}

From source file:com.mobicage.rogerthat.util.http.HTTPUtil.java

public static HttpClient getHttpClient(int connectionTimeout, int socketTimeout, final int retryCount) {
    final HttpParams params = new BasicHttpParams();

    HttpConnectionParams.setStaleCheckingEnabled(params, true);
    HttpConnectionParams.setConnectionTimeout(params, connectionTimeout);
    HttpConnectionParams.setSoTimeout(params, socketTimeout);

    HttpClientParams.setRedirecting(params, false);

    final DefaultHttpClient httpClient = new DefaultHttpClient(params);

    if (shouldUseTruststore()) {
        KeyStore trustStore = loadTrustStore();

        SSLSocketFactory socketFactory;
        try {/* www. ja va2  s  .c  o  m*/
            socketFactory = new SSLSocketFactory(null, null, trustStore);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        socketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);

        Scheme sch = new Scheme("https", socketFactory, CloudConstants.HTTPS_PORT);
        httpClient.getConnectionManager().getSchemeRegistry().register(sch);
    }

    if (retryCount > 0) {
        httpClient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
            @Override
            public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
                return executionCount < retryCount;
            }
        });
    }
    return httpClient;
}

From source file:org.pixmob.appengine.client.SSLEnabledHttpClient.java

public static SSLEnabledHttpClient newInstance(String userAgent) {
    // the following code comes from AndroidHttpClient (API level 10)

    final HttpParams params = new BasicHttpParams();

    // Turn off stale checking. Our connections break all the time anyway,
    // and it's not worth it to pay the penalty of checking every time.
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    final int timeout = 60 * 1000;
    HttpConnectionParams.setConnectionTimeout(params, timeout);
    HttpConnectionParams.setSoTimeout(params, timeout);
    HttpConnectionParams.setSocketBufferSize(params, 8192);

    // Don't handle redirects -- return them to the caller. Our code
    // often wants to re-POST after a redirect, which we must do ourselves.
    HttpClientParams.setRedirecting(params, false);

    // Set the specified user agent and register standard protocols.
    HttpProtocolParams.setUserAgent(params, userAgent);

    // Prevent UnknownHostException error with 3G connections:
    // http://stackoverflow.com/questions/2052299/httpclient-on-android-nohttpresponseexception-through-umts-3g
    HttpProtocolParams.setUseExpectContinue(params, false);

    final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

    final SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));

    final ClientConnectionManager manager = new SingleClientConnManager(params, schemeRegistry);
    final SSLEnabledHttpClient client = new SSLEnabledHttpClient(manager, params);
    client.addRequestInterceptor(new GzipRequestInterceptor());
    client.addResponseInterceptor(new GzipResponseInterceptor());

    return client;
}

From source file:com.blacklocus.sample.time.HttpClientFactory.java

/**
 * Construct a new HttpClient which uses the {@link #POOL_MGR default connection pool}.
 *
 * @param connectionTimeout highly sensitive to application so must be specified
 * @param socketTimeout highly sensitive to application so must be specified
 */// ww  w  . j ava2  s  . c om
public static HttpClient createHttpClient(final int connectionTimeout, final int socketTimeout) {
    return new DefaultHttpClient(POOL_MGR) {
        {
            HttpParams httpParams = getParams();

            // prevent seg fault JVM bug, see https://code.google.com/p/crawler4j/issues/detail?id=136
            httpParams.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);

            HttpConnectionParams.setConnectionTimeout(httpParams, connectionTimeout);
            HttpConnectionParams.setSoTimeout(httpParams, socketTimeout);
            HttpConnectionParams.setStaleCheckingEnabled(httpParams, true);

        }
    };
}

From source file:com.squeezecontrol.image.HttpFetchingImageStore.java

public HttpFetchingImageStore(String baseUrl, String username, String password) {
    this.baseUrl = baseUrl;

    HttpParams params = new BasicHttpParams();

    // Turn off stale checking. Our connections break all the time anyway,
    // and it's not worth it to pay the penalty of checking every time.
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    // Default connection and socket timeout of 20 seconds. Tweak to taste.
    HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
    HttpConnectionParams.setSoTimeout(params, 20 * 1000);
    HttpConnectionParams.setSocketBufferSize(params, 8192);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

    ClientConnectionManager mgr = new ThreadSafeClientConnManager(params, schemeRegistry);
    mClient = new DefaultHttpClient(mgr, params);
    if (username != null && !"".equals(username)) {
        Credentials defaultcreds = new UsernamePasswordCredentials("dag", "test");
        mClient.getCredentialsProvider().setCredentials(AuthScope.ANY, defaultcreds);
    }//from w  ww .  jav a  2s. c o  m
}

From source file:com.dubsar_dictionary.SecureClient.SecureAndroidHttpClient.java

/**
 * Create a new HttpClient with reasonable defaults (which you can update).
 * (Lifted and modified from AndroidHttpClient.)
 *
 * @param userAgent to report in your HTTP requests
 * @param context to use for caching SSL sessions (may be null for no caching)
 * @return AndroidHttpClient for you to use for all your requests.
 *//*from   w  w w.j a v  a  2s.c o m*/
public static HttpClient newInstance(String userAgent) {
    Log.d(TAG, "Creating new client instance");

    HttpParams params = new BasicHttpParams();

    // Turn off stale checking.  Our connections break all the time anyway,
    // and it's not worth it to pay the penalty of checking every time.
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    HttpConnectionParams.setConnectionTimeout(params, SOCKET_OPERATION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, SOCKET_OPERATION_TIMEOUT);
    HttpConnectionParams.setSocketBufferSize(params, 8192);

    // Default to following redirects
    HttpClientParams.setRedirecting(params, true);

    // Set the specified user agent and register standard protocols.
    HttpProtocolParams.setUserAgent(params, userAgent);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    SSLSocketFactory sf = SecureSocketFactory.getHttpSocketFactory(SOCKET_OPERATION_TIMEOUT);
    schemeRegistry.register(new Scheme("https", sf, 443));
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));

    ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);

    // We use a factory method to modify superclass initialization
    // parameters without the funny call-a-static-method dance.
    return new SecureAndroidHttpClient(manager, params);
}

From source file:com.google.api.client.apache.ApacheHttpTransport.java

ApacheHttpTransport() {
    // Turn off stale checking. Our connections break all the time anyway,
    // and it's not worth it to pay the penalty of checking every time.
    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setStaleCheckingEnabled(params, false);
    // Default connection and socket timeout of 20 seconds. Tweak to taste.
    HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
    HttpConnectionParams.setSoTimeout(params, 20 * 1000);
    HttpConnectionParams.setSocketBufferSize(params, 8192);
    this.httpClient = new DefaultHttpClient(params);
}

From source file:com.google.android.apps.authenticator.testability.HttpClientFactory.java

private static void configureHttpClient(HttpClient httpClient) {
    HttpParams params = httpClient.getParams();
    HttpConnectionParams.setStaleCheckingEnabled(params, false);
    HttpConnectionParams.setConnectionTimeout(params, DEFAULT_CONNECT_TIMEOUT_MILLIS);
    HttpConnectionParams.setSoTimeout(params, DEFAULT_READ_TIMEOUT_MILLIS);
    HttpConnectionParams.setSocketBufferSize(params, 8192);
    ConnManagerParams.setTimeout(params, DEFAULT_GET_CONNECTION_FROM_POOL_TIMEOUT_MILLIS);

    // Don't handle redirects automatically
    HttpClientParams.setRedirecting(params, false);

    // Don't handle authentication automatically
    HttpClientParams.setAuthenticating(params, false);
}

From source file:com.application.food.zxing.client.android.AndroidHttpClient.java

/**
 * Create a new HttpClient with reasonable defaults (which you can update).
 *
 * @param userAgent to report in your HTTP requests.
 * @return AndroidHttpClient for you to use for all your requests.
 *///from   ww  w.  ja v  a2  s  .co  m
public static AndroidHttpClient newInstance(String userAgent) {
    HttpParams params = new BasicHttpParams();

    // Turn off stale checking.  Our connections break all the time anyway,
    // and it's not worth it to pay the penalty of checking every time.
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    // Default connection and socket timeout of 20 seconds.  Tweak to taste.
    HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
    HttpConnectionParams.setSoTimeout(params, 20 * 1000);
    HttpConnectionParams.setSocketBufferSize(params, 8192);

    // Don't handle redirects -- return them to the caller.  Our code
    // often wants to re-POST after a redirect, which we must do ourselves.
    HttpClientParams.setRedirecting(params, false);

    // Set the specified user agent and register standard protocols.
    if (userAgent != null) {
        HttpProtocolParams.setUserAgent(params, userAgent);
    }
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);

    // We use a factory method to modify superclass initialization
    // parameters without the funny call-a-static-method dance.
    return new AndroidHttpClient(manager, params);
}

From source file:org.andstatus.app.net.http.MisconfiguredSslHttpClientFactory.java

private static HttpParams getHttpParams() {
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
    HttpConnectionParams.setStaleCheckingEnabled(params, true);

    HttpProtocolParams.setUseExpectContinue(params, false);
    HttpConnectionParams.setSoTimeout(params, MyPreferences.getConnectionTimeoutMs());
    HttpConnectionParams.setSocketBufferSize(params, 2 * 8192);
    return params;
}