List of usage examples for org.apache.http.impl.client DefaultHttpClient execute
public CloseableHttpResponse execute(final HttpUriRequest request) throws IOException, ClientProtocolException
From source file:com.rackspacecloud.blueflood.outputs.handlers.HttpRollupHandlerIntegrationTest.java
public static void testHappyCaseHTTPRequest(String metricName, String tenantId, DefaultHttpClient client) throws Exception { HttpGet get = new HttpGet(getMetricsQueryURI(metricName, tenantId)); HttpResponse response = client.execute(get); Assert.assertEquals(200, response.getStatusLine().getStatusCode()); }
From source file:gov.nih.nci.firebird.commons.selenium2.util.FileDownloadUtils.java
/** * Downloads and returns a file from the given uri. * * @param driver the driver// w ww .j a va 2 s. co m * @param uri the uri to use to download the file * @return the response including the file and the response headers. */ public static FileDownloadResponse downloadFromUri(WebDriver driver, String uri) throws IOException { File file = getDestinationFile(); OutputStream out = FileUtils.openOutputStream(file); InputStream inputStream = null; try { DefaultHttpClient client = new DefaultHttpClient(); setupCookies(client, driver); HttpGet get = new HttpGet(uri); HttpResponse response = client.execute(get); inputStream = response.getEntity().getContent(); IOUtils.copy(inputStream, out); return new FileDownloadResponse(file, response.getAllHeaders()); } finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(inputStream); } }
From source file:com.rackspacecloud.blueflood.outputs.handlers.HttpRollupHandlerIntegrationTest.java
public static void testBadMethod(String metricName, String tenantId, DefaultHttpClient client) throws Exception { HttpPost post = new HttpPost(getMetricsQueryURI(metricName, tenantId)); HttpResponse response = client.execute(post); Assert.assertEquals(405, response.getStatusLine().getStatusCode()); }
From source file:es.deustotech.piramide.utils.net.RestClient.java
public static HttpEntity connect(String url, HttpEntity httpEntity) { final DefaultHttpClient httpClient = new DefaultHttpClient(); HttpParams params = new BasicHttpParams(); params.setParameter("http.protocol.content-charset", "UTF-8"); httpClient.setParams(params);//from w w w. jav a 2 s . co m final HttpGet httpGet = new HttpGet(url); //request object HttpResponse response = null; try { response = httpClient.execute(httpGet); } catch (ClientProtocolException cpe) { Log.d(Constants.TAG, cpe.getMessage()); } catch (IOException ioe) { Log.d(Constants.TAG, ioe.getMessage()); } return httpEntity = response.getEntity(); }
From source file:org.jboss.capedwarf.tools.BulkLoader.java
private static void sendPacket(UploadPacket packet, DefaultHttpClient client, String url) throws IOException { HttpPut put = new HttpPut(url); System.out.println("Uploading packet of " + packet.size() + " entities"); put.setEntity(new FileEntity(packet.getFile(), "application/capedwarf-data")); HttpResponse response = client.execute(put); response.getEntity().writeTo(new ByteArrayOutputStream()); System.out.println("Received response " + response); }
From source file:com.quietlycoding.android.reader.util.api.Subscriptions.java
/** * This method queries Google Reader for the list of subscribed feeds. * /*from www.jav a2s . c om*/ * @param sid * authentication code to pass along in a cookie. * @return arr returns a JSONArray of JSONObjects for each feed. * * The JSONObject returned by the service looks like this: id: this * is the feed url. title: this is the title of the feed. sortid: * this has not been figured out yet. firstitemsec: this has not * been figured out yet. */ public static JSONArray getSubscriptionList(String sid) { final DefaultHttpClient client = new DefaultHttpClient(); final HttpGet get = new HttpGet(SUB_URL + "/list?output=json"); final BasicClientCookie cookie = Authentication.buildCookie(sid); try { client.getCookieStore().addCookie(cookie); final HttpResponse response = client.execute(get); final HttpEntity respEntity = response.getEntity(); Log.d(TAG, "Response from server: " + response.getStatusLine()); final InputStream in = respEntity.getContent(); final BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line = ""; String arr = ""; while ((line = reader.readLine()) != null) { arr += line; } final JSONObject obj = new JSONObject(arr); final JSONArray array = obj.getJSONArray("subscriptions"); reader.close(); client.getConnectionManager().shutdown(); return array; } catch (final Exception e) { Log.d(TAG, "Exception caught:: " + e.toString()); return null; } }
From source file:com.qihoo.permmgr.util.d.java
public static String a(String paramString, int paramInt) { try {/*from ww w . j a v a 2 s .co 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.quietlycoding.android.reader.util.api.Tags.java
/** * This method pulls the tags from Google Reader, its used by the methods in * this class to communicate before parsing the specific results. * /* w ww . jav a 2 s .c o m*/ * @param sid * the Google Reader authentication string. * @return arr JSONArray of the items from the server. */ private static JSONArray pullTags(String sid) { final DefaultHttpClient client = new DefaultHttpClient(); final HttpGet get = new HttpGet(URL); final BasicClientCookie cookie = Authentication.buildCookie(sid); try { client.getCookieStore().addCookie(cookie); final HttpResponse response = client.execute(get); final HttpEntity respEntity = response.getEntity(); Log.d(TAG, "Response from server: " + response.getStatusLine()); final InputStream in = respEntity.getContent(); final BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line = ""; String arr = ""; while ((line = reader.readLine()) != null) { arr += line; } final JSONObject obj = new JSONObject(arr); final JSONArray array = obj.getJSONArray("tags"); return array; } catch (final Exception e) { Log.d(TAG, "Exception caught:: " + e.toString()); return null; } }
From source file:com.rackspacecloud.blueflood.outputs.handlers.HttpRollupHandlerIntegrationTest.java
public static void testBadRequest(String metricName, String tenantId, DefaultHttpClient client) throws Exception { HttpGet get = new HttpGet(getInvalidMetricsQueryURI(metricName, tenantId)); HttpResponse response = client.execute(get); Assert.assertEquals(400, response.getStatusLine().getStatusCode()); }
From source file:att.jaxrs.client.Content_tag.java
public static String addContent_tag(long content_id, long tag_id) { List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("content_id", Long.toString(content_id))); urlParameters.add(new BasicNameValuePair("tag_id", Long.toString(tag_id))); String resultStr = ""; try {// w w w .j av a2 s . com DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost post = new HttpPost(Constants.INSERT_CONTENT_TAG_RESOURCE); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse result = httpClient.execute(post); System.out.println(Constants.RESPONSE_STATUS_CODE + result); resultStr = Util.getStringFromInputStream(result.getEntity().getContent()); System.out.println(Constants.RESPONSE_BODY + resultStr); } catch (Exception e) { System.out.println(e.getMessage()); } return resultStr; }