Search in sources :

Example 21 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project OpenAttestation by OpenAttestation.

the class ApacheHttpClient method delete.

public ApiResponse delete(String requestURL) throws IOException, SignatureException {
    log.debug("DELETE url: {}", requestURL);
    HttpDelete request = new HttpDelete(requestURL);
    // send the request and print the response
    HttpResponse httpResponse = httpClient.execute(request);
    ApiResponse apiResponse = readResponse(httpResponse);
    request.releaseConnection();
    return apiResponse;
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse)

Example 22 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project OpenAttestation by OpenAttestation.

the class ApacheHttpClient method put.

public ApiResponse put(String requestURL, ApiRequest message) throws IOException, SignatureException {
    log.debug("PUT url: {}", requestURL);
    log.debug("PUT content: {}", message == null ? "(empty)" : message.content);
    HttpPut request = new HttpPut(requestURL);
    if (message != null && message.content != null) {
        request.setEntity(new StringEntity(message.content, ContentType.create(message.contentType.toString(), "UTF-8")));
    }
    HttpResponse httpResponse = httpClient.execute(request);
    ApiResponse apiResponse = readResponse(httpResponse);
    request.releaseConnection();
    return apiResponse;
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut)

Example 23 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project OpenAttestation by OpenAttestation.

the class ApacheHttpClient method post.

public ApiResponse post(String requestURL, ApiRequest message) throws IOException, SignatureException {
    log.debug("POST url: {}", requestURL);
    log.debug("POST content: {}", message == null ? "(empty)" : message.content);
    HttpPost request = new HttpPost(requestURL);
    if (message != null && message.content != null) {
        request.setEntity(new StringEntity(message.content, ContentType.create(message.contentType.toString(), "UTF-8")));
    }
    HttpResponse httpResponse = httpClient.execute(request);
    ApiResponse apiResponse = readResponse(httpResponse);
    request.releaseConnection();
    return apiResponse;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) HttpResponse(org.apache.http.HttpResponse)

Example 24 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project pinot by linkedin.

the class BackfillControllerAPIs method getAllSegments.

/**
   * Fetches the list of all segment names for a table
   * @param tableName
   * @return
   * @throws IOException
   */
public List<String> getAllSegments(String tableName) throws IOException {
    List<String> allSegments = new ArrayList<>();
    HttpClient controllerClient = new DefaultHttpClient();
    HttpGet req = new HttpGet(SEGMENTS_ENDPOINT + URLEncoder.encode(tableName, UTF_8));
    HttpResponse res = controllerClient.execute(controllerHttpHost, req);
    try {
        if (res.getStatusLine().getStatusCode() != 200) {
            throw new IllegalStateException(res.getStatusLine().toString());
        }
        InputStream content = res.getEntity().getContent();
        String response = IOUtils.toString(content);
        List<String> allSegmentsPaths = getSegmentsFromResponse(response);
        for (String segment : allSegmentsPaths) {
            allSegments.add(segment.substring(segment.lastIndexOf("/") + 1));
        }
        LOGGER.info("All segments : {}", allSegments);
    } finally {
        if (res.getEntity() != null) {
            EntityUtils.consume(res.getEntity());
        }
    }
    return allSegments;
}
Also used : InputStream(java.io.InputStream) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 25 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project pinot by linkedin.

the class BackfillControllerAPIs method getSegmentMetadata.

/**
   * Returns the metadata of a segment, given the segment name and table name
   * @param tableName - table where segment resides
   * @param segmentName - name of the segment
   * @return
   * @throws IOException
   */
public Map<String, String> getSegmentMetadata(String tableName, String segmentName) throws IOException {
    Map<String, String> metadata = null;
    HttpClient controllerClient = new DefaultHttpClient();
    HttpGet req = new HttpGet(TABLES_ENDPOINT + URLEncoder.encode(tableName, UTF_8) + "/" + SEGMENTS_ENDPOINT + URLEncoder.encode(segmentName, UTF_8) + "/" + METADATA_ENDPOINT);
    HttpResponse res = controllerClient.execute(controllerHttpHost, req);
    try {
        if (res.getStatusLine().getStatusCode() != 200) {
            throw new IllegalStateException(res.getStatusLine().toString());
        }
        InputStream content = res.getEntity().getContent();
        String metadataResponse = IOUtils.toString(content);
        metadata = getMetadataFromResponse(metadataResponse);
    } finally {
        if (res.getEntity() != null) {
            EntityUtils.consume(res.getEntity());
        }
    }
    return metadata;
}
Also used : InputStream(java.io.InputStream) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Aggregations

HttpResponse (org.apache.http.HttpResponse)4366 Test (org.junit.Test)2158 HttpGet (org.apache.http.client.methods.HttpGet)1833 IOException (java.io.IOException)1110 URI (java.net.URI)834 HttpPost (org.apache.http.client.methods.HttpPost)759 HttpClient (org.apache.http.client.HttpClient)600 HttpEntity (org.apache.http.HttpEntity)541 TestHttpClient (io.undertow.testutils.TestHttpClient)403 InputStream (java.io.InputStream)398 Header (org.apache.http.Header)385 StringEntity (org.apache.http.entity.StringEntity)363 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)344 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)338 HttpPut (org.apache.http.client.methods.HttpPut)320 ArrayList (java.util.ArrayList)316 Identity (org.olat.core.id.Identity)262 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)253 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)209 File (java.io.File)196