List of usage examples for org.apache.http.client HttpClient getConnectionManager
@Deprecated ClientConnectionManager getConnectionManager();
From source file:it.componentSearch.ProjectSearchTest.java
/** * SONAR-3105/*from w ww . j a va2 s .c om*/ */ @Test public void projects_web_service() throws IOException { SonarRunner build = SonarRunner.create(projectDir("shared/xoo-sample")); orchestrator.executeBuild(build); String url = orchestrator.getServer().getUrl() + "/api/projects?key=sample&versions=true"; HttpClient httpclient = new DefaultHttpClient(); try { HttpGet get = new HttpGet(url); HttpResponse response = httpclient.execute(get); assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200); String content = IOUtils.toString(response.getEntity().getContent()); assertThat(content).doesNotContain("error"); assertThat(content).contains("sample"); EntityUtils.consume(response.getEntity()); } finally { httpclient.getConnectionManager().shutdown(); } }
From source file:com.nagazuka.mobile.android.goedkooptanken.service.impl.ZukaService.java
public String upload(PlacesParams params) throws NetworkException { String response = ""; try {/*from w w w .j a va2 s. co m*/ HttpClient httpClient = new DefaultHttpClient(); HttpGet request = new HttpGet(constructURL(params)); //Log.d(TAG, "<< HTTP Request: " + request.toString()); ResponseHandler<String> handler = new BasicResponseHandler(); response = httpClient.execute(request, handler); //Log.d(TAG, "<< HTTP Response: " + response); httpClient.getConnectionManager().shutdown(); } catch (ClientProtocolException c) { c.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return response; }
From source file:com.nagazuka.mobile.android.goedkooptanken.service.impl.ZukaService.java
public String download(PlacesParams params) throws NetworkException { String response = ""; try {/*w ww .j a v a 2s . c om*/ HttpClient httpClient = new DefaultHttpClient(); HttpGet request = new HttpGet(constructURL(params)); //Log.d(TAG, "<< HTTP Request: " + request.toString()); ResponseHandler<String> handler = new BasicResponseHandler(); response = httpClient.execute(request, handler); //Log.d(TAG, "<< HTTP Response: " + response); httpClient.getConnectionManager().shutdown(); } catch (ClientProtocolException c) { c.printStackTrace(); throw new NetworkException("Er zijn netwerkproblemen opgetreden bij het downloaden van de tankstations", c); } catch (IOException e) { e.printStackTrace(); throw new NetworkException("Er zijn netwerkproblemen opgetreden bij het downloaden van de tankstations", e); } return response; }
From source file:wuit.common.crawler.search.Crawler.java
public static String doGetHttp(String url) { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 12000); HttpConnectionParams.setSoTimeout(params, 9000); HttpClient httpclient = new DefaultHttpClient(params); String rs = ""; try {//from ww w . j ava 2s .c om // System.out.println(url); HttpGet httpget = new HttpGet(url); HttpContext httpContext = new BasicHttpContext(); // httpget.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"); httpget.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 1.7; .NET CLR 1.1.4322; CIBA; .NET CLR 2.0.50727)"); HttpResponse response = httpclient.execute(httpget, httpContext); HttpUriRequest realRequest = (HttpUriRequest) httpContext.getAttribute(ExecutionContext.HTTP_REQUEST); HttpHost targetHost = (HttpHost) httpContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST); url = targetHost.toString() + realRequest.getURI(); int resStatu = response.getStatusLine().getStatusCode();//? if (resStatu == 200) { HttpEntity entity = response.getEntity(); if (entity != null) { rs = EntityUtils.toString(entity, "iso-8859-1"); String in_code = getEncoding(rs); String encode = getHtmlEncode(rs); if (encode.isEmpty()) { httpclient.getConnectionManager().shutdown(); return ""; } else { if (!in_code.toLowerCase().equals("utf-8") && !in_code.toLowerCase().equals(encode.toLowerCase())) { if (!in_code.toLowerCase().equals("iso-8859-1")) rs = new String(rs.getBytes("iso-8859-1"), in_code); if (!encode.toLowerCase().equals(in_code.toLowerCase())) rs = new String(rs.getBytes(in_code), encode); } } try { } catch (RuntimeException ex) { httpget.abort(); throw ex; } finally { // Closing the input stream will trigger connection release // try { instream.close(); } catch (Exception ignore) {} } } } } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); return rs; } }
From source file:com.cloud.network.utils.HttpClientWrapper.java
public static HttpClient wrapClient(HttpClient base) { try {/* w w w. ja v a 2 s .com*/ SSLContext ctx = SSLUtils.getSSLContext(); X509TrustManager tm = new X509TrustManager() { @Override public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } @Override public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } @Override public X509Certificate[] getAcceptedIssuers() { return null; } }; X509HostnameVerifier verifier = new X509HostnameVerifier() { @Override public void verify(String string, SSLSocket ssls) throws IOException { } @Override public void verify(String string, X509Certificate xc) throws SSLException { } @Override public void verify(String string, String[] strings, String[] strings1) throws SSLException { } @Override public boolean verify(String string, SSLSession ssls) { return true; } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx); ssf.setHostnameVerifier(verifier); ClientConnectionManager ccm = base.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", ssf, 443)); return new DefaultHttpClient(ccm, base.getParams()); } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:wuit.common.crawler.WebSit.Crawler.java
public static String doGetHttp(DSCrawlerUrl pageUrl) { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 12000); HttpConnectionParams.setSoTimeout(params, 9000); HttpClient httpclient = new DefaultHttpClient(params); String rs = ""; try {//from w ww . j a v a 2s. c o m HttpGet httpget = new HttpGet(pageUrl.url); // System.out.println("executing request " + pageUrl.url); HttpContext httpContext = new BasicHttpContext(); // httpget.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"); httpget.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 1.7; .NET CLR 1.1.4322; CIBA; .NET CLR 2.0.50727)"); HttpResponse response = httpclient.execute(httpget, httpContext); HttpUriRequest realRequest = (HttpUriRequest) httpContext.getAttribute(ExecutionContext.HTTP_REQUEST); HttpHost targetHost = (HttpHost) httpContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST); pageUrl.url = targetHost.toString() + realRequest.getURI(); int resStatu = response.getStatusLine().getStatusCode();//? if (resStatu == 200) { HttpEntity entity = response.getEntity(); if (entity != null) { rs = EntityUtils.toString(entity, "iso-8859-1"); String in_code = getEncoding(rs); String encode = getHtmlEncode(rs); if (encode.isEmpty()) { httpclient.getConnectionManager().shutdown(); return ""; } else { if (!in_code.toLowerCase().equals("utf-8") && !in_code.toLowerCase().equals(encode.toLowerCase())) { if (!in_code.toLowerCase().equals("iso-8859-1")) rs = new String(rs.getBytes("iso-8859-1"), in_code); if (!encode.toLowerCase().equals(in_code.toLowerCase())) rs = new String(rs.getBytes(in_code), encode); } } try { } catch (RuntimeException ex) { httpget.abort(); throw ex; } finally { // Closing the input stream will trigger connection release // try { instream.close(); } catch (Exception ignore) {} } } } } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); return rs; } }
From source file:org.kairosdb.testclient.QueryTests.java
private int putDataPoints(JsonElement dataPoints) throws IOException, JSONException { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://" + m_host + ":" + m_port + "/api/v1/datapoints"); post.setHeader("Content-Type", "application/json"); post.setEntity(new StringEntity(dataPoints.toString())); HttpResponse httpResponse = client.execute(post); client.getConnectionManager().shutdown(); return httpResponse.getStatusLine().getStatusCode(); }
From source file:org.sociotech.communitymashup.source.readability.apiwrapper.ReadabilityAPIWrapper.java
/** * Does a get request at the given url and returns the result as string. * //from ww w.j av a 2s. c om * @param url * Url to get * @return The result as string null in error case. */ private String doGet(String url) { // System.out.println("calling: " + url); String result = null; HttpClient httpClient = new DefaultHttpClient(); HttpGet get = new HttpGet(url); ResponseHandler<String> responseHandler = new BasicResponseHandler(); try { result = httpClient.execute(get, responseHandler); } catch (Exception e) { // do nothing } finally { // client is no longer needed httpClient.getConnectionManager().shutdown(); } // System.out.println("got: " + result); return result; }
From source file:org.kairosdb.testclient.QueryTests.java
private int deleteDataPoints(JsonElement query) throws IOException, JSONException { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://" + m_host + ":" + m_port + "/api/v1/datapoints/delete"); post.setHeader("Content-Type", "application/json"); post.setEntity(new StringEntity(query.toString())); HttpResponse httpResponse = client.execute(post); client.getConnectionManager().shutdown(); return httpResponse.getStatusLine().getStatusCode(); }
From source file:com.leanengine.RestService.java
/** * Dispose http client / its connection manager once done. *///from www . j a v a 2 s . c o m public void dispose() { final HttpClient temp = client; client = null; if (temp != null) { final ClientConnectionManager manager = temp.getConnectionManager(); if (manager != null) manager.shutdown(); } }