List of usage examples for org.apache.http.params HttpConnectionParams setSocketBufferSize
public static void setSocketBufferSize(HttpParams httpParams, int i)
From source file:kks.lib.helper.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. *//*w w w . j ava2 s . co m*/ public static AndroidHttpClient newInstance(String userAgent, int timeout) { 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, 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); 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:com.jhlibrary.util.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. *//*www . j av a 2s . c o 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. HttpProtocolParams.setUserAgent(params, userAgent); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); //TODO schemeRegistry.register(new Scheme("mxiss", new EasySSLSocketFactory(), 8443)); 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.droidparts.http.worker.HttpClientWorker.java
public HttpClientWorker(String userAgent) { super(userAgent); httpClient = new DefaultHttpClient(); HttpParams params = httpClient.getParams(); HttpConnectionParams.setStaleCheckingEnabled(params, false); HttpClientParams.setRedirecting(params, false); HttpConnectionParams.setConnectionTimeout(params, SOCKET_OPERATION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, SOCKET_OPERATION_TIMEOUT); HttpConnectionParams.setSocketBufferSize(params, BUFFER_SIZE); HttpClientParams.setCookiePolicy(params, BROWSER_COMPATIBILITY); if (userAgent != null) { HttpProtocolParams.setUserAgent(params, userAgent); }//from ww w. j a v a2s . co m }
From source file:playn.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 www . j a v a 2 s . c o 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. 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:com.dahl.brendan.wordsearch.util.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. */// w w w . j a v a2s .c o 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); HttpClientParams.setAuthenticating(params, false); // Set the specified user agent and register standard protocols. 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:com.androidrocks.bex.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. *//*w ww .j a v a 2s .c o 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. 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.openiot.gsn.http.rest.RestRemoteWrapper.java
private HttpParams getHttpClientParams(int timeout) { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET); HttpProtocolParams.setUseExpectContinue(params, true); HttpConnectionParams.setTcpNoDelay(params, false); HttpConnectionParams.setSocketBufferSize(params, 8192); HttpConnectionParams.setStaleCheckingEnabled(params, true); HttpConnectionParams.setConnectionTimeout(params, 30 * 1000); // Set the connection time to 30s HttpConnectionParams.setSoTimeout(params, timeout); HttpProtocolParams.setUserAgent(params, "GSN-HTTP-CLIENT"); return params; }
From source file:riddimon.android.asianetautologin.HttpManager.java
private HttpManager(Boolean debug, String version) { // Set basic data HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "UTF-8"); HttpProtocolParams.setUseExpectContinue(params, true); HttpProtocolParams.setUserAgent(params, HttpUtils.userAgent); // Make pool/*from w ww . java2 s.com*/ ConnPerRoute connPerRoute = new ConnPerRouteBean(12); ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute); ConnManagerParams.setMaxTotalConnections(params, 20); // Set timeout HttpConnectionParams.setStaleCheckingEnabled(params, false); HttpConnectionParams.setConnectionTimeout(params, 20 * 1000); HttpConnectionParams.setSoTimeout(params, 20 * 1000); HttpConnectionParams.setSocketBufferSize(params, 8192); // Some client params HttpClientParams.setRedirecting(params, false); // Register http/s schemas! SchemeRegistry schReg = new SchemeRegistry(); schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); if (debug) { // Install the all-trusting trust manager // Create a trust manager that does not validate certificate chains TrustManager[] trustManagers = new X509TrustManager[1]; trustManagers[0] = new TrustAllManager(); try { SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustManagers, null); schReg.register(new Scheme("https", (SocketFactory) sc.getSocketFactory(), 443)); } catch (Exception e) { ; } } else { schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); } ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg); client = new DefaultHttpClient(conMgr, params); }
From source file:com.gs.tools.doc.extractor.core.util.HttpUtility.java
/** * Get data from HTTP POST method./*from w w w . j a va2 s . co m*/ * * 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; }