List of usage examples for org.apache.http.client.methods CloseableHttpResponse close
public void close() throws IOException;
From source file:org.sead.repositories.reference.util.SEADGoogleLogin.java
static void getTokensFromCode() { access_token = null;// w w w. j a v a 2s . c o m expires_in = -1; token_start_time = -1; refresh_token = null; new File("refresh.txt").delete(); if (gProps == null) { initGProps(); } // Query for token now that user has gone through browser part // of // flow HttpPost tokenRequest = new HttpPost(gProps.token_uri); MultipartEntityBuilder tokenRequestParams = MultipartEntityBuilder.create(); tokenRequestParams.addTextBody("client_id", gProps.client_id); tokenRequestParams.addTextBody("client_secret", gProps.client_secret); tokenRequestParams.addTextBody("code", device_code); tokenRequestParams.addTextBody("grant_type", "http://oauth.net/grant_type/device/1.0"); HttpEntity reqEntity = tokenRequestParams.build(); tokenRequest.setEntity(reqEntity); CloseableHttpClient httpclient = HttpClients.createDefault(); CloseableHttpResponse response = null; try { response = httpclient.execute(tokenRequest); if (response.getStatusLine().getStatusCode() == 200) { HttpEntity resEntity = response.getEntity(); if (resEntity != null) { String responseJSON = EntityUtils.toString(resEntity); ObjectNode root = (ObjectNode) new ObjectMapper().readTree(responseJSON); access_token = root.get("access_token").asText(); refresh_token = root.get("refresh_token").asText(); token_start_time = System.currentTimeMillis() / 1000; expires_in = root.get("expires_in").asInt(); } } else { log.error("Error response from Google: " + response.getStatusLine().getReasonPhrase()); } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (response != null) { try { response.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { httpclient.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:org.wso2.carbon.ml.analysis.test.ModelConfigurationsTestCase.java
/** * Test setting default values to hyper-parameters of an analysis without setting model configs. * //from www . j av a2 s. c o m * @throws MLHttpClientException * @throws IOException */ @Test(priority = 3, description = "Set default values to hyperparameters without setting model configs.") public void testSetDefaultHyperparametersWithoutModelConfigs() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient .doHttpPost("/api/analyses/" + analysisId2 + "/hyperParams/defaults", null); assertEquals("Unexpected response received", Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }
From source file:org.wso2.carbon.ml.analysis.test.ModelConfigurationsTestCase.java
/** * @throws MLHttpClientException/*from w w w . j av a 2s . c om*/ * @throws IOException */ @Test(priority = 4, description = "Get hyper parameters of the analyses and of a algorithm") public void testGetHyperParametersOfAlgorithm() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient .doHttpGet("/api/analyses/" + analysisId + "/hyperParameters?algorithmName=" + ALGORITHM_NAME); assertEquals("Unexpected response received", Response.Status.OK.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }
From source file:org.wso2.carbon.ml.dataset.test.CreateDatasetTestCase.java
/** * Test creating a dataset from a valid csv file. * //from www.j a v a 2 s . c o m * @throws MLHttpClientException * @throws IOException */ @Test(description = "Create a dataset from a CSV file") public void testCreateDatasetFromFile() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient.uploadDatasetFromCSV( MLIntegrationTestConstants.DATASET_NAME_DIABETES, "1.0", MLIntegrationTestConstants.DIABETES_DATASET_SAMPLE); assertEquals("Unexpected response received", Response.Status.OK.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }
From source file:org.wso2.carbon.ml.dataset.test.CreateDatasetTestCase.java
/** * Test Creating a new version of an existing dataset * //from w w w. j av a 2s . c o m * @throws MLHttpClientException * @throws IOException */ @Test(description = "Create a new version of an existing dataset", dependsOnMethods = "testCreateDatasetFromFile") public void testCreateNewDatasetVersion() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient.uploadDatasetFromCSV( MLIntegrationTestConstants.DATASET_NAME_DIABETES, "2.0", MLIntegrationTestConstants.DIABETES_DATASET_SAMPLE); assertEquals("Unexpected response received", Response.Status.OK.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }
From source file:org.wso2.carbon.ml.configs.test.ConfigurationAPITestCase.java
/** * Test retrieving all DAS tables./*www. ja v a 2 s .c om*/ * * @throws MLHttpClientException * @throws IOException * @throws JSONException */ @Test(description = "Get all das tables") public void testGetAllDASTables() throws MLHttpClientException, IOException, JSONException { CloseableHttpResponse response = mlHttpclient.doHttpGet("/api/configs/das/tables"); assertEquals("Unexpected response received", Response.Status.OK.getStatusCode(), response.getStatusLine().getStatusCode()); assertEquals("DAS tables are not populated properly.", true, MLTestUtils.getJsonArrayAsString(response).contains(MLIntegrationTestConstants.DAS_DATASET_SAMPLE)); response.close(); }
From source file:org.wso2.carbon.ml.dataset.test.GetDatasetsTestCase.java
/** * Test retrieving a dataset, given a invalid dataset ID * @throws MLHttpClientException /*w w w .ja v a2 s .co m*/ * @throws IOException */ @Test(description = "Get a dataset with an invalid ID") public void testGetDatasetWithInvalidId() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient.doHttpGet("/api/datasets/" + 999); assertEquals("Unexpected response received", Response.Status.NOT_FOUND.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }
From source file:org.openscore.content.httpclient.ScoreHttpClient.java
private void checkKeepAlive(HttpRequestBase httpRequestBase, PoolingHttpClientConnectionManager connManager, String keepAliveInput, CloseableHttpResponse httpResponse) { boolean keepAlive = StringUtils.isBlank(keepAliveInput) || Boolean.parseBoolean(keepAliveInput); if (!keepAlive) { try {//w w w . j av a 2s.c om httpResponse.close(); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } httpRequestBase.releaseConnection(); connManager.closeExpiredConnections(); } }
From source file:org.wso2.carbon.ml.dataset.test.GetDatasetsTestCase.java
/** * @throws MLHttpClientException // w w w . j av a 2 s . co m * @throws IOException */ @Test(description = "Get all available dataset versions") public void testGetAllDatasetVersions() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient.doHttpGet("/api/datasets/versions"); Assert.assertEquals("Unexpected response received", Response.Status.OK.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }
From source file:com.spectralogic.ds3client.NetworkClientImpl.java
@Override public WebResponse getResponse(final Ds3Request request) throws IOException, SignatureException { try (final RequestExecutor requestExecutor = new RequestExecutor(this.client, host, request)) { int redirectCount = 0; do {/*w w w . j ava 2 s . com*/ final CloseableHttpResponse response = requestExecutor.execute(); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_TEMPORARY_REDIRECT) { redirectCount++; response.close(); LOG.info("Performing retry - attempt: " + redirectCount); } else { LOG.info("Got response from server"); return new WebResponseImpl(response); } } while (redirectCount < this.connectionDetails.getRetries()); throw new TooManyRedirectsException(redirectCount); } }