Search in sources :

Example 81 with CloseableHttpResponse

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

Example 82 with CloseableHttpResponse

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());
    }
}
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 83 with CloseableHttpResponse

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);
    }
}
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 84 with CloseableHttpResponse

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

Example 85 with CloseableHttpResponse

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."));
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Aggregations

CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)536 HttpGet (org.apache.http.client.methods.HttpGet)242 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)171 StringEntity (org.apache.http.entity.StringEntity)127 JsonNode (com.fasterxml.jackson.databind.JsonNode)125 Test (org.junit.Test)125 HttpPost (org.apache.http.client.methods.HttpPost)107 IOException (java.io.IOException)105 HttpEntity (org.apache.http.HttpEntity)103 Deployment (org.activiti.engine.test.Deployment)87 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)67 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)57 InputStream (java.io.InputStream)53 HttpPut (org.apache.http.client.methods.HttpPut)50 Task (org.activiti.engine.task.Task)41 URI (java.net.URI)36 StatusLine (org.apache.http.StatusLine)34 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)34 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)31 BufferedReader (java.io.BufferedReader)30