List of usage examples for org.apache.http.client.methods CloseableHttpResponse close
public void close() throws IOException;
From source file:org.wso2.carbon.ml.analysis.test.FeatureProcessingTestCase.java
/** * //from w w w . j a v a 2 s .c o m * @throws MLHttpClientException * @throws IOException */ @Test(priority = 3, description = "Get all features") public void testGetAllFeatures() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient.doHttpGet("/api/analyses/" + analysisId + "/features"); assertEquals("Unexpected response received", Response.Status.OK.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }
From source file:jchat.test.RestTest.java
private String getBody(CloseableHttpResponse response) throws Exception { String body = null;//from www . ja v a 2 s . com try { HttpEntity entity = response.getEntity(); body = EntityUtils.toString(entity); EntityUtils.consume(entity); } finally { response.close(); } return body; }
From source file:org.cloudfoundry.identity.uaa.integration.FormLoginIntegrationTests.java
@Test public void testSuccessfulAuthenticationFlow() throws Exception { //request home page / String location = serverRunning.getBaseUrl() + "/"; HttpGet httpget = new HttpGet(location); CloseableHttpResponse response = httpclient.execute(httpget); assertEquals(OK.value(), response.getStatusLine().getStatusCode()); String body = EntityUtils.toString(response.getEntity()); EntityUtils.consume(response.getEntity()); response.close(); httpget.completed();//from www . j a v a 2 s .c om assertTrue(body.contains("/login.do")); assertTrue(body.contains("username")); assertTrue(body.contains("password")); String csrf = IntegrationTestUtils.extractCookieCsrf(body); HttpUriRequest loginPost = RequestBuilder.post().setUri(serverRunning.getBaseUrl() + "/login.do") .addParameter("username", testAccounts.getUserName()) .addParameter("password", testAccounts.getPassword()) .addParameter(CookieBasedCsrfTokenRepository.DEFAULT_CSRF_COOKIE_NAME, csrf).build(); response = httpclient.execute(loginPost); assertEquals(FOUND.value(), response.getStatusLine().getStatusCode()); location = response.getFirstHeader("Location").getValue(); response.close(); httpget = new HttpGet(location); response = httpclient.execute(httpget); assertEquals(OK.value(), response.getStatusLine().getStatusCode()); body = EntityUtils.toString(response.getEntity()); response.close(); assertTrue(body.contains("Sign Out")); }
From source file:org.wso2.carbon.ml.analysis.test.FeatureProcessingTestCase.java
/** * //from ww w . ja v a 2s . c om * @throws MLHttpClientException * @throws IOException */ @Test(priority = 4, description = "Get summary stats - without providing a feature") public void testGetSummaryStatsWithoutFeature() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient.doHttpGet("/api/analyses/" + analysisId + "/stats"); assertEquals("Unexpected response received", Response.Status.NOT_FOUND.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }
From source file:org.wso2.carbon.ml.configs.test.ConfigurationAPITestCase.java
/** * Test retrieving default hyper params of an algorithm. * /*w ww. j a v a 2s .c o m*/ * @throws MLHttpClientException * @throws IOException */ @Test(description = "Retrieve hyper params of an algorithm") public void testGetHyperParamsOfAlgorithm() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient .doHttpGet("/api/configs/algorithms/LOGISTIC_REGRESSION/hyperParams"); assertEquals("Unexpected response received", Response.Status.OK.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }
From source file:org.wso2.carbon.ml.project.test.CreateProjectsTestCase.java
/** * Test creating a project with a duplicate project name. * @throws MLHttpClientException /*from ww w .j a v a2 s . c o m*/ * @throws IOException */ //FIXME: This should fail!! @Test(description = "Create a project with duplicate Name", dependsOnMethods = "testCreateProject") public void testCreateProjectWithDuplicateName() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient.createProject("TestProjectForCreatProjectTestCase", MLIntegrationTestConstants.DATASET_NAME); assertEquals("Unexpected response recieved", Response.Status.OK.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }
From source file:org.wso2.carbon.ml.project.test.CreateProjectsTestCase.java
/** * Test creating a project./*ww w. j a va 2s.c om*/ * @throws MLHttpClientException * @throws IOException */ @Test(description = "Create a project") public void testCreateProject() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient.createProject(MLIntegrationTestConstants.PROJECT_NAME, MLIntegrationTestConstants.DATASET_NAME); assertEquals("Unexpected response recieved", Response.Status.OK.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }
From source file:org.elasticsearch.river.solr.support.SolrIndexer.java
public void clearDocuments() throws IOException { HttpPost httpPost = new HttpPost(solrUrl + "?commit=true"); httpPost.setHeader("Content-type", "application/xml"); httpPost.setEntity(new StringEntity("<delete><query>*:*</query></delete>")); CloseableHttpResponse response = httpClient.execute(httpPost); try {//from w w w .j ava 2 s . c om if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("documents were not properly cleared"); } } finally { EntityUtils.consume(response.getEntity()); response.close(); } }
From source file:fridgegameinstaller.MCJsonConf.java
public static void getJson(String path, int mb) throws IOException { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet("http://api.fridgegame.com/mcconf/Fridgegame.json"); CloseableHttpResponse response1 = httpclient.execute(httpGet); try {/*from w w w. j a v a2 s. co m*/ System.out.println(httpGet.toString()); System.out.println(response1.getStatusLine()); BufferedReader br = new BufferedReader(new InputStreamReader(response1.getEntity().getContent())); String a; String output = ""; while ((a = br.readLine()) != null) { output += a + "\n"; } System.out.println(output); try { JSONObject json = new JSONObject(output); String mcArgs = json.getString("minecraftArguments"); String regex = "(-Xmx[^ ]*)"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(mcArgs); String newArgs = m.replaceAll("-Xmx" + mb + "M"); json.put("minecraftArguments", newArgs); FileWriter file = new FileWriter(path); try { file.write(json.toString()); } catch (IOException e) { e.printStackTrace(); } finally { file.flush(); file.close(); } } catch (JSONException e) { } } finally { response1.close(); } }
From source file:com.tremolosecurity.unison.proxy.auth.openidconnect.loadUser.LoadAttributesFromWS.java
public Map loadUserAttributesFromIdP(HttpServletRequest request, HttpServletResponse response, ConfigManager cfg, HashMap<String, Attribute> authParams, Map accessToken) throws Exception { String bearerTokenName = authParams.get("bearerTokenName").getValues().get(0); String url = authParams.get("restURL").getValues().get(0); BasicHttpClientConnectionManager bhcm = new BasicHttpClientConnectionManager( GlobalEntries.getGlobalEntries().getConfigManager().getHttpClientSocketRegistry()); RequestConfig rc = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build(); CloseableHttpClient http = HttpClients.custom().setConnectionManager(bhcm).setDefaultRequestConfig(rc) .build();//from w w w . j a v a 2s . c o m HttpGet get = new HttpGet(url); get.addHeader("Authorization", "Bearer " + request.getSession().getAttribute(bearerTokenName)); CloseableHttpResponse httpResp = http.execute(get); BufferedReader in = new BufferedReader(new InputStreamReader(httpResp.getEntity().getContent())); StringBuffer token = new StringBuffer(); String line = null; while ((line = in.readLine()) != null) { token.append(line); } httpResp.close(); bhcm.close(); Map jwtNVP = com.cedarsoftware.util.io.JsonReader.jsonToMaps(token.toString()); return jwtNVP; }