List of usage examples for org.apache.http.util EntityUtils consume
public static void consume(HttpEntity httpEntity) throws IOException
From source file:com.rackspacecloud.blueflood.http.HttpEnumIntegrationTest.java
@Test public void testMetricIngestionWithEnum() throws Exception { // ingest and rollup metrics with enum values and verify CF points and elastic search indexes final String tenant_id = "333333"; final String metric_name = "enum_metric_test"; Set<Locator> locators = new HashSet<Locator>(); locators.add(Locator.createLocatorFromPathComponents(tenant_id, metric_name)); // post enum metric for ingestion and verify HttpResponse response = postMetric(tenant_id, postAggregatedPath, "sample_enums_payload.json"); Assert.assertEquals("Should get status 200 from ingestion server for POST", 200, response.getStatusLine().getStatusCode()); EntityUtils.consume(response.getEntity()); // execute EnumValidator EnumValidator enumValidator = new EnumValidator(locators); enumValidator.run();//from ww w. j av a 2s .c om //Sleep for a while Thread.sleep(3000); // query for metric and assert results HttpResponse query_response = queryMetricIncludeEnum(tenant_id, metric_name); Assert.assertEquals("Should get status 200 from query server for GET", 200, query_response.getStatusLine().getStatusCode()); // assert response content String responseContent = EntityUtils.toString(query_response.getEntity(), "UTF-8"); Assert.assertEquals( String.format("[{\"metric\":\"%s\",\"enum_values\":[\"v1\",\"v2\",\"v3\"]}]", metric_name), responseContent); EntityUtils.consume(query_response.getEntity()); }
From source file:us.pserver.revok.http.HttpContentFactory.java
public static void main(String[] args) throws IOException { HttpContentFactory fac = HttpContentFactory.instance(new XmlSerializer()).enableGZipCoder() .enableCryptCoder(CryptKey.createRandomKey(CryptAlgorithm.AES_CBC_PKCS5)); class MSG {//from w w w . j av a 2 s . co m String str; public MSG(String s) { str = s; } public String toString() { return "MSG{str=" + str + "}"; } } fac.put(new MSG("Hello EntityFactory!")); HttpEntity ent = fac.create(); ent.writeTo(System.out); System.out.println(); ent = fac.create(); HttpEntityParser ep = HttpEntityParser.instance(new XmlSerializer());//.enableGZipCoder(); ep.parse(ent); System.out.println("* key: " + ep.getCryptKey()); System.out.println("* rob: " + ep.getObject()); EntityUtils.consume(ent); }
From source file:com.sonatype.nexus.perftest.maven.DownloadAction.java
public void download(String path) throws IOException { final String url = baseUrl.endsWith("/") ? baseUrl + path : baseUrl + "/" + path; final HttpGet httpGet = new HttpGet(url); final HttpResponse response = httpClient.execute(httpGet); if (!isSuccess(response)) { EntityUtils.consume(response.getEntity()); if (response.getStatusLine().getStatusCode() != 404) { throw new IOException(response.getStatusLine().toString()); }//from ww w . j a v a 2 s . c o m return; } // consume entity entirely final Checksumer checksumer = new Checksumer(response.getEntity()); checksumer.consumeEntity(); if (!url.contains(".meta/nexus-smartproxy-plugin/handshake/")) { final String sha1 = getUrlContents(url + ".sha1"); if (sha1 != null) { if (!sha1.startsWith(checksumer.getSha1())) { throw new IOException("Wrong SHA1 " + url); } } } }
From source file:com.canoo.dolphin.client.impl.IdBasedResponseHandler.java
@Override public String handleResponse(HttpResponse response) throws IOException { final StatusLine statusLine = response.getStatusLine(); final HttpEntity entity = response.getEntity(); if (statusLine.getStatusCode() == 408) { EntityUtils.consume(entity); throw new DolphinSessionException("Server can not handle Dolphin Client ID"); }//w w w. j ava 2 s . c o m if (statusLine.getStatusCode() >= 300) { EntityUtils.consume(entity); throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); } try { final Header dolphinHeader = response.getFirstHeader(PlatformConstants.CLIENT_ID_HTTP_HEADER_NAME); clientConnector.setClientId(dolphinHeader.getValue()); } catch (Exception e) { throw new DolphinSessionException("Error in handling Dolphin Client ID", e); } String sessionID = null; Header cookieHeader = response.getFirstHeader("Set-Cookie"); if (cookieHeader != null) { sessionID = cookieHeader.getValue(); if (lastSessionId != null) { throw new DolphinSessionException( "Http session must not change but did. Old: " + lastSessionId + ", new: " + sessionID); } lastSessionId = sessionID; } return entity == null ? null : EntityUtils.toString(entity); }
From source file:gertjvr.slacknotifier.SlackApiProcessor.java
public void sendNotification(String url, SlackNotificationMessage notification) throws IOException { String content = new Gson().toJson(notification); logger.debug(String.format("sendNotification: %s", content)); CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new StringEntity(content, ContentType.APPLICATION_JSON)); CloseableHttpResponse response = httpClient.execute(httpPost); try {// ww w . j a va 2 s . com HttpEntity entity = response.getEntity(); EntityUtils.consume(entity); } catch (Exception ex) { logger.error(String.format("sendNotification %s", ex.getMessage()), ex); } finally { response.close(); } }
From source file:com.github.mfriedenhagen.artifactorygo.StatusCodeCodeLessThanScMultipleChoicesResponseHandler.java
/** * Checks that the returncode is in the range of 200 < rc < 300. * * @param response whose rc is validated. * @return the entity of the response.//from w ww . j a v a 2s .co m * @throws IOException when the rc > 300 and swallowing the response body has a problem.. */ protected final HttpEntity returnEntityWhenStatusValid(HttpResponse response) throws IOException { final StatusLine statusLine = response.getStatusLine(); final HttpEntity entity = response.getEntity(); if (statusLine.getStatusCode() >= HttpStatus.SC_MULTIPLE_CHOICES) { EntityUtils.consume(entity); throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); } return entity; }
From source file:org.apache.asterix.experiment.action.derived.RunRESTIOWaitAction.java
@Override public void doPerform() throws Exception { String uri = MessageFormat.format(REST_URI_TEMPLATE, restHost, String.valueOf(restPort)); HttpGet get = new HttpGet(uri); HttpEntity entity = httpClient.execute(get).getEntity(); EntityUtils.consume(entity); }
From source file:org.jboss.narayana.rts.TxnHelper.java
public static int endTxn(Client client, Set<Link> links) throws IOException { Response response = null;//from w w w .j av a2 s . c o m try { response = client.target(getLink(links, TxLinkNames.TERMINATOR).getUri()).request() .put(Entity.entity(TxStatusMediaType.TX_COMMITTED, TxMediaType.TX_STATUS_MEDIA_TYPE)); int sc = response.getStatus(); EntityUtils.consume((HttpEntity) response.getEntity()); if (sc != HttpURLConnection.HTTP_OK) throw new RuntimeException("endTxn returned " + sc); return sc; } finally { if (response != null) response.close(); } }
From source file:com.nibss.util.Request.java
public void post(String url, List<NameValuePair> list) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); try {//from w w w.j a va 2 s .c o m HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(list)); CloseableHttpResponse response2 = httpclient.execute(httpPost); try { System.out.println(response2.getStatusLine().getStatusCode()); HttpEntity entity2 = response2.getEntity(); EntityUtils.consume(entity2); } finally { response2.close(); } } finally { httpclient.close(); } }
From source file:us.pserver.revok.http.HttpEntityFactory.java
public static void main(String[] args) throws IOException { HttpEntityFactory fac = HttpEntityFactory.instance(new XmlSerializer()).enableGZipCoder() .enableCryptCoder(CryptKey.createRandomKey(CryptAlgorithm.AES_CBC_PKCS5)); class MSG {//from ww w .j a va 2 s . c om String str; public MSG(String s) { str = s; } public String toString() { return "MSG{str=" + str + "}"; } } fac.put(new MSG("Hello EntityFactory!")); HttpEntity ent = fac.create(); ent.writeTo(System.out); System.out.println(); ent = fac.create(); HttpEntityParser ep = HttpEntityParser.instance(new XmlSerializer());//.enableGZipCoder(); ep.parse(ent); System.out.println("* key: " + ep.getCryptKey()); System.out.println("* rob: " + ep.getObject()); EntityUtils.consume(ent); }