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

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

Introduction

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

Prototype

public static void setSocketBufferSize(HttpParams httpParams, int i) 

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:org.zywx.wbpalmstar.engine.eservice.EServiceTest.java

public static void test() {
    String realyPath = "http://localhost:8000/other.QDV";
    HttpRequestBase mHhttpRequest = new HttpGet(realyPath);
    mHhttpRequest.addHeader("range", "bytes=34199-");
    BasicHttpParams bparams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(bparams, 20000);
    HttpConnectionParams.setSoTimeout(bparams, 20000);
    HttpConnectionParams.setSocketBufferSize(bparams, 8 * 1024);
    HttpClientParams.setRedirecting(bparams, true);
    DefaultHttpClient mDefaultHttpClient = new DefaultHttpClient(bparams);
    HttpResponse response = null;//from  ww w.  j  a  v  a 2s  . com
    try {
        response = mDefaultHttpClient.execute(mHhttpRequest);

        int responseCode = response.getStatusLine().getStatusCode();
        byte[] arrayOfByte = null;
        HttpEntity httpEntity = response.getEntity();
        if (responseCode == 200 || responseCode == 206) {
            arrayOfByte = toByteArray(httpEntity);
            String m = new String(arrayOfByte, "UTF-8");
            Log.i("ldx", "" + m.length());
            Log.i("ldx", m);
            return;

        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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.onemorecastle.util.HttpFetch.java

public static Bitmap fetchBitmap(String imageAddress, int sampleSize)
        throws MalformedURLException, IOException {
    Bitmap bitmap = null;//from w  w w. jav a 2  s . c om
    DefaultHttpClient httpclient = null;
    try {
        HttpParams httpParameters = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParameters, 2000);
        HttpConnectionParams.setSoTimeout(httpParameters, 5000);
        HttpConnectionParams.setSocketBufferSize(httpParameters, 512);
        HttpGet httpRequest = new HttpGet(URI.create(imageAddress));
        httpclient = new DefaultHttpClient();
        httpclient.setParams(httpParameters);
        HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
        HttpEntity entity = response.getEntity();
        BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
        InputStream instream = bufHttpEntity.getContent();
        BitmapFactory.Options options = new BitmapFactory.Options();
        //first decode with inJustDecodeBounds=true to check dimensions
        options.inJustDecodeBounds = true;
        options.inSampleSize = sampleSize;
        BitmapFactory.decodeStream(instream, null, options);
        //decode bitmap with inSampleSize set
        options.inSampleSize = calculateInSampleSize(options, MAX_WIDTH, MAX_HEIGHT);
        options.inPurgeable = true;
        options.inInputShareable = true;
        options.inDither = true;
        options.inJustDecodeBounds = false;
        //response=(HttpResponse)httpclient.execute(httpRequest);
        //entity=response.getEntity();
        //bufHttpEntity=new BufferedHttpEntity(entity);
        instream = bufHttpEntity.getContent();
        bitmap = BitmapFactory.decodeStream(instream, null, options);
        //close out stuff
        try {
            instream.close();
            bufHttpEntity.consumeContent();
            entity.consumeContent();
        } finally {
            instream = null;
            bufHttpEntity = null;
            entity = null;
        }
    } catch (Exception x) {
        Log.e("HttpFetch.fetchBitmap", imageAddress, x);
    } finally {
        httpclient = null;
    }
    return (bitmap);
}

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);
    }// ww  w .  j  a  v  a2s  . c o m
}

From source file:com.blork.anpod.util.SyncUtils.java

/**
 * Generate and return a {@link HttpClient} configured for general use,
 * including setting an application-specific user-agent string.
 *
 * @param context the context/*from ww w  . j ava 2 s. c o  m*/
 * @return the http client
 */
static HttpClient getHttpClient(Context context) {
    final HttpParams params = new BasicHttpParams();

    // Use generous timeouts for slow mobile networks
    HttpConnectionParams.setConnectionTimeout(params, 20 * SECOND_IN_MILLIS);
    HttpConnectionParams.setSoTimeout(params, 20 * SECOND_IN_MILLIS);

    HttpConnectionParams.setSocketBufferSize(params, 8192);
    HttpProtocolParams.setUserAgent(params, buildUserAgent(context));

    final DefaultHttpClient client = new DefaultHttpClient(params);

    client.addRequestInterceptor(new HttpRequestInterceptor() {
        public void process(HttpRequest request, HttpContext context) {
            // Add header to accept gzip content
            if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
                request.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
            }
        }
    });

    client.addResponseInterceptor(new HttpResponseInterceptor() {
        public void process(HttpResponse response, HttpContext context) {
            // Inflate any responses compressed with gzip
            final HttpEntity entity = response.getEntity();
            final Header encoding = entity.getContentEncoding();
            if (encoding != null) {
                for (HeaderElement element : encoding.getElements()) {
                    if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
                        response.setEntity(new InflatingEntity(response.getEntity()));
                        break;
                    }
                }
            }
        }
    });

    return client;
}

From source file:com.makotosan.vimeodroid.common.HttpHelper.java

/**
* Generate and return a {@link HttpClient} configured for general use,
* including setting an application-specific user-agent string.
*///ww  w . ja va2 s.co  m
public static HttpClient getHttpClient(Context context) {
    final HttpParams params = new BasicHttpParams();

    // Use generous timeouts for slow mobile networks
    HttpConnectionParams.setConnectionTimeout(params, 20 * SECOND_IN_MILLIS);
    HttpConnectionParams.setSoTimeout(params, 20 * SECOND_IN_MILLIS);

    HttpConnectionParams.setSocketBufferSize(params, 8192);
    HttpProtocolParams.setUserAgent(params, buildUserAgent(context));

    final DefaultHttpClient client = new DefaultHttpClient(params);

    client.addRequestInterceptor(new HttpRequestInterceptor() {
        @Override
        public void process(HttpRequest request, HttpContext context) {
            // Add header to accept gzip content
            if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
                request.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
            }
        }
    });

    client.addResponseInterceptor(new HttpResponseInterceptor() {
        @Override
        public void process(HttpResponse response, HttpContext context) {
            // Inflate any responses compressed with gzip
            final HttpEntity entity = response.getEntity();
            final Header encoding = entity.getContentEncoding();
            if (encoding != null) {
                for (HeaderElement element : encoding.getElements()) {
                    if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
                        response.setEntity(new InflatingEntity(response.getEntity()));
                        break;
                    }
                }
            }
        }
    });

    return client;
}

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 www .  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.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);
}