List of usage examples for org.apache.http.client.methods CloseableHttpResponse close
public void close() throws IOException;
From source file:com.ibm.watson.developer_cloud.professor_languo.pipeline.RnrMergerAndRanker.java
/** * Deletes the specified ranker/* ww w.j av a2 s . c o m*/ * * @param ranker_id ofthe ranker to be deleted * @throws ClientProtocolException * @throws IOException * @throws JSONException */ public static void deleteRanker(CloseableHttpClient client, String ranker_id) throws ClientProtocolException, IOException { JSONObject res; try { HttpDelete httpdelete = new HttpDelete(ranker_url + "/" + ranker_id); httpdelete.setHeader("Content-Type", "application/json"); CloseableHttpResponse response = client.execute(httpdelete); try { String result = EntityUtils.toString(response.getEntity()); res = (JSONObject) JSON.parse(result); if (res.isEmpty()) { logger.info(MessageFormat.format(Messages.getString("RetrieveAndRank.RANKER_DELETE"), //$NON-NLS-1$ ranker_id)); } else { logger.info(MessageFormat.format(Messages.getString("RetrieveAndRank.RANKER_DELETE_FAIL"), //$NON-NLS-1$ ranker_id)); } } catch (NullPointerException | JSONException e) { logger.error(e.getMessage()); } finally { response.close(); } } finally { client.close(); } }
From source file:org.wso2.carbon.ml.analysis.test.DeleteAnalysesTestCase.java
/** * Test deleting a non-existing analysis. * //from w w w. j av a2 s . c o m * @throws MLHttpClientException * @throws IOException */ @Test(description = "Delete a non-existing analysis") public void testDeleteNonExistingAnalysis() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient.doHttpDelete("/api/analyses/" + 100); assertEquals("Unexpected response received", Response.Status.OK.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }
From source file:org.wso2.carbon.ml.project.test.DeleteProjectsTestCase.java
/** * Test deleting a project.//from w ww .jav a 2s. c o m * @throws MLHttpClientException * @throws IOException */ @Test(description = "Delete an exsisting project") public void testDeleteProject() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient.doHttpDelete("/api/projects/" + projectName); assertEquals("Unexpected response recieved", Response.Status.OK.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }
From source file:org.wildfly.test.integration.microprofile.health.MicroProfileHealthHTTPEndpointTestCase.java
void checkGlobalOutcome(ManagementClient managementClient, boolean mustBeUP, String probeName) throws IOException { final String healthURL = "http://" + managementClient.getMgmtAddress() + ":" + managementClient.getMgmtPort() + "/health"; try (CloseableHttpClient client = HttpClients.createDefault()) { CloseableHttpResponse resp = client.execute(new HttpGet(healthURL)); assertEquals(mustBeUP ? 200 : 503, resp.getStatusLine().getStatusCode()); String content = getContent(resp); resp.close(); try (JsonReader jsonReader = Json.createReader(new StringReader(content))) { JsonObject payload = jsonReader.readObject(); String outcome = payload.getString("outcome"); assertEquals(mustBeUP ? "UP" : "DOWN", outcome); if (probeName != null) { for (JsonValue check : payload.getJsonArray("checks")) { if (probeName.equals(check.asJsonObject().getString("name"))) { // probe name found assertEquals(mustBeUP ? "UP" : "DOWN", check.asJsonObject().getString("state")); return; }//ww w . j av a 2s . c o m } fail("Probe named " + probeName + " not found in " + content); } } } }
From source file:org.wso2.carbon.ml.analysis.test.DeleteAnalysesTestCase.java
/** * Test deleting an analysis by name.//w ww .j av a2 s. c om * * @throws MLHttpClientException * @throws IOException */ @Test(description = "Delete an analysis") public void testDeleteAnalysis() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient.doHttpDelete("/api/analyses/" + analysisId); assertEquals("Unexpected response received", Response.Status.OK.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }
From source file:org.wildfly.test.integration.microprofile.health.MicroProfileHealthSecuredHTTPEndpointTestCase.java
@Test public void securedHTTPEndpointWithoutUserDefined() throws Exception { final String healthURL = "http://" + managementClient.getMgmtAddress() + ":" + managementClient.getMgmtPort() + "/health"; try (CloseableHttpClient client = HttpClients.createDefault()) { CloseableHttpResponse resp = client.execute(new HttpGet(healthURL)); assertEquals(401, resp.getStatusLine().getStatusCode()); String content = MicroProfileHealthHTTPEndpointTestCase.getContent(resp); resp.close(); assertTrue("'401 - Unauthorized' message is expected", content.contains("401 - Unauthorized")); }//from w w w . j a v a 2 s .c o m }
From source file:org.wso2.carbon.ml.project.test.DeleteProjectsTestCase.java
/** * Test deleting a non-existing project. * @throws MLHttpClientException //from w w w . j a v a 2 s .c o m * @throws IOException */ @Test(description = "Delete an exsisting project") public void testDeleteNonExistingProject() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient.doHttpDelete("/api/projects/" + "NonExistingProjectName"); assertEquals("Unexpected response recieved", Response.Status.OK.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }
From source file:org.cloudfoundry.identity.uaa.integration.FormLoginIntegrationTests.java
@Test public void testUnauthenticatedRedirect() throws Exception { String location = serverRunning.getBaseUrl() + "/"; HttpGet httpget = new HttpGet(location); httpget.setConfig(RequestConfig.custom().setRedirectsEnabled(false).build()); CloseableHttpResponse response = httpclient.execute(httpget); assertEquals(FOUND.value(), response.getStatusLine().getStatusCode()); location = response.getFirstHeader("Location").getValue(); response.close(); httpget.completed();//from w w w . ja v a 2 s. c om assertTrue(location.contains("/login")); }
From source file:com.abc.turkey.service.unfreeze.SmsService.java
private String checkRes(String res, HttpUriRequest lastRequest) throws Exception { String errorCode = JSON.parseObject(res).getString("error"); if (errorCode == null) { return res; }// w w w . j av a2 s . c o m if (errorCode.equals("10001")) { // ,,?? login(); CloseableHttpResponse response = httpclient.execute(lastRequest); res = EntityUtils.toString(response.getEntity(), "utf8"); logger.debug(res); response.close(); } else { // throw new ServiceException("Sms api error, code: " + errorCode); } return res; }
From source file:org.wso2.carbon.ml.analysis.test.AddFeaturesTestCase.java
/** * Test adding default values to customized features an analysis. * @throws MLHttpClientException /*ww w. jav a 2s .co m*/ * @throws IOException */ @Test(description = "Add default values to customized features") public void testAddDefaultsToCustomizedFeatures() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient.setFeartureDefaults(MLIntegrationTestConstants.ANALYSIS_ID); assertEquals("Unexpected response recieved", Response.Status.OK.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }