List of usage examples for org.apache.http.util EntityUtils consume
public static void consume(HttpEntity httpEntity) throws IOException
From source file:org.wuspba.ctams.ws.ITSoloContestController.java
@Test public void testListAll() throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build(); LOG.info("Connecting to " + uri.toString()); HttpGet httpGet = new HttpGet(uri); try (CloseableHttpResponse response = httpclient.execute(httpGet)) { assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING); HttpEntity entity = response.getEntity(); CTAMSDocument doc = IntegrationTestUtils.convertEntity(entity); assertEquals(doc.getSoloContests().size(), 1); testEquality(doc.getSoloContests().get(0), TestFixture.INSTANCE.soloContest); EntityUtils.consume(entity); }/*ww w . ja v a2 s . c om*/ }
From source file:net.tirasa.wink.client.asynchttpclient.FutureClientResponse.java
private void createClientResponse(final HttpResponse httpResponse) throws IOException { this.clientResponse = new ClientResponseImpl(); StatusLine statusLine = httpResponse.getStatusLine(); this.clientResponse.setStatusCode(statusLine.getStatusCode()); this.clientResponse.setMessage(statusLine.getReasonPhrase()); this.clientResponse.getAttributes().putAll(this.request.getAttributes()); this.clientResponse.setContentConsumer(new Runnable() { @Override//from w ww . ja v a 2s.co m public void run() { HttpEntity entity = httpResponse.getEntity(); if (entity != null) { try { EntityUtils.consume(entity); } catch (IOException e) { throw new RuntimeException(e); } } } }); Header[] allHeaders = httpResponse.getAllHeaders(); for (Header header : allHeaders) { this.clientResponse.getHeaders().add(header.getName(), header.getValue()); } HttpEntity entity = httpResponse.getEntity(); InputStream is; if (entity == null) { is = new EmptyInputStream(); } else { is = entity.getContent(); } is = this.handler.adaptInputStream(is, this.clientResponse, this.context); this.clientResponse.setEntity(is); }
From source file:org.jboss.as.test.integration.jaxrs.validator.BeanValidationConfiguredGloballyTestCase.java
@Test public void testInvalidRequestsAreAcceptedDependingOnGlobalValidationConfiguration() throws Exception { DefaultHttpClient client = new DefaultHttpClient(new PoolingClientConnectionManager()); HttpGet get = new HttpGet(url + "myjaxrs/globally-configured-validate/3/disabled"); HttpResponse result = client.execute(get); Assert.assertEquals("No constraint violated", 200, result.getStatusLine().getStatusCode()); EntityUtils.consume(result.getEntity()); get = new HttpGet(url + "myjaxrs/globally-configured-validate/3/enabled"); result = client.execute(get);// w ww . j a v a 2s .c o m Assert.assertEquals("Parameter constraint violated", 400, result.getStatusLine().getStatusCode()); }
From source file:nl.nn.adapterframework.http.HttpResponseHandler.java
/** * Consumes the {@link HttpEntity} and will release the connection. * @throws IOException//from w w w . java2 s . c om */ public void close() throws IOException { EntityUtils.consume(httpEntity); content.close(); }
From source file:com.subgraph.vega.internal.crawler.HttpResponseProcessor.java
private void runLoop() throws InterruptedException { while (!stop) { CrawlerTask task = crawlerResponseQueue.take(); if (task.isExitTask()) { crawlerRequestQueue.add(CrawlerTask.createExitTask()); crawlerResponseQueue.add(task); return; }/* w w w .j av a 2s . co m*/ HttpUriRequest req = task.getRequest(); activeRequest = req; try { if (task.getResponse() != null) { task.getResponseProcessor().processResponse(crawler, req, task.getResponse(), task.getArgument()); } } catch (Exception e) { logger.log(Level.WARNING, "Unexpected exception processing crawler request: " + req.getURI(), e); } finally { synchronized (requestLock) { activeRequest = null; } final HttpEntity entity = (task.getResponse() == null) ? (null) : task.getResponse().getRawResponse().getEntity(); if (entity != null) try { EntityUtils.consume(entity); } catch (IOException e) { logger.log(Level.WARNING, "I/O exception consuming request entity content for " + req.getURI() + " : " + e.getMessage()); } } synchronized (counter) { counter.addCompletedTask(); crawler.updateProgress(); } if (task.causedException()) { crawler.notifyException(req, task.getException()); } if (outstandingTasks.decrementAndGet() <= 0) { crawlerRequestQueue.add(CrawlerTask.createExitTask()); crawlerResponseQueue.add(CrawlerTask.createExitTask()); return; } } }
From source file:org.wso2.apim.billing.clients.APIRESTClient.java
public String getSubscriptionByApp(String app) throws Exception { response = sendGetRequest(getSubsUrl + "?action=getSubscriptionByApplication&app=" + app); String res = getResponseBody(response); EntityUtils.consume(response.getEntity()); return res;/*w ww . j ava 2 s .c o m*/ }
From source file:com.bigdata.journal.jini.ha.AbstractHA3BackupTestCase.java
/** * Issue HTTP request to a service to take a snapshot. * /*from w ww . j a v a2s . c om*/ * @param haGlue * The service. * @param percentLogSize * The percent log size parameter for the request (optional). * * @throws Exception */ protected void doSnapshotRequest(final HAGlue haGlue, final Integer percentLogSize) throws Exception { // Client for talking to the NSS. final HttpClient httpClient = new DefaultHttpClient(ccm); // The NSS service URL (NOT the SPARQL end point). final String serviceURL = getNanoSparqlServerURL(haGlue); final ConnectOptions opts = new ConnectOptions( serviceURL + "/status?snapshot" + (percentLogSize != null ? "=" + percentLogSize : "")); opts.method = "GET"; try { final HttpResponse response; RemoteRepository.checkResponseCode(response = doConnect(httpClient, opts)); EntityUtils.consume(response.getEntity()); } catch (IOException ex) { log.error(ex, ex); throw ex; } }
From source file:org.cerberus.util.HTTPSession.java
public int getURL(String url) { LOG.debug(url);//from w w w . j a v a2s . c o m HttpGet get = new HttpGet(url); HttpResponse response = null; HttpEntity entity = null; try { // Execute your request with the given context response = client.execute(get, context); entity = response.getEntity(); EntityUtils.consume(entity); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (response != null && response.getStatusLine() != null) { return response.getStatusLine().getStatusCode(); } return 0; }
From source file:org.mahasen.client.UpdateMetadata.java
/** * @param fileToUpdate// w ww . j a v a2s . c om * @param tags * @throws URISyntaxException * @throws AuthenticationExceptionException * * @throws IOException * @throws UnsupportedEncodingException */ public void updateMetadata(String fileToUpdate, String tags) throws URISyntaxException, AuthenticationExceptionException, IOException, UnsupportedEncodingException, MahasenClientException { httpclient = new DefaultHttpClient(); String userName = clientLoginData.getUserName(); String passWord = clientLoginData.getPassWord(); String hostAndPort = clientLoginData.getHostNameAndPort(); String userId = clientLoginData.getUserId(userName, passWord); Boolean isLogged = clientLoginData.isLoggedIn(); System.out.println(" Is Logged : " + isLogged); if (isLogged == true) { httpclient = WebClientSSLWrapper.wrapClient(httpclient); // this will add file name and tags to user defined property list properties.add(new BasicNameValuePair("fileName", fileToUpdate)); properties.add(new BasicNameValuePair("tags", tags)); URI uri = URIUtils.createURI("https", hostAndPort, -1, "/mahasen/update_ajaxprocessor.jsp", URLEncodedUtils.format(properties, "UTF-8"), null); HttpPost httpPost = new HttpPost(uri); HttpResponse response = httpclient.execute(httpPost); HttpEntity resEntity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); EntityUtils.consume(resEntity); if (response.getStatusLine().getStatusCode() == 900) { throw new MahasenClientException(String.valueOf(response.getStatusLine())); } } else { System.out.println("User has to be logged in to perform this function"); } httpclient.getConnectionManager().shutdown(); }
From source file:org.apache.asterix.experiment.action.derived.RunSQLPPFileAction.java
@Override public void doPerform() throws Exception { FileOutputStream csvFileOut = new FileOutputStream(csvFilePath.toFile()); PrintWriter printer = new PrintWriter(csvFileOut, true); try {/*from w w w . ja va 2 s . co m*/ if (aqlFilePath.toFile().isDirectory()) { for (File f : aqlFilePath.toFile().listFiles()) { queriesToRun.add(f.toPath()); } } else { queriesToRun.add(aqlFilePath); } for (Path p : queriesToRun) { String sqlpp = StandardCharsets.UTF_8.decode(ByteBuffer.wrap(Files.readAllBytes(p))).toString(); String uri = MessageFormat.format(REST_URI_TEMPLATE, restHost, String.valueOf(restPort)); HttpPost post = new HttpPost(uri); post.setHeader(HttpHeaders.CONTENT_TYPE, "application/json"); post.setEntity(new StringEntity(sqlpp, StandardCharsets.UTF_8)); long start = System.currentTimeMillis(); HttpResponse resp = httpClient.execute(post); HttpEntity entity = resp.getEntity(); if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new HttpException("Query returned error" + EntityUtils.toString(entity)); } EntityUtils.consume(entity); long end = System.currentTimeMillis(); long wallClock = end - start; String currLine = p.getFileName().toString() + ',' + wallClock; System.out.println(currLine); printer.print(currLine + '\n'); } } finally { printer.close(); } }