Search in sources :

Example 66 with CloseableHttpClient

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());
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpResponseWithoutHeader(com.microsoft.azure.hdinsight.common.HttpResponseWithoutHeader) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HDIException(com.microsoft.azure.hdinsight.sdk.common.HDIException)

Example 67 with CloseableHttpClient

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);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 68 with CloseableHttpClient

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);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 69 with CloseableHttpClient

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");
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BasicResponseHandler(org.apache.http.impl.client.BasicResponseHandler)

Example 70 with CloseableHttpClient

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);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Aggregations

CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)430 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)238 HttpGet (org.apache.http.client.methods.HttpGet)212 Test (org.junit.Test)206 HttpResponse (org.apache.http.HttpResponse)108 HttpEntity (org.apache.http.HttpEntity)92 IOException (java.io.IOException)90 HttpPost (org.apache.http.client.methods.HttpPost)85 StringEntity (org.apache.http.entity.StringEntity)67 InputStream (java.io.InputStream)57 StatusLine (org.apache.http.StatusLine)41 HttpHost (org.apache.http.HttpHost)36 URI (java.net.URI)35 RequestConfig (org.apache.http.client.config.RequestConfig)32 Header (org.apache.http.Header)24 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)24 File (java.io.File)22 HttpPut (org.apache.http.client.methods.HttpPut)22 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)20 ByteArrayInputStream (java.io.ByteArrayInputStream)19