List of usage examples for org.apache.http.impl.client DefaultHttpClient getConnectionManager
public synchronized final ClientConnectionManager getConnectionManager()
From source file:org.ow2.proactive_grid_cloud_portal.common.server.HttpUtils.java
public static DefaultHttpClient createDefaultExecutor() { PoolingClientConnectionManager cm = new PoolingClientConnectionManager(); cm.setDefaultMaxPerRoute(50);/* w ww. j av a2 s .c o m*/ cm.setMaxTotal(50); DefaultHttpClient httpClient = new DefaultHttpClient(cm); try { SSLSocketFactory socketFactory = new SSLSocketFactory(new RelaxedTrustStrategy(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme https = new Scheme("https", 443, socketFactory); httpClient.getConnectionManager().getSchemeRegistry().register(https); } catch (Exception ignored) { } return httpClient; }
From source file:com.wiyun.engine.network.Network.java
static void shutdown(DefaultHttpClient client) { try {/*from w w w .jav a 2 s .com*/ if (client != null) client.getConnectionManager().shutdown(); } catch (Exception e) { } }
From source file:com.waku.common.http.MyHttpClient.java
public static Document getAsDom4jDoc(String url, MultipartEntity reqEntity) { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler()); try {/*from w w w. jav a 2 s. c om*/ HttpPost httpPost = new HttpPost(url); httpPost.setEntity(reqEntity); return getResponseAndConvertToDom(httpclient, httpPost); } finally { try { httpclient.getConnectionManager().shutdown(); } catch (Exception ignore) { } } }
From source file:middleware.HTTPRequest.java
public static void doPostReplica() throws UnsupportedEncodingException, IOException { String url = "http://localhost:8084/MVIv2/webapi/rr/replicar"; DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost(url); HttpResponse response = httpClient.execute(postRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("ERROR AL REPLICAR DEL TIPO: " + response.getStatusLine().getStatusCode()); }/*w w w .j av a 2s .c o m*/ httpClient.getConnectionManager().shutdown(); }
From source file:middleware.HTTPRequest.java
public static void doPostRestaura() throws UnsupportedEncodingException, IOException { String url = "http://localhost:8084/MVIv2/webapi/rr/restaurar"; DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost(url); HttpResponse response = httpClient.execute(postRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("ERROR AL RESTAURAR DEL TIPO: " + response.getStatusLine().getStatusCode()); }/*from w ww . j a va 2s . com*/ httpClient.getConnectionManager().shutdown(); }
From source file:biocode.fims.ezid.EzidService.java
/** * Generate an HTTP Client for communicating with web services that is * thread safe and can be used in the context of a multi-threaded application. * * @return DefaultHttpClient// www .j a va 2 s . c om */ private static DefaultHttpClient createThreadSafeClient() { DefaultHttpClient client = new DefaultHttpClient(); ClientConnectionManager mgr = client.getConnectionManager(); HttpParams params = client.getParams(); ThreadSafeClientConnManager connManager = new ThreadSafeClientConnManager(mgr.getSchemeRegistry()); connManager.setDefaultMaxPerRoute(CONNECTIONS_PER_ROUTE); client = new DefaultHttpClient(connManager, params); return client; }
From source file:Main.java
private static String reverseGeocode(String url) { try {/*from ww w . jav a 2 s . c o m*/ HttpGet httpGet = new HttpGet(url); BasicHttpParams httpParams = new BasicHttpParams(); DefaultHttpClient defaultHttpClient = new DefaultHttpClient(httpParams); HttpResponse httpResponse = defaultHttpClient.execute(httpGet); int responseCode = httpResponse.getStatusLine().getStatusCode(); if (responseCode == HttpStatus.SC_OK) { String charSet = EntityUtils.getContentCharSet(httpResponse.getEntity()); if (null == charSet) { charSet = "UTF-8"; } String str = new String(EntityUtils.toByteArray(httpResponse.getEntity()), charSet); defaultHttpClient.getConnectionManager().shutdown(); return str; } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String reverseGeocode(String url) { try {/* ww w. java2 s . c o m*/ HttpGet httpGet = new HttpGet(url); BasicHttpParams httpParams = new BasicHttpParams(); DefaultHttpClient defaultHttpClient = new DefaultHttpClient(httpParams); HttpResponse httpResponse = defaultHttpClient.execute(httpGet); int responseCode = httpResponse.getStatusLine().getStatusCode(); if (responseCode == HttpStatus.SC_OK) { String charSet = EntityUtils.getContentCharSet(httpResponse.getEntity()); if (null == charSet) { charSet = "UTF-8"; } String str = new String(EntityUtils.toByteArray(httpResponse.getEntity()), charSet); defaultHttpClient.getConnectionManager().shutdown(); Log.i("-----------", "str = " + str); return str; } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:org.eclipse.thym.core.internal.util.HttpUtil.java
/** * Set the proxy settings from ProxyService. * This method sets a {@link HttpRoutePlanner} to the client * // ww w . j ava 2 s.com * @param client */ public static void setupProxy(final DefaultHttpClient client) { client.setRoutePlanner(new HttpRoutePlanner() { @Override public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context) throws HttpException { //use forced route if one exists HttpRoute route = ConnRouteParams.getForcedRoute(request.getParams()); if (route != null) return route; // if layered, is it secure? final Scheme scheme = client.getConnectionManager().getSchemeRegistry().getScheme(target); final boolean secure = scheme.isLayered(); HttpHost host = null; try { IProxyData[] proxyDatas = getEclipseProxyData(new URI(target.toURI())); for (IProxyData data : proxyDatas) { if (data.getType().equals(IProxyData.HTTP_PROXY_TYPE)) { host = new HttpHost(data.getHost(), data.getPort()); break; } } } catch (URISyntaxException e) { HybridCore.log(IStatus.ERROR, "Incorrect URI", e); } if (host == null) { return new HttpRoute(target, null, secure); } return new HttpRoute(target, null, host, secure); } }); }
From source file:com.sat.common.SDdetails.java
public static void sdStatus(String SDip) throws IOException, FileNotFoundException, ClientProtocolException { new FileOutputStream(htmlfname).close(); htmlfile = new PrintWriter(new BufferedWriter(new FileWriter(htmlfname, true))); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet getRequest = new HttpGet("http://" + SDip + ":2013/service"); HttpResponse response = httpClient.execute(getRequest); BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output;//from w w w . ja v a2 s.c o m String q = null; System.out.println("SD details .... \n"); while ((output = br.readLine()) != null) { q = output; // System.out.println(output); } httpClient.getConnectionManager().shutdown(); parserGson(q); //htmlfile.close(); }