use of org.apache.http.client.methods.CloseableHttpResponse in project azure-tools-for-java by Microsoft.
the class MultiRestTask method call.
@Override
public List<String> call() throws Exception {
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
List<String> results = new ArrayList<>();
for (String path : paths) {
HttpGet httpGet = new HttpGet(path);
httpGet.addHeader("Content-Type", "application/json");
CloseableHttpResponse response = httpclient.execute(httpGet);
int code = response.getStatusLine().getStatusCode();
if (code == 200 || code == 201) {
results.add(EntityUtils.toString(response.getEntity()));
} else {
throw new HDIException(response.getStatusLine().getReasonPhrase(), code);
}
}
return results;
}
use of org.apache.http.client.methods.CloseableHttpResponse in project azure-tools-for-java by Microsoft.
the class RestTask method call.
@Override
public String call() throws Exception {
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
HttpGet httpGet = new HttpGet(path);
httpGet.addHeader("Content-Type", "application/json");
CloseableHttpResponse response = httpclient.execute(httpGet);
HttpResponseWithoutHeader header = getResultFromHttpResponse(response);
if (header.getStatusCode() == 200 || header.getStatusCode() == 201) {
return header.getMessage();
} else {
throw new HDIException(header.getReason(), header.getStatusCode());
}
}
use of org.apache.http.client.methods.CloseableHttpResponse in project azure-tools-for-java by Microsoft.
the class SparkBatchSubmission method createBatchSparkJob.
/**
* create batch spark job
* @param connectUrl : eg http://localhost:8998/batches
* @param submissionParameter : spark submission parameter
* @return response result
*/
public HttpResponse createBatchSparkJob(String connectUrl, SparkSubmissionParameter submissionParameter) throws IOException {
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
HttpPost httpPost = new HttpPost(connectUrl);
httpPost.addHeader("Content-Type", "application/json");
httpPost.addHeader("User-Agent", userAgentName);
StringEntity postingString = new StringEntity(submissionParameter.serializeToJson());
httpPost.setEntity(postingString);
try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
return StreamUtil.getResultFromHttpResponse(response);
}
}
use of org.apache.http.client.methods.CloseableHttpResponse in project azure-tools-for-java by Microsoft.
the class SparkBatchSubmission method getHttpResponseViaGet.
public HttpResponse getHttpResponseViaGet(String connectUrl) throws IOException {
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
HttpGet httpGet = new HttpGet(connectUrl);
httpGet.addHeader("Content-Type", "application/json");
httpGet.addHeader("User-Agent", userAgentName);
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
return StreamUtil.getResultFromHttpResponse(response);
}
}
use of org.apache.http.client.methods.CloseableHttpResponse in project opennms by OpenNMS.
the class JUnitHttpServerTest method testServer.
@Test
@JUnitHttpServer(port = 9162)
public void testServer() throws HttpException, IOException {
HttpUriRequest method = new HttpGet("http://localhost:9162/test.html");
final CloseableHttpResponse response = m_clientWrapper.execute(method);
String responseString = EntityUtils.toString(response.getEntity());
LOG.debug("got response:\n{}", responseString);
assertEquals(200, response.getStatusLine().getStatusCode());
assertTrue(responseString.contains("Purple monkey dishwasher."));
}
Aggregations