Search in sources :

Example 1 with HttpResponseWithoutHeader

use of com.microsoft.azure.hdinsight.common.HttpResponseWithoutHeader in project azure-tools-for-java by Microsoft.

the class RestTask method getResultFromHttpResponse.

private static HttpResponseWithoutHeader getResultFromHttpResponse(@NotNull CloseableHttpResponse response) throws IOException {
    int code = response.getStatusLine().getStatusCode();
    String reason = response.getStatusLine().getReasonPhrase();
    HttpEntity entity = response.getEntity();
    try (InputStream inputStream = entity.getContent()) {
        String response_content = getResultFromInputStream(inputStream);
        return new HttpResponseWithoutHeader(code, response_content, reason);
    }
}
Also used : HttpResponseWithoutHeader(com.microsoft.azure.hdinsight.common.HttpResponseWithoutHeader) HttpEntity(org.apache.http.HttpEntity) InputStream(java.io.InputStream)

Example 2 with HttpResponseWithoutHeader

use of com.microsoft.azure.hdinsight.common.HttpResponseWithoutHeader 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)

Aggregations

HttpResponseWithoutHeader (com.microsoft.azure.hdinsight.common.HttpResponseWithoutHeader)2 HDIException (com.microsoft.azure.hdinsight.sdk.common.HDIException)1 InputStream (java.io.InputStream)1 HttpEntity (org.apache.http.HttpEntity)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1