List of usage examples for org.apache.http.impl.client DefaultHttpClient getParams
public synchronized final HttpParams getParams()
From source file:Main.java
public static DefaultHttpClient getDefaultHttpClient() { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); HttpParams params = new BasicHttpParams(); ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); DefaultHttpClient defaultHttpClient = new DefaultHttpClient(cm, params); HttpConnectionParams.setSoTimeout(defaultHttpClient.getParams(), SOCKET_TIME_OUT); HttpConnectionParams.setConnectionTimeout(defaultHttpClient.getParams(), CONNECTION_TIME_OUT); defaultHttpClient.getParams().setIntParameter(ClientPNames.MAX_REDIRECTS, 10); HttpClientParams.setCookiePolicy(defaultHttpClient.getParams(), CookiePolicy.BROWSER_COMPATIBILITY); HttpProtocolParams.setUserAgent(defaultHttpClient.getParams(), "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110628 Ubuntu/10.04 (lucid) Firefox/3.6.18"); defaultHttpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3, true)); return defaultHttpClient; }
From source file:com.qihoo.permmgr.util.d.java
public static String a(String paramString, int paramInt) { try {/*w ww. j av a2s .c o m*/ HttpGet localHttpGet = new HttpGet(paramString); DefaultHttpClient localDefaultHttpClient = new DefaultHttpClient(); localDefaultHttpClient.getParams().setParameter("http.connection.timeout", Integer.valueOf(paramInt)); localDefaultHttpClient.getParams().setParameter("http.socket.timeout", Integer.valueOf(paramInt)); HttpResponse localHttpResponse = localDefaultHttpClient.execute(localHttpGet); if (200 == localHttpResponse.getStatusLine().getStatusCode()) { String str = EntityUtils.toString(localHttpResponse.getEntity()); return str; } } catch (Exception localException) { localException.printStackTrace(); } return null; }
From source file:com.starbucks.apps.HttpUtils.java
private static DefaultHttpClient getHttpClient(HttpInvocationContext context) { DefaultHttpClient client = new DefaultHttpClient(); HttpParams params = client.getParams(); HttpConnectionParams.setConnectionTimeout(params, 30000); HttpConnectionParams.setSoTimeout(params, 30000); client.setHttpRequestRetryHandler(new HttpRequestRetryHandler() { public boolean retryRequest(IOException e, int i, HttpContext httpContext) { return false; }/*from ww w. ja v a2 s.c om*/ }); client.addRequestInterceptor(context); client.addResponseInterceptor(context); return client; }
From source file:org.deegree.maven.utils.HttpUtils.java
public static HttpClient getAuthenticatedHttpClient(ServiceIntegrationTestHelper helper) { DefaultHttpClient client = new DefaultHttpClient(); HttpConnectionParams.setConnectionTimeout(client.getParams(), 30000); HttpConnectionParams.setSoTimeout(client.getParams(), 1200000); client.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("deegree", "deegree")); // preemptive authentication used to be easier in pre-4.x httpclient AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); HttpHost host = new HttpHost("localhost", Integer.parseInt(helper.getPort())); authCache.put(host, basicAuth);/* w w w.j a va 2 s . co m*/ BasicHttpContext localcontext = new BasicHttpContext(); localcontext.setAttribute(AUTH_CACHE, authCache); return client; }
From source file:org.wwscc.registration.attendance.Attendance.java
/** * Retrieve the attendance report from the main host * @param host the hostname to retrieve from * @throws IOException /*from ww w.ja va2 s . c om*/ * @throws URISyntaxException * @throws UnsupportedEncodingException */ public static void getAttendance(String host) throws IOException, URISyntaxException { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpProtocolParams.setUserAgent(httpclient.getParams(), "Scorekeeper/2.0"); MonitorProgressStream monitor = new MonitorProgressStream("Download Attendance"); monitor.setProgress(1); monitor.setNote("Initialize"); HttpPost request = new HttpPost(new URI("http", host, "/history/attendance", null)); File temp = File.createTempFile("attendance", "tmp"); monitor.setProgress(2); monitor.setNote("Connecting/Calcuation..."); HttpEntity download = httpclient.execute(request).getEntity(); monitor.setProgress(3); monitor.setNote("Downloading..."); FileOutputStream todisk = new FileOutputStream(temp); monitor.setStream(todisk, download.getContentLength()); download.writeTo(monitor); FileUtils.copyFile(temp, defaultfile); }
From source file:cn.loveapple.client.android.util.ApiUtil.java
public static String getHttpBody(String url, PackageManager packageManager) { if (StringUtils.isEmpty(url)) { return null; }/* www.j a va 2s. com*/ String body = null; DefaultHttpClient httpClient = new DefaultHttpClient(); HttpParams params = httpClient.getParams(); // SYSTEM INFO params.setParameter("", ""); params.setParameter("", ""); params.setParameter("", ""); HttpConnectionParams.setConnectionTimeout(params, 1000); HttpConnectionParams.setSoTimeout(params, 1000); HttpPost httpRequest = new HttpPost(url); HttpResponse httpResponse = null; try { httpResponse = httpClient.execute(httpRequest); } catch (Exception e) { Log.e(LOG_TAG, "http response execute failed.", e); return null; } if (httpResponse != null && httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { HttpEntity httpEntity = httpResponse.getEntity(); try { body = EntityUtils.toString(httpEntity); } catch (Exception e) { Log.e(LOG_TAG, "get http response body failed.", e); return null; } finally { try { httpEntity.consumeContent(); } catch (IOException e) { } } } httpClient.getConnectionManager().shutdown(); return body; }
From source file:costumetrade.common.util.HttpClientUtils.java
public static String get(String url, String encoding) throws ClientProtocolException, IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); try {/* ww w . jav a 2s . c o m*/ httpclient.getParams().setBooleanParameter(CookieSpecPNames.SINGLE_COOKIE_HEADER, true); //log.info("GET "+url); HttpGet httpget = new HttpGet(url); httpget.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)"); HttpResponse response = httpclient.execute(httpget); //log.info(response.getStatusLine().getStatusCode()); HttpEntity entity = response.getEntity(); return EntityUtils.toString(entity, encoding); } finally { if (httpclient != null) { httpclient.getConnectionManager().shutdown(); } } }
From source file:org.ow2.proactive.scheduler.rest.utils.HttpUtility.java
public static HttpClient threadSafeClient() { DefaultHttpClient client = new DefaultHttpClient(); ClientConnectionManager mgr = client.getConnectionManager(); HttpParams params = client.getParams(); client = new DefaultHttpClient(new PoolingClientConnectionManager(mgr.getSchemeRegistry()), params); return client; }
From source file:net.ecfirm.ec.ec1.net.EcNetHelper.java
public static DefaultHttpClient getThreadSafeClient() { DefaultHttpClient client = new DefaultHttpClient(); ClientConnectionManager mgr = client.getConnectionManager(); ////////// w w w . j ava2s. c om client.getParams().setParameter("http.protocol.expect-continue", false); client.getParams().setParameter("http.connection.timeout", EcConst.NET_HTTP_CONN_TIMEOUT); //client.getParams().setParameter("http.socket.timeout", ); //////// HttpParams params = client.getParams(); //////// ConnManagerParams.setMaxTotalConnections(params, EcConst.NET_HTTP_CONN); ConnPerRouteBean connPerRoute = new ConnPerRouteBean(EcConst.NET_HTTP_CONN_PER_ROUTE); HttpHost localhost = new HttpHost("localhost", 80); connPerRoute.setMaxForRoute(new HttpRoute(localhost), EcConst.NET_HTTP_CONN_PER_ROUTE); ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute); mgr.getSchemeRegistry().register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); mgr.getSchemeRegistry().register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); //////// client = new DefaultHttpClient(new ThreadSafeClientConnManager(params, mgr.getSchemeRegistry()), params); return client; }
From source file:com.github.ajasmin.telususageandroidwidget.TelusReportFetcher.java
private static void fetchFromTelusSite(final PreferencesData prefs) throws NetworkErrorException, InvalidCredentialsException { final DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "ajasmin-widget"); logIn(httpclient, prefs);/*from ww w . ja va 2 s . co m*/ fetchUsageSummaryPage(httpclient, prefs); prefs.markAsUpdatedNow(); // Log out to avoid session limit // on background thread to avoid extra delay new Thread(new Runnable() { @Override public void run() { try { fetchLogOutPage(httpclient); Log.i("TelusWebScraper", "Logged out " + prefs.email); } catch (IOException e) { Log.e("TelusWebScraper", "Couldn't fetch logout page for " + prefs.email, e); } } }).run(); }