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.ModelConfigurationsTestCase.java
/** * @throws MLHttpClientException/*from w ww . j av a 2 s . com*/ * @throws IOException */ @Test(priority = 2, description = "Get algorithm of the analyses") public void testGetAlgorithm() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient.doHttpGet("/api/analyses/" + analysisId + "/algorithmName"); assertEquals("Unexpected response received", Response.Status.OK.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }
From source file:org.wso2.carbon.ml.analysis.test.ModelConfigurationsTestCase.java
/** * @throws MLHttpClientException//from w w w .j a v a 2 s . c o m * @throws IOException */ @Test(priority = 2, description = "Get algorithm type of the analyses") public void testGetAlgorithmType() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient.doHttpGet("/api/analyses/" + analysisId + "/algorithmType"); assertEquals("Unexpected response received", Response.Status.OK.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }
From source file:com.yahoo.ycsb.webservice.rest.RestClient.java
private int httpDelete(String endpoint) throws IOException { requestTimedout.setIsSatisfied(false); Thread timer = new Thread(new Timer(execTimeout, requestTimedout)); timer.start();//from www.j av a 2s . c o m int responseCode = 200; HttpDelete request = new HttpDelete(endpoint); for (int i = 0; i < headers.length; i = i + 2) { request.setHeader(headers[i], headers[i + 1]); } CloseableHttpResponse response = client.execute(request); responseCode = response.getStatusLine().getStatusCode(); response.close(); client.close(); return responseCode; }
From source file:co.cask.cdap.client.rest.RestStreamClient.java
@Override public void create(String stream) throws IOException { HttpPut putRequest = new HttpPut( restClient.getBaseURL().resolve(String.format("/%s/streams/%s", restClient.getVersion(), stream))); CloseableHttpResponse httpResponse = restClient.execute(putRequest); try {//from ww w. j a v a 2 s.c o m LOG.debug("Create Stream Response Code : {}", httpResponse.getStatusLine().getStatusCode()); RestClient.responseCodeAnalysis(httpResponse); } finally { httpResponse.close(); } }
From source file:org.wso2.carbon.ml.analysis.test.ModelConfigurationsTestCase.java
/** * @throws MLHttpClientException// w ww.j a v a 2 s . c o m * @throws IOException */ @Test(priority = 4, description = "Get hyper parameters of the analyses") public void testGetHyperParameters() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient.doHttpGet("/api/analyses/" + analysisId + "/hyperParameters"); assertEquals("Unexpected response received", Response.Status.OK.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }
From source file:org.brutusin.rpc.client.http.HttpEndpoint.java
private void initPingThread(final int pingSeconds) { this.pingThread = new Thread() { @Override//from ww w . ja v a 2s. c o m public void run() { while (!isInterrupted()) { try { Thread.sleep(1000 * pingSeconds); try { CloseableHttpResponse resp = doExec("rpc.http.ping", null, HttpMethod.GET, null); resp.close(); } catch (ConnectException ex) { LOGGER.log(Level.SEVERE, ex.getMessage() + " (" + HttpEndpoint.this.endpoint + ")"); } catch (IOException ex) { LOGGER.log(Level.SEVERE, ex.getMessage() + " (" + HttpEndpoint.this.endpoint + ")", ex); } } catch (InterruptedException ie) { break; } } } }; this.pingThread.setDaemon(true); this.pingThread.start(); }
From source file:com.cognifide.aet.proxy.RestProxyServer.java
@Override public void addHeader(String name, String value) { CloseableHttpClient httpClient = HttpClients.createSystem(); try {//from w w w . jav a 2 s . co m URIBuilder uriBuilder = new URIBuilder().setScheme(HTTP).setHost(server.getAPIHost()) .setPort(server.getAPIPort()); // Request BMP to add header HttpPost request = new HttpPost( uriBuilder.setPath(String.format("/proxy/%d/headers", server.getProxyPort())).build()); request.setHeader("Content-Type", "application/json"); JSONObject json = new JSONObject(); json.put(name, value); request.setEntity(new StringEntity(json.toString())); // Execute request CloseableHttpResponse response = httpClient.execute(request); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != STATUS_CODE_OK) { throw new UnableToAddHeaderException( "Invalid HTTP Response when attempting to add header" + statusCode); } response.close(); } catch (Exception e) { throw new BMPCUnableToConnectException(String.format("Unable to connect to BMP Proxy at '%s:%s'", server.getAPIHost(), server.getAPIPort()), e); } finally { try { httpClient.close(); } catch (IOException e) { LOGGER.warn("Unable to close httpClient", e); } } }
From source file:org.cloudsimulator.utility.RestAPI.java
public static ResponseMessageByteArray receiveByteArray(final String restAPIURI, final String username, final String password, final String typeOfByteArray) throws IOException { CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpResponse httpResponse = null; ResponseMessageByteArray responseMessageByteArray = null; httpResponse = getRequestBasicAuth(httpClient, escapeURI(restAPIURI), username, password, typeOfByteArray); if (httpResponse != null) { if (httpResponse.getStatusLine() != null) { if (httpResponse.getEntity() != null) { responseMessageByteArray = new ResponseMessageByteArray( httpResponse.getStatusLine().getStatusCode(), httpResponse.getStatusLine().getReasonPhrase(), IOUtils.toByteArray(httpResponse.getEntity().getContent())); } else { responseMessageByteArray = new ResponseMessageByteArray( httpResponse.getStatusLine().getStatusCode(), httpResponse.getStatusLine().getReasonPhrase(), null); }//from w w w . j av a2 s . co m } else { if (httpResponse.getEntity() != null) { responseMessageByteArray = new ResponseMessageByteArray(null, null, IOUtils.toByteArray(httpResponse.getEntity().getContent())); } } httpResponse.close(); } httpClient.close(); return responseMessageByteArray; }
From source file:org.wso2.carbon.ml.dataset.test.CreateDatasetTestCase.java
/** * Test creating a dataset for an invalid DAS table. * //from w w w . j a v a 2 s.c o m * @throws MLHttpClientException * @throws IOException */ @Test(description = "Create a dataset for an invalid DAS table") public void testCreateDatasetForInvalidDASTable() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient.uploadDatasetFromDAS("SampleDataForCreateDatasetTestCase_5", "1.0", "INVALID_TABLE"); assertEquals("Unexpected response received", Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }
From source file:org.wso2.carbon.ml.project.test.MLProjectsTestCase.java
/** * Test creating a project without the project name. * /*from w w w .j a va 2s. c o m*/ * @throws MLHttpClientException * @throws IOException */ @Test(priority = 2, description = "Create a project without name") public void testCreateProjectWithoutName() throws MLHttpClientException, IOException { CloseableHttpResponse response = mlHttpclient.createProject(null, MLIntegrationTestConstants.DATASET_NAME_DIABETES); assertEquals("Unexpected response received", Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusLine().getStatusCode()); response.close(); }