List of usage examples for org.apache.http.client.methods CloseableHttpResponse getEntity
HttpEntity getEntity();
From source file:com.yahoo.sql4d.sql4ddriver.DruidNodeAccessor.java
/** * This ensures the response body is completely consumed and hence the HttpClient * object will be return back to the pool successfully. * @param resp //from w w w .jav a 2 s . c om */ public void returnClient(CloseableHttpResponse resp) { try { if (resp != null) { EntityUtils.consume(resp.getEntity()); } } catch (IOException ex) { //TODO: Could not consume response completely. This is serious because the client will not be returned back to pool. log.error("Error returning client to pool {}", ExceptionUtils.getStackTrace(ex)); } }
From source file:org.ambraproject.wombat.service.remote.AbstractRemoteService.java
/** * Get a response and open the response entity. * * @param target the request to send/*from ww w . j av a 2s .com*/ * @return the response entity * @throws IOException on making the request * @throws RuntimeException if a response is received but it has no response entity object * @see org.apache.http.HttpResponse#getEntity() */ private HttpEntity requestEntity(HttpUriRequest target) throws IOException { Preconditions.checkNotNull(target); // We must leave the response open if we return a valid stream, but must close it otherwise. boolean returningResponse = false; CloseableHttpResponse response = null; try { response = getResponse(target); HttpEntity entity = response.getEntity(); if (entity == null) { throw new RuntimeException("No response"); } returningResponse = true; return entity; } finally { if (!returningResponse && response != null) { response.close(); } } }
From source file:ch.ralscha.extdirectspring_itest.MyModelControlerTest.java
@Test public void testApi() throws IOException { HttpGet g = new HttpGet("http://localhost:9998/controller/api.js?group=itest_base"); CloseableHttpResponse response = this.client.execute(g); try {//from w ww .ja v a 2 s . co m String responseString = EntityUtils.toString(response.getEntity()); String contentType = response.getFirstHeader("Content-Type").getValue(); ApiControllerTest.compare(responseString, contentType, api(), ApiRequestParams.builder().build()); SimpleServiceTest.assertCacheHeaders(response, false); } finally { IOUtils.closeQuietly(response); } }
From source file:ch.ralscha.extdirectspring_itest.MyModelControlerTest.java
@Test public void testApiDebug() throws IOException { HttpGet g = new HttpGet("http://localhost:9998/controller/api-debug.js?group=itest_base"); CloseableHttpResponse response = this.client.execute(g); try {/* w w w . j a v a2 s . c o m*/ String responseString = EntityUtils.toString(response.getEntity()); String contentType = response.getFirstHeader("Content-Type").getValue(); ApiControllerTest.compare(responseString, contentType, api(), ApiRequestParams.builder().build()); SimpleServiceTest.assertCacheHeaders(response, false); } finally { IOUtils.closeQuietly(response); } }
From source file:ch.ralscha.extdirectspring_itest.MyModelControlerTest.java
@Test public void testApiFingerprinted() throws IOException { HttpGet g = new HttpGet("http://localhost:9998/controller/api-1.1.1.js?group=itest_base"); CloseableHttpResponse response = this.client.execute(g); try {/*from w ww. j a v a 2 s . c om*/ String responseString = EntityUtils.toString(response.getEntity()); String contentType = response.getFirstHeader("Content-Type").getValue(); ApiControllerTest.compare(responseString, contentType, api(), ApiRequestParams.builder().build()); SimpleServiceTest.assertCacheHeaders(response, true); } finally { IOUtils.closeQuietly(response); } }
From source file:ch.ralscha.extdirectspring_itest.MyModelServiceTest.java
@Test public void testApi() throws IOException { HttpGet g = new HttpGet("http://localhost:9998/controller/api.js?group=itest_base_service"); CloseableHttpResponse response = this.client.execute(g); try {/* ww w.j a v a 2s . com*/ String responseString = EntityUtils.toString(response.getEntity()); String contentType = response.getFirstHeader("Content-Type").getValue(); ApiControllerTest.compare(responseString, contentType, api(), ApiRequestParams.builder().build()); SimpleServiceTest.assertCacheHeaders(response, false); } finally { IOUtils.closeQuietly(response); } }
From source file:ch.ralscha.extdirectspring_itest.MyModelServiceTest.java
@Test public void testApiDebug() throws IOException { HttpGet g = new HttpGet("http://localhost:9998/controller/api-debug.js?group=itest_base_service"); CloseableHttpResponse response = this.client.execute(g); try {//from ww w.j av a 2s. co m String responseString = EntityUtils.toString(response.getEntity()); String contentType = response.getFirstHeader("Content-Type").getValue(); ApiControllerTest.compare(responseString, contentType, api(), ApiRequestParams.builder().build()); SimpleServiceTest.assertCacheHeaders(response, false); } finally { IOUtils.closeQuietly(response); } }
From source file:ch.ralscha.extdirectspring_itest.MyModelServiceTest.java
@Test public void testApiFingerprinted() throws IOException { HttpGet g = new HttpGet("http://localhost:9998/controller/api-1.1.1.js?group=itest_base_service"); CloseableHttpResponse response = this.client.execute(g); try {//from www. j a v a2s.c o m String responseString = EntityUtils.toString(response.getEntity()); String contentType = response.getFirstHeader("Content-Type").getValue(); ApiControllerTest.compare(responseString, contentType, api(), ApiRequestParams.builder().build()); SimpleServiceTest.assertCacheHeaders(response, true); } finally { IOUtils.closeQuietly(response); } }
From source file:com.msds.km.service.Impl.YunmaiAPIDrivingLicenseRecognitionServcieiImpl.java
@Override protected DrivingLicense recognitionInternal(File file) throws RecognitionException { try {/*from www . ja v a2 s. c o m*/ HttpPost httppost = new HttpPost(POST_URL); FileBody fileBody = new FileBody(file); HttpEntity reqEntity = MultipartEntityBuilder.create().addPart("img", fileBody) .addTextBody("action", "driving").addTextBody("callbackurl", "/idcard/").build(); httppost.setEntity(reqEntity); CloseableHttpResponse response = httpclient.execute(httppost); try { String content = EntityUtils.toString(response.getEntity()); EntityUtils.consume(response.getEntity()); return this.parseDrivingLicense(content); } catch (IOException e) { throw new RecognitionException( "can not post request to the url:" + POST_URL + ", please check the network.", e); } finally { try { response.close(); } catch (IOException e) { throw new RecognitionException( "can not post request to the url:" + POST_URL + ", please check the network.", e); } } } catch (FileNotFoundException e) { throw new RecognitionException( "the file can not founded:" + file.getAbsolutePath() + ", please check the file.", e); } catch (ClientProtocolException e) { throw new RecognitionException( "can not post request to the url:" + POST_URL + ", please check the network.", e); } catch (IOException e) { throw new RecognitionException( "can not post request to the url:" + POST_URL + ", please check the network.", e); } }
From source file:org.wso2.ml.conf.MLConfiguration.java
public void runConfiguration() { try {/*from w ww.j a v a 2 s. com*/ System.out.println("========== Uploading Dataset ============"); mlClient.createdDataSet(confMapObjectValued.get(MLConstants.KEY_DATASET)); Thread.sleep(2000); System.out.println("========== Creating Project ============="); mlClient.createProject(confMapObjectValued.get(MLConstants.KEY_PROJECT)); System.out.println("========== Getting projectID ============="); CloseableHttpResponse response = mlClient.getProject(confMapObjectValued.get(MLConstants.KEY_PROJECT)); String bodyAsString = EntityUtils.toString(response.getEntity()); Thread.sleep(2000); JSONParser parser = new JSONParser(); JSONObject o = (JSONObject) parser.parse(bodyAsString); long projectId = (Long) o.get("id"); System.out.println("========== Creating Analysis ============="); mlClient.createAnalysis(confMapObjectValued.get(MLConstants.KEY_ANALYSIS), projectId); System.out.println("========== Getting AnalysisID ============="); response = mlClient.getAnalysis(confMapObjectValued.get(MLConstants.KEY_ANALYSIS), projectId); bodyAsString = EntityUtils.toString(response.getEntity()); Thread.sleep(2000); o = (JSONObject) parser.parse(bodyAsString); long analysisId = (Long) o.get("id"); System.out.println("========== Setting Model Configs ============="); mlClient.setModelConfigs(confMapArrayValued.get(MLConstants.KEY_MODELCONFIG), analysisId); System.out.println("========== Setting Default Hyper-Params ============="); mlClient.setDefaultHyperParams(analysisId); } catch (Exception e) { e.printStackTrace(); } }