List of usage examples for org.apache.http.impl.client DefaultHttpClient getParams
public synchronized final HttpParams getParams()
From source file:com.pursuer.reader.easyrss.Utils.java
public static DefaultHttpClient createHttpClient() { final HttpParams config = new BasicHttpParams(); HttpProtocolParams.setVersion(config, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(config, HTTP.UTF_8); HttpProtocolParams.setUserAgent(config, Utils.class.getName()); final SchemeRegistry reg = new SchemeRegistry(); reg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); reg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); final ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(config, reg); final DefaultHttpClient client = new DefaultHttpClient(manager, config); client.getParams().setParameter("http.socket.timeout", 30 * 1000); return client; }
From source file:org.transitime.avl.amigocloud.AmigoRest.java
/********************** Member Functions **************************/ private static DefaultHttpClient getThreadSafeClient() { DefaultHttpClient client = new DefaultHttpClient(); ClientConnectionManager mgr = client.getConnectionManager(); HttpParams params = client.getParams(); client = new DefaultHttpClient(new ThreadSafeClientConnManager(params, mgr.getSchemeRegistry()), params); return client; }
From source file:ee.ria.xroad.asyncsender.ProxyClient.java
private static HttpClient createHttpClient() { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpParams params = httpClient.getParams(); HttpConnectionParams.setConnectionTimeout(params, CLIENT_TIMEOUT); // Disable request retry httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); return httpClient; }
From source file:se.vgregion.pubsub.push.impl.HttpUtil.java
public static DefaultHttpClient getClient() { DefaultHttpClient client = new DefaultHttpClient(); //ConnManagerParams.setMaxTotalConnections(client.getParams(), 100); HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); HttpConnectionParams.setSoTimeout(client.getParams(), 10000); return client; }
From source file:net.peterkuterna.android.apps.devoxxfrsched.util.HttpUtils.java
/** * Generate and return a {@link HttpClient} configured for general use, * including setting an application-specific user-agent string. *//*ww w . j av a 2 s. c om*/ public static HttpClient getHttpClient(Context context) { final DefaultHttpClient client = new DevoxxHttpClient(context); client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, buildUserAgent(context)); 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.fabula.android.timeline.sync.ServerDownloader.java
/** * Method that fetches JSON-data from a URL * /* w ww . j av a2 s . co m*/ * @param url Address to service that provide JSON * @return data as {@link InputStream} */ public static InputStream getJSONData(String url) { DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "TimelineAndroid"); InputStream data = null; try { HttpHost targetHost = new HttpHost(Constants.GOOGLE_APP_ENGINE_URL, 80, "http"); HttpGet httpGet = new HttpGet(url); // Make sure the server knows what kind of a response we will accept httpGet.addHeader("Accept", "application/json"); // Also be sure to tell the server what kind of content we are sending httpGet.addHeader("Content-Type", "application/json"); HttpResponse response = httpClient.execute(targetHost, httpGet); data = null; try { data = response.getEntity().getContent(); } catch (NullPointerException e) { } } catch (Exception e) { e.printStackTrace(); } return data; }
From source file:com.bjorsond.android.timeline.sync.ServerDownloader.java
/** * Method that fetches JSON-data from a URL * //from w w w . ja va2s .c o m * @param url Address to service that provide JSON * @return data as {@link InputStream} */ public static InputStream getJSONData(String url) { DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "TimelineAndroid"); InputStream data = null; try { HttpHost targetHost = new HttpHost(Constants.GOOGLE_APP_ENGINE_URL, 80, "http"); HttpGet httpGet = new HttpGet(url); // Make sure the server knows what kind of a response we will accept httpGet.addHeader("Accept", "application/json"); // Also be sure to tell the server what kind of content we are sending httpGet.addHeader("Content-Type", "application/json"); HttpResponse response = httpClient.execute(targetHost, httpGet); data = null; try { data = response.getEntity().getContent(); } catch (NullPointerException e) { } } catch (Exception e) { e.printStackTrace(); } return data; }
From source file:com.sfalma.trace.Sfalma.java
public static void submitError(int sTimeout, Date occuredAt, final String stacktrace) throws Exception { // Transmit stack trace with POST request try {//from w ww. j a v a 2 s. c o m Log.d(G.TAG, "Transmitting stack trace: " + stacktrace); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpParams params = httpClient.getParams(); // Lighty 1.4 has trouble with the expect header // (http://redmine.lighttpd.net/issues/1017), and a // potential workaround is only included in 1.4.21 // (http://www.lighttpd.net/2009/2/16/1-4-21-yes-we-can-do-another-release). HttpProtocolParams.setUseExpectContinue(params, false); if (sTimeout != 0) { HttpConnectionParams.setConnectionTimeout(params, sTimeout); HttpConnectionParams.setSoTimeout(params, sTimeout); } HttpPost httpPost = new HttpPost(G.URL); httpPost.addHeader("X-Sfalma-Api-Key", G.API_KEY); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("data", createJSON(G.APP_PACKAGE, G.APP_VERSION, G.PHONE_MODEL, G.ANDROID_VERSION, stacktrace, SfalmaHandler.isWifiOn(), SfalmaHandler.isMobileNetworkOn(), SfalmaHandler.isGPSOn(), occuredAt))); nvps.add(new BasicNameValuePair("hash", MD5(stacktrace))); httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); // we don't care about the actual response // only if we managed to reach the server HttpResponse response = httpClient.execute(httpPost); HttpEntity entity = response.getEntity(); // maybe no internet? // save to send another day if (entity == null) { throw new Exception("no internet connection maybe"); } } catch (Exception e) { Log.e(G.TAG, "Error sending exception stacktrace", e); throw e; } }
From source file:org.carrot2.util.httpclient.HttpClientFactory.java
/** * @param timeout Timeout in milliseconds. * @return Returns a client with sockets configured to timeout after some sensible * time./*from w w w .ja v a 2 s. c o m*/ */ public static DefaultHttpClient getTimeoutingClient(int timeout) { final DefaultHttpClient httpClient = new DefaultHttpClient(); configureProxy(httpClient); // Setup defaults. httpClient.setReuseStrategy(new NoConnectionReuseStrategy()); httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout); httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_LINGER, 0); return httpClient; }
From source file:com.wbtech.ums.NetworkUtil.java
private static void processCookieRejected(DefaultHttpClient client) { client.getCookieSpecs().register("esay", new EasyCookieSpecFactory()); client.getParams().setParameter(ClientPNames.COOKIE_POLICY, "esay"); }