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

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

Introduction

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

Prototype

public static void setSoTimeout(HttpParams httpParams, int i) 

Source Link

Usage

From source file:com.ntsync.android.sync.client.MyHttpClient.java

protected ClientConnectionManager createClientConnectionManager() {
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", new PlainSocketFactory(), 80));
    registry.register(new Scheme("https", getSSLSocketFactory(), 443));

    HttpParams params = getParams();/*w  w w .j av  a  2s.  co m*/
    HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, READ_TIMEOUT_MS);
    ConnManagerParams.setTimeout(params, GET_CONNECTION_MS);
    HttpProtocolParams.setUserAgent(params, getUserAgent(context, HttpProtocolParams.getUserAgent(params)));

    return new ThreadSafeClientConnManager(params, registry);
}

From source file:com.android.idtt.HttpUtils.java

public HttpUtils(int connTimeout) {
    HttpParams params = new BasicHttpParams();

    ConnManagerParams.setTimeout(params, connTimeout);
    HttpConnectionParams.setSoTimeout(params, connTimeout);
    HttpConnectionParams.setConnectionTimeout(params, connTimeout);

    ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(10));
    ConnManagerParams.setMaxTotalConnections(params, 10);

    HttpConnectionParams.setTcpNoDelay(params, true);
    HttpConnectionParams.setSocketBufferSize(params, 1024 * 8);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

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

    httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(params, schemeRegistry), params);

    httpClient.setHttpRequestRetryHandler(new RetryHandler(DEFAULT_RETRY_TIMES));

    httpClient.addRequestInterceptor(new HttpRequestInterceptor() {
        @Override//from  w w  w.  j a va 2s. c o  m
        public void process(org.apache.http.HttpRequest httpRequest, HttpContext httpContext)
                throws org.apache.http.HttpException, IOException {
            if (!httpRequest.containsHeader(HEADER_ACCEPT_ENCODING)) {
                httpRequest.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
            }
        }
    });

    httpClient.addResponseInterceptor(new HttpResponseInterceptor() {
        @Override
        public void process(HttpResponse response, HttpContext httpContext)
                throws org.apache.http.HttpException, IOException {
            final HttpEntity entity = response.getEntity();
            if (entity == null) {
                return;
            }
            final Header encoding = entity.getContentEncoding();
            if (encoding != null) {
                for (HeaderElement element : encoding.getElements()) {
                    if (element.getName().equalsIgnoreCase("gzip")) {
                        response.setEntity(new GZipDecompressingEntity(response.getEntity()));
                        return;
                    }
                }
            }
        }
    });
}

From source file:com.worthed.googleplus.HttpUtils.java

private HttpClient getHttpClient() {
    //  HttpParams ? HTTP ??
    HttpParams httpParams = new BasicHttpParams();

    //  Socket ? Socket ?
    HttpConnectionParams.setConnectionTimeout(httpParams, 20 * 1000);
    HttpConnectionParams.setSoTimeout(httpParams, 20 * 1000);
    HttpConnectionParams.setSocketBufferSize(httpParams, 8192);

    // ??? true//from  w ww. j av  a2  s  .  com
    HttpClientParams.setRedirecting(httpParams, true);

    //  user agent
    String userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2) Gecko/20100115 Firefox/3.6";
    HttpProtocolParams.setUserAgent(httpParams, userAgent);

    //  HttpClient 
    // ? HttpClient httpClient = new HttpClient(); Commons HttpClient
    //  Android 1.5 ? Apache ? DefaultHttpClient
    HttpClient httpClient = new DefaultHttpClient(httpParams);

    return httpClient;
}

From source file:com.gs.tools.doc.extractor.core.util.HttpUtility.java

/**
 * Get data from HTTP POST method.// w w  w .  j  a va2 s . c  om
 * 
 * This method uses
 * <ul>
 * <li>Connection timeout = 300000 (5 minutes)</li>
 * <li>Socket/Read timeout = 300000 (5 minutes)</li>
 * <li>Socket Read Buffer = 10485760 (10MB) to provide more space to read</li>
 * </ul>
 * -- in case the site is slow
 * 
 * @return
 * @throws MalformedURLException
 * @throws URISyntaxException
 * @throws UnsupportedEncodingException
 * @throws IOException
 * @throws ClientProtocolException
 * @throws Exception
 */
public static String getPostData(String sourceUrl, String postString) throws MalformedURLException,
        URISyntaxException, UnsupportedEncodingException, IOException, ClientProtocolException, Exception {
    String result = "";
    URL targetUrl = new URL(sourceUrl);

    /*
     * Create http parameter to set Connection timeout = 300000 Socket/Read
     * timeout = 300000 Socket Read Buffer = 10485760
     */
    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, 300000);
    HttpConnectionParams.setSocketBufferSize(httpParams, 10485760);
    HttpConnectionParams.setSoTimeout(httpParams, 300000);

    // set the http param to the DefaultHttpClient
    HttpClient httpClient = new DefaultHttpClient(httpParams);

    // create POST method and set the URL and POST data
    HttpPost post = new HttpPost(targetUrl.toURI());
    StringEntity entity = new StringEntity(postString, "UTF-8");
    post.setEntity(entity);
    logger.info("Execute the POST request with all input data");
    // Execute the POST request on the http client to get the response
    HttpResponse response = httpClient.execute(post, new BasicHttpContext());
    if (null != response && response.getStatusLine().getStatusCode() == 200) {
        HttpEntity httpEntity = response.getEntity();
        if (null != httpEntity) {
            long contentLength = httpEntity.getContentLength();
            logger.info("Content length: " + contentLength);
            // no data, if the content length is insufficient
            if (contentLength <= 0) {
                return "";
            }

            // read the response to String
            InputStream responseStream = httpEntity.getContent();
            if (null != responseStream) {
                BufferedReader reader = null;
                StringWriter writer = null;
                try {
                    reader = new BufferedReader(new InputStreamReader(responseStream));
                    writer = new StringWriter();
                    int count = 0;
                    int size = 1024 * 1024;
                    char[] chBuff = new char[size];
                    while ((count = reader.read(chBuff, 0, size)) >= 0) {
                        writer.write(chBuff, 0, count);
                    }
                    result = writer.getBuffer().toString();
                } catch (Exception ex) {
                    ex.printStackTrace();
                    throw ex;
                } finally {
                    IOUtils.closeQuietly(responseStream);
                    IOUtils.closeQuietly(reader);
                    IOUtils.closeQuietly(writer);
                }
            }
        }
    }
    logger.info("data read complete");
    return result;
}

From source file:com.taxicop.client.NetworkUtilities.java

public static void CreateHttpClient() {
    Log.i(TAG, "CreateHttpClient(): ");
    mHttpClient = new DefaultHttpClient();
    final HttpParams params = mHttpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, REGISTRATION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, REGISTRATION_TIMEOUT);
    ConnManagerParams.setTimeout(params, REGISTRATION_TIMEOUT);
}

From source file:edu.htl3r.schoolplanner.backend.network.Network.java

public Network() {
    initSSLSocketFactories();//ww w  .j a  v a2s  .c o m

    HttpParams params = new BasicHttpParams();

    // TODO: Timeouts sind statisch
    HttpConnectionParams.setConnectionTimeout(params, 20000);
    HttpConnectionParams.setSoTimeout(params, 10000);

    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
    HttpProtocolParams.setUseExpectContinue(params, false);

    SchemeRegistry registry = new SchemeRegistry();

    ClientConnectionManager connman = new ThreadSafeClientConnManager(params, registry);

    client = new DefaultHttpClient(connman, params);
}

From source file:eu.masconsult.bgbanking.banks.procreditbank.ProcreditClient.java

/**
 * Configures the httpClient to connect to the URL provided.
 * /*from   w  w w .ja va  2  s.  com*/
 * @param authToken
 */
private static DefaultHttpClient getHttpClient(final String authToken) {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    final HttpParams params = httpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, HTTP_REQUEST_TIMEOUT_MS);
    HttpConnectionParams.setSoTimeout(params, HTTP_REQUEST_TIMEOUT_MS);
    ConnManagerParams.setTimeout(params, HTTP_REQUEST_TIMEOUT_MS);
    HttpClientParams.setRedirecting(params, false);
    httpClient.addRequestInterceptor(new CookieRequestInterceptor(Arrays.asList(authToken)));
    return httpClient;
}

From source file:eu.trentorise.smartcampus.network.RemoteConnector.java

protected static HttpClient getHttpClient() {
    HttpClient httpClient = null;/* w w w .j ava 2s  .c o  m*/
    switch (clientType) {
    case CLIENT_WILDCARD:
        httpClient = getWildcartHttpClient(null);
        break;
    case CLIENT_ACCEPTALL:
        httpClient = getAcceptAllHttpClient(null);
        break;
    default:
        httpClient = getDefaultHttpClient(null);
    }

    final HttpParams params = httpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, HTTP_REQUEST_TIMEOUT_MS);
    HttpConnectionParams.setSoTimeout(params, HTTP_REQUEST_TIMEOUT_MS);
    ConnManagerParams.setTimeout(params, HTTP_REQUEST_TIMEOUT_MS);
    return httpClient;
}

From source file:com.android.volley.toolbox.HttpClientStack.java

@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    HttpUriRequest httpRequest = createHttpRequest(request, additionalHeaders);
    addHeaders(httpRequest, additionalHeaders);
    addHeaders(httpRequest, request.getHeaders());
    onPrepareRequest(httpRequest);//from www  . j  a v a 2s.c om
    HttpParams httpParams = httpRequest.getParams();
    int timeoutMs = request.getTimeoutMs();
    // TODO: Reevaluate this connection timeout based on more wide-scale
    // data collection and possibly different for wifi vs. 3G.
    HttpConnectionParams.setConnectionTimeout(httpParams, 5000);
    HttpConnectionParams.setSoTimeout(httpParams, timeoutMs);
    return mClient.execute(httpRequest);
}