List of usage examples for org.apache.http.util EntityUtils toString
public static String toString(HttpEntity httpEntity) throws IOException, ParseException
From source file:com.sonatype.nexus.perftest.ossrh.ProjectProvisioningOperation.java
@Override public void perform(ClientRequestInfo requestInfo) throws Exception { DefaultHttpClient httpclient = getHttpClient(); StringBuilder url = new StringBuilder(nexusBaseurl); if (!nexusBaseurl.endsWith("/")) { url.append("/"); }//from w w w .j a va 2 s . c om url.append("service/siesta/onboard"); url.append("?users=").append("jvanzyl"); url.append("&groupId=").append(String.format("test.nexustaging-%03d", requestInfo.getRequestId())); HttpPost request = new HttpPost(url.toString()); HttpResponse response = httpclient.execute(request); String json = EntityUtils.toString(response.getEntity()); if (!isSuccess(response)) { throw new IOException(request.toString() + " : " + response.getStatusLine().toString()); } }
From source file:es.rocapal.utils.Download.HTTPActions.java
public String doGetPetition(String url) { try {//w ww . j a v a 2s . c o m DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httpGet = null; httpGet = new HttpGet(url); HttpResponse response = httpclient.execute(httpGet); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { HttpEntity entity = response.getEntity(); String str = EntityUtils.toString(entity); Log.d("doGetPetition", str); return str; } return String.valueOf(response.getStatusLine().getStatusCode()); } catch (IOException e) { Log.e("doGetPetition", e.getMessage()); return null; } }
From source file:ph.sakay.gateway.PollingService.java
@Override public void onHandleIntent(Intent intent) { Log.d("PollingService", "Attempting to poll"); try {//from ww w.j a va 2s.c om HttpResponse response = new APIClient(this).get("/poll", ""); int status = response.getStatusLine().getStatusCode(); if (status >= 200 && status < 300) { Log.d("PollingService", "Got server response"); ToSend toSend = new ToSend(); ObjectMapper m = new ObjectMapper(); ObjectReader r = m.readerForUpdating(toSend); JsonParser p = m.getJsonFactory().createJsonParser(response.getEntity().getContent()); p.nextToken(); while (p.nextToken() != JsonToken.END_ARRAY) { r.readValue(p); Util.sendSms(toSend.target, toSend.message); } } else { String body = EntityUtils.toString(response.getEntity()); Log.e("PollingService", "Error while contacting server. Got status " + status + " and response: " + body); } } catch (Exception e) { Log.e("PollingService", "Error while contacting server", e); } }
From source file:com.netflix.http4.NFHttpClientTest.java
@Test public void testDefaultClient() throws Exception { NFHttpClient client = NFHttpClientFactory.getDefaultClient(); HttpGet get = new HttpGet("http://www.google.com"); // uri // this is not the overridable method HttpResponse response = client.execute(get); HttpEntity entity = response.getEntity(); String contentStr = EntityUtils.toString(entity); assertTrue(contentStr.length() > 0); }
From source file:org.fcrepo.serialization.bagit.BagItSerializerIT.java
@Test public void tryOneObject() throws ClientProtocolException, IOException { client.execute(postObjMethod("BagIt1")); client.execute(postDSMethod("BagIt1", "testDS", "stuff")); final HttpGet getObjMethod = new HttpGet(serverAddress + "objects/BagIt1/fcr:export?format=bagit"); HttpResponse response = client.execute(getObjMethod); assertEquals(200, response.getStatusLine().getStatusCode()); final String content = EntityUtils.toString(response.getEntity()); logger.debug("Found exported object: " + content); client.execute(new HttpDelete(serverAddress + "objects/BagIt1")); logger.debug("Deleted test object."); final HttpPost importMethod = new HttpPost(serverAddress + "objects/fcr:import?format=bagit"); importMethod.setEntity(new StringEntity(content)); assertEquals("Couldn't import!", 201, getStatus(importMethod)); final HttpGet httpGet = new HttpGet(serverAddress + "objects/BagIt1"); httpGet.setHeader("Accepts", "application/n3"); response = client.execute(httpGet);//from w w w . j a v a 2s . co m assertEquals("Couldn't find reimported object!", 200, response.getStatusLine().getStatusCode()); response = client.execute(new HttpGet(serverAddress + "objects/BagIt1/testDS")); assertEquals("Couldn't find reimported datastream!", 200, response.getStatusLine().getStatusCode()); logger.debug("Successfully reimported!"); }
From source file:be.evias.cloudLogin.services.ServiceBase.java
public Boolean ping(Context context) { DefaultHttpClient httpClient = new DefaultHttpClient(); String url = "http://evias.be/api/index/ping"; url += "?format=json&api_key=c611c52d7054086f207ffad27f3927cd"; HttpGet httpGet = new HttpGet(url); SimpleResult result;/* w ww . j a va 2 s .c om*/ try { HttpResponse response = httpClient.execute(httpGet); String responseString = EntityUtils.toString(response.getEntity()); if (response.getStatusLine().getStatusCode() != 200) return false; result = new Gson().fromJson(responseString, SimpleResult.class); return result.getResult(); } catch (IOException e) { } return false; }
From source file:com.googlecode.deadalus.games.bomberman.RestApiTests.java
@Test(enabled = false) public void testCreatePlayerAndDetonateBomd() throws IOException, InterruptedException { // first create the bomb HttpGet createBomb = new HttpGet( testHost + "create/3d82f2e1-d5c1-376e-8047-a98a395fcf4a/52.3777634,4.869633/a.json"); HttpResponse response = httpClient.execute(createBomb); System.out.println(EntityUtils.toString(response.getEntity())); // give it some time to tick Thread.sleep(5000);//ww w .jav a 2 s . c o m // now create the player right on top of the bomd HttpGet createPlayer = new HttpGet( testHost + "create/43155b7e-69b0-39f4-99c7-7160b4d46e43/52.3777634,4.869533/a.json"); response = httpClient.execute(createPlayer); System.out.println(EntityUtils.toString(response.getEntity())); // we should see an explosion }
From source file:com.javaquery.aws.elasticsearch.AddUpdateExample.java
/** * Perform post request./*from ww w.ja va2 s. co m*/ * @param httpPost */ public static void httpPostRequest(HttpPost httpPost) { /* Create object of CloseableHttpClient */ CloseableHttpClient httpClient = HttpClients.createDefault(); /* Response handler for after request execution */ ResponseHandler<String> responseHandler = new ResponseHandler<String>() { @Override public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException { /* Get status code */ int status = response.getStatusLine().getStatusCode(); if (status >= 200 && status < 300) { /* Convert response to String */ HttpEntity entity = response.getEntity(); return entity != null ? EntityUtils.toString(entity) : null; } else { throw new ClientProtocolException("Unexpected response status: " + status); } } }; try { /* Execute URL and attach after execution response handler */ String strResponse = httpClient.execute(httpPost, responseHandler); /* Print the response */ System.out.println("Response: " + strResponse); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ajah.http.Http.java
/** * Fetch a URI and return it's response as a String. * /*from w ww . jav a 2 s . c o m*/ * @param uri * The URI to fetch. * @return The response body as a String. * @throws IOException * If the response could not be completed. * @throws UnexpectedResponseCode * If an unexpected/illegal response status is issued. * @throws NotFoundException * If the resource could not be found at the URI (404). */ public static String get(final URI uri) throws IOException, UnexpectedResponseCode, NotFoundException { return EntityUtils.toString(internalGet(uri)); }
From source file:com.loyalty.service.RemoteService.java
public KioskDTO activate() throws IOException, KioskException { try (CloseableHttpResponse result = getHttpClient().post("/public-api/activate", ContentType.APPLICATION_FORM_URLENCODED, new BasicNameValuePair("kioskLicense", license))) { if (result.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new KioskException(result.getStatusLine().getStatusCode(), "Can't activate Kiosk with provided license code: " + getLicense()); }/* ww w. j a va2s . c o m*/ kioskDTO = getMapper().readValue(EntityUtils.toString(result.getEntity()), KioskDTO.class); return kioskDTO; } }