List of usage examples for org.apache.http.client HttpClient getConnectionManager
@Deprecated ClientConnectionManager getConnectionManager();
From source file:com.phunkosis.gifstitch.helpers.ShareHelper.java
public static String uploadToSite(String filePath, Context c) { URLStorageHelper storage = new URLStorageHelper(c); String url = storage.lookupUrl(filePath); if (url != null) { return url; }/*from w ww.ja v a 2 s .co m*/ String did = GSSettings.getDeviceId(); File file = new File(filePath); String seed = "" + GSS + did + file.getName(); String hash = generateSHA256(seed); HttpClient httpClient = new DefaultHttpClient(); try { HttpPost httpPost = new HttpPost(SHAREURL); FileBody fileBody = new FileBody(file); StringBody didBody = new StringBody(did); StringBody hashBody = new StringBody(hash); StringBody filenameBody = new StringBody(file.getName()); MultipartEntity mpe = new MultipartEntity(); mpe.addPart("did", didBody); mpe.addPart("hash", hashBody); mpe.addPart("img", filenameBody); mpe.addPart("sharedgif", fileBody); httpPost.setEntity(mpe); HttpResponse response = httpClient.execute(httpPost); HttpEntity entity = response.getEntity(); if (entity != null) { BufferedReader r = new BufferedReader(new InputStreamReader(entity.getContent())); String line = r.readLine(); if (line != null && line.startsWith("http:")) { storage.addRow(filePath, line); return line; } return line; } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { httpClient.getConnectionManager().shutdown(); } catch (Exception ignore) { } } return null; }
From source file:com.mmd.mssp.util.HttpUtil.java
public static String httpGet(String uri) throws IOException { HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(uri); HttpResponse response = httpclient.execute(httpget); logger.info(httpget.getURI().toString() + " == " + response.getStatusLine()); HttpEntity entity = response.getEntity(); Header[] cts = response.getHeaders("Content-Type"); String charset = "UTF-8"; if (cts.length > 0) { String ContentType = cts[0].getValue(); if (ContentType.contains("charset")) { charset = ContentType.split("charset=")[1]; }/* w w w. ja va 2 s .c o m*/ } if (entity != null) { InputStream instream = entity.getContent(); try { StringBuffer buffer = new StringBuffer(); char[] chars = new char[BUFFER_SIZE]; while (true) { BufferedReader reader = new BufferedReader(new InputStreamReader(instream, charset)); int len = reader.read(chars); if (len < 0) { break; } buffer.append(chars, 0, len); } return buffer.toString(); } catch (IOException ex) { throw ex; } catch (RuntimeException ex) { httpget.abort(); throw ex; } finally { instream.close(); httpclient.getConnectionManager().shutdown(); } } return ""; }
From source file:android.net.http.HttpsThroughHttpProxyTest.java
public void testConnectViaHttpProxyToHttps() throws IOException, InterruptedException { TestSSLContext testSSLContext = TestSSLContext.create(); MockWebServer proxy = new MockWebServer(); proxy.useHttps(testSSLContext.serverContext.getSocketFactory(), true); MockResponse connectResponse = new MockResponse().setResponseCode(200); connectResponse.getHeaders().clear(); proxy.enqueue(connectResponse);// w ww. j a va2 s . c o m proxy.enqueue(new MockResponse().setResponseCode(200).setBody("this response comes via a secure proxy")); proxy.play(); HttpClient httpProxyClient = new DefaultHttpClient(); HttpHost proxyHost = new HttpHost("localhost", proxy.getPort()); httpProxyClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxyHost); SSLSocketFactory sslSocketFactory = new SSLSocketFactory(testSSLContext.clientContext.getSocketFactory()); sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier()); httpProxyClient.getConnectionManager().getSchemeRegistry() .register(new Scheme("https", sslSocketFactory, 443)); HttpResponse response = httpProxyClient.execute(new HttpGet("https://android.com/foo")); assertEquals("this response comes via a secure proxy", contentToString(response)); RecordedRequest connect = proxy.takeRequest(); assertEquals("Connect line failure on proxy " + proxyHost.toHostString(), "CONNECT android.com:443 HTTP/1.1", connect.getRequestLine()); assertContains(connect.getHeaders(), "Host: android.com"); RecordedRequest get = proxy.takeRequest(); assertEquals("GET /foo HTTP/1.1", get.getRequestLine()); assertContains(get.getHeaders(), "Host: android.com"); }
From source file:org.apache.camel.component.cxf.jaxrs.CxfRsRouterTest.java
@Test public void testGetCustomer() throws Exception { HttpGet get = new HttpGet( "http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/customers/123"); get.addHeader("Accept", "application/json"); HttpClient httpclient = new DefaultHttpClient(); try {//ww w.jav a 2s. com HttpResponse response = httpclient.execute(get); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals("{\"Customer\":{\"id\":123,\"name\":\"John\"}}", EntityUtils.toString(response.getEntity())); } finally { httpclient.getConnectionManager().shutdown(); } }
From source file:org.apache.camel.component.cxf.jaxrs.CxfRsRouterTest.java
@Test public void testGetCustomerWithQuery() throws Exception { HttpGet get = new HttpGet( "http://localhost:" + getPort() + "/CxfRsRouterTest/route/customerservice/customers?id=123"); get.addHeader("Accept", "application/json"); HttpClient httpclient = new DefaultHttpClient(); try {//ww w . j a va 2 s . co m HttpResponse response = httpclient.execute(get); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals("{\"Customer\":{\"id\":123,\"name\":\"John\"}}", EntityUtils.toString(response.getEntity())); } finally { httpclient.getConnectionManager().shutdown(); } }
From source file:com.basho.riak.client.http.util.TestClientUtils.java
@Test public void newHttpClient_sets_max_total_connections() { final int maxConnections = 11; config.setMaxConnections(maxConnections); HttpClient httpClient = ClientUtils.newHttpClient(config); assertEquals(maxConnections,/*from w ww.j a va 2 s. c om*/ ((PoolingClientConnectionManager) httpClient.getConnectionManager()).getMaxTotal()); }
From source file:org.apache.camel.component.cxf.cxfbean.CxfBeanTest.java
@Test public void testPutConsumer() throws Exception { HttpPut put = new HttpPut("http://localhost:" + PORT1 + "/customerservice/customers"); StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1"); entity.setContentType("text/xml; charset=ISO-8859-1"); put.setEntity(entity);//from w ww . j ava 2 s . c o m HttpClient httpclient = new DefaultHttpClient(); try { HttpResponse response = httpclient.execute(put); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals("", EntityUtils.toString(response.getEntity())); } finally { httpclient.getConnectionManager().shutdown(); } }
From source file:org.thiesen.jiffs.jobs.fullpage.PageLoader.java
@Override public void run() { final URI link = _story.getLink(); final HttpGet get = new HttpGet(link); final HttpClient client = new DefaultHttpClient(); try {/*from w ww . j a v a 2s . co m*/ final String page = client.execute(get, new BasicResponseHandler()); _story.setFullPage(page); _storyDAO.update(_story); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { client.getConnectionManager().shutdown(); } }
From source file:org.apache.camel.component.cxf.cxfbean.CxfBeanTest.java
private void invokeRsService(String getUrl, String expected) throws Exception { HttpGet get = new HttpGet(getUrl); get.addHeader("Accept", "application/json"); get.addHeader("key", "customer"); HttpClient httpclient = new DefaultHttpClient(); try {//from w w w . j a v a2s . co m HttpResponse response = httpclient.execute(get); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals(expected, EntityUtils.toString(response.getEntity())); } finally { httpclient.getConnectionManager().shutdown(); } }
From source file:com.nagazuka.mobile.android.goedkooptanken.service.impl.GoogleHttpGeocodingService.java
public String download(String url) throws NetworkException { String response = ""; try {/*from w ww. j av a 2s .c om*/ HttpClient httpClient = new DefaultHttpClient(); HttpGet request = new HttpGet(url); //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 opvragen van de postcode", c); } catch (IOException e) { e.printStackTrace(); throw new NetworkException("Er zijn netwerkproblemen opgetreden bij het opvragen van de postcode", e); } return response; }