List of usage examples for org.apache.http.params BasicHttpParams BasicHttpParams
public BasicHttpParams()
From source file:dk.i2m.drupal.DrupalHttpClient.java
DrupalHttpClient(int connectionTimeout, int socketTimeout) { BasicHttpParams params = new BasicHttpParams(); params.setParameter(AllClientPNames.CONNECTION_TIMEOUT, connectionTimeout) .setParameter(AllClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH) .setParameter(AllClientPNames.HTTP_CONTENT_CHARSET, HTTP.UTF_8) .setParameter(AllClientPNames.SO_TIMEOUT, socketTimeout); this.setParams(params); }
From source file:com.lonepulse.robozombie.executor.ZombieConfig.java
@Override public HttpClient httpClient() { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setSoTimeout(params, 2 * 1000); //to simulate a socket timeout SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry); return new DefaultHttpClient(manager, params); }
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. *//*from w w w . j a va 2 s . c o 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.basistech.readability.HttpPageReader.java
/** {@inheritDoc}*/ @Override/*from ww w . j a va 2 s . c om*/ public String readPage(String url) throws PageReadException { LOG.info("Reading " + url); HttpParams httpParameters = new BasicHttpParams(); // Set the timeout in milliseconds until a connection is established. 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 = 10000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); DefaultHttpClient httpclient = new DefaultHttpClient(httpParameters); HttpContext localContext = new BasicHttpContext(); HttpGet get = new HttpGet(url); InputStream response = null; HttpResponse httpResponse = null; try { try { httpResponse = httpclient.execute(get, localContext); int resp = httpResponse.getStatusLine().getStatusCode(); if (HttpStatus.SC_OK != resp) { LOG.error("Download failed of " + url + " status " + resp + " " + httpResponse.getStatusLine().getReasonPhrase()); return null; } String respCharset = EntityUtils.getContentCharSet(httpResponse.getEntity()); return readContent(httpResponse.getEntity().getContent(), respCharset); } finally { if (response != null) { response.close(); } if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().consumeContent(); } } } catch (IOException e) { LOG.error("Download failed of " + url, e); throw new PageReadException("Failed to read " + url, e); } }
From source file:com.dajodi.scandic.ScandicSessionHelper.java
public static InputStream get(URI uri) { DefaultHttpClient client = Singleton.INSTANCE.getHttpClient(); try {/* www . ja v a 2 s .c om*/ HttpGet get = new HttpGet(uri); Util.gzipify(get); final HttpParams params = new BasicHttpParams(); HttpClientParams.setRedirecting(params, false); get.setParams(params); Log.d("Executing get"); // should give us a 302 HttpResponse response = client.execute(get); if (response.getStatusLine().getStatusCode() != 200) { throw new ScandicHtmlException("Expected a 200, got " + response.getStatusLine()); } InputStream instream = Util.ungzip(response); return instream; } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new RuntimeException(e); } } }
From source file:cn.keke.travelmix.HttpClientHelper.java
public static HttpClient getNewHttpClient() { try {// w ww.j a v a 2 s . c o m SSLSocketFactory sf = new EasySSLSocketFactory(); // TODO test, if SyncBasicHttpParams is needed HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); HttpProtocolParams.setUseExpectContinue(params, false); HttpProtocolParams.setHttpElementCharset(params, HTTP.UTF_8); HttpConnectionParams.setConnectionTimeout(params, 10000); HttpConnectionParams.setSocketBufferSize(params, 8192); HttpConnectionParams.setLinger(params, 1); HttpConnectionParams.setStaleCheckingEnabled(params, false); HttpConnectionParams.setSoReuseaddr(params, true); HttpConnectionParams.setTcpNoDelay(params, true); HttpClientParams.setCookiePolicy(params, CookiePolicy.IGNORE_COOKIES); HttpClientParams.setAuthenticating(params, false); HttpClientParams.setRedirecting(params, false); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); registry.register(new Scheme("https", 443, sf)); ThreadSafeClientConnManager ccm = new ThreadSafeClientConnManager(registry, 20, TimeUnit.MINUTES); ccm.setMaxTotal(100); ccm.setDefaultMaxPerRoute(20); return new DefaultHttpClient(ccm, params); } catch (Exception e) { LOG.warn("Failed to create custom http client. Default http client is created", e); return new DefaultHttpClient(); } }
From source file:com.halseyburgund.roundware.server.RWHttpManager.java
public static String doGet(String page, Properties props) throws Exception { HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, CONNECTION_TIMEOUT_MSEC); HttpConnectionParams.setSoTimeout(httpParams, CONNECTION_TIMEOUT_MSEC); HttpClient httpClient = new DefaultHttpClient(httpParams); StringBuilder uriBuilder = new StringBuilder(page); StringBuffer sbResponse = new StringBuffer(); Enumeration<Object> enumProps = props.keys(); String key, value = null;/* ww w . ja v a 2 s .c o m*/ uriBuilder.append('?'); while (enumProps.hasMoreElements()) { key = enumProps.nextElement().toString(); value = props.get(key).toString(); uriBuilder.append(key); uriBuilder.append('='); uriBuilder.append(java.net.URLEncoder.encode(value)); if (enumProps.hasMoreElements()) { uriBuilder.append('&'); } } if (D) { RWHtmlLog.i(TAG, "GET request: " + uriBuilder.toString(), null); } HttpGet request = new HttpGet(uriBuilder.toString()); HttpResponse response = httpClient.execute(request); int status = response.getStatusLine().getStatusCode(); // we assume that the response body contains the error message if (status != HttpStatus.SC_OK) { ByteArrayOutputStream ostream = new ByteArrayOutputStream(); response.getEntity().writeTo(ostream); RWHtmlLog.e(TAG, "GET ERROR: " + ostream.toString(), null); throw new Exception(HTTP_POST_FAILED + status); } else { InputStream content = response.getEntity().getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) { sbResponse.append(line); } content.close(); // this will also close the connection } if (D) { RWHtmlLog.i(TAG, "GET response: " + sbResponse.toString(), null); } return sbResponse.toString(); }
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:org.pluroid.pluroium.HttpClientFactory.java
public static DefaultHttpClient createHttpClient(ClientConnectionManager connMgr) { DefaultHttpClient httpClient;//from w ww .j a v a 2 s. c o m HttpParams params = new BasicHttpParams(); params.setParameter("http.socket.timeout", new Integer(READ_TIMEOUT)); params.setParameter("http.connection.timeout", new Integer(CONNECT_TIMEOUT)); connMgr = new ThreadSafeClientConnManager(params, supportedSchemes); httpClient = new DefaultHttpClient(connMgr, params); httpClient.removeRequestInterceptorByClass(RequestExpectContinue.class); return httpClient; }
From source file:com.android.dumprendertree2.FsUtils.java
private static HttpClient getHttpClient() { if (sHttpClient == null) { HttpParams params = new BasicHttpParams(); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(// w w w. j a v a 2s .co m new Scheme("http", PlainSocketFactory.getSocketFactory(), ForwarderManager.HTTP_PORT)); schemeRegistry.register( new Scheme("https", SSLSocketFactory.getSocketFactory(), ForwarderManager.HTTPS_PORT)); ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(params, schemeRegistry); sHttpClient = new DefaultHttpClient(connectionManager, params); HttpConnectionParams.setSoTimeout(sHttpClient.getParams(), HTTP_TIMEOUT_MS); HttpConnectionParams.setConnectionTimeout(sHttpClient.getParams(), HTTP_TIMEOUT_MS); } return sHttpClient; }