use of org.apache.http.impl.client.CloseableHttpClient 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.impl.client.CloseableHttpClient 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.impl.client.CloseableHttpClient 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.impl.client.CloseableHttpClient in project libresonic by Libresonic.
the class AudioScrobblerService method executeRequest.
private String[] executeRequest(HttpUriRequest request) throws IOException {
try (CloseableHttpClient client = HttpClients.createDefault()) {
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = client.execute(request, responseHandler);
return response.split("\\n");
}
}
use of org.apache.http.impl.client.CloseableHttpClient in project azure-tools-for-java by Microsoft.
the class SparkInteractiveSessions method getSessionFullLog.
/**
* @param connectUrl : eg http://localhost:8998/sessions
* @param sessionId : session Id
* @return response result
* @throws IOException
*/
public HttpResponse getSessionFullLog(String connectUrl, int sessionId) throws IOException {
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
HttpGet httpGet = new HttpGet(connectUrl + "/" + sessionId + "/log?from=0&size=" + Integer.MAX_VALUE);
httpGet.addHeader("Content-Type", "application/json");
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
return StreamUtil.getResultFromHttpResponse(response);
}
}
Aggregations