org.apache.http.client.entity.GzipCompressingEntity Java Examples

The following examples show how to use org.apache.http.client.entity.GzipCompressingEntity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InfluxDBPublisher.java    From beam with Apache License 2.0 6 votes vote down vote up
private static void publishNexmark(
    final Collection<Map<String, Object>> results, final InfluxDBSettings settings)
    throws Exception {

  final HttpClientBuilder builder = provideHttpBuilder(settings);
  final HttpPost postRequest = providePOSTRequest(settings);
  final StringBuilder metricBuilder = new StringBuilder();
  results.forEach(
      map ->
          metricBuilder
              .append(map.get("measurement"))
              .append(",")
              .append(getKV(map, "runner"))
              .append(" ")
              .append(getKV(map, "runtimeMs"))
              .append(",")
              .append(getKV(map, "numResults"))
              .append(" ")
              .append(map.get("timestamp"))
              .append('\n'));

  postRequest.setEntity(
      new GzipCompressingEntity(new ByteArrayEntity(metricBuilder.toString().getBytes(UTF_8))));

  executeWithVerification(postRequest, builder);
}
 
Example #2
Source File: HttpConnectionPool.java    From Poseidon with Apache License 2.0 5 votes vote down vote up
/**
 * Method for executing HTTP PUT request
 */
public HttpResponse doPUT(String uri, byte[] data, Map<String, String> requestHeaders) throws Exception {
    HttpPut request = new HttpPut(constructUrl(uri));
    if (data != null) {
        if (this.requestGzipEnabled) {
            request.addHeader(CONTENT_ENCODING, COMPRESSION_TYPE);
            request.setEntity(new GzipCompressingEntity(new ByteArrayEntity(data)));
        } else {
            request.setEntity(new ByteArrayEntity(data));
        }
    }
    setRequestHeaders(request, requestHeaders);
    return execute(request);
}
 
Example #3
Source File: HttpConnectionPool.java    From Poseidon with Apache License 2.0 5 votes vote down vote up
/**
 * Method for executing HTTP POST request
 */
public HttpResponse doPOST(String uri, byte[] data, Map<String, String> requestHeaders) throws Exception {
    HttpPost request = new HttpPost(constructUrl(uri));
    if (data != null) {
        if (this.requestGzipEnabled) {
            request.addHeader(CONTENT_ENCODING, COMPRESSION_TYPE);
            request.setEntity(new GzipCompressingEntity(new ByteArrayEntity(data)));
        } else {
            request.setEntity(new ByteArrayEntity(data));
        }
    }
    setRequestHeaders(request, requestHeaders);
    return execute(request);
}
 
Example #4
Source File: HttpConnectionPool.java    From Poseidon with Apache License 2.0 5 votes vote down vote up
/**
   * Method for executing HTTP POST request with form params
   */
  public HttpResponse doPOST(String uri, List<NameValuePair> formParams , Map<String, String> requestHeaders) throws Exception {
      HttpPost request = new HttpPost(constructUrl(uri));
if (this.requestGzipEnabled) {
	request.addHeader(CONTENT_ENCODING, COMPRESSION_TYPE);
	request.setEntity(new GzipCompressingEntity(new UrlEncodedFormEntity(formParams)));
} else {
	request.setEntity(new UrlEncodedFormEntity(formParams));
}
      setRequestHeaders(request, requestHeaders);
      return execute(request);
  }
 
Example #5
Source File: HttpConnectionPool.java    From Poseidon with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param request
 * @param data
 */
private void setRequestBody(HttpEntityEnclosingRequestBase request, byte[] data) {
    if (data != null) {
        if (this.requestGzipEnabled) {
            request.addHeader(CONTENT_ENCODING, COMPRESSION_TYPE);
            request.setEntity(new GzipCompressingEntity(new ByteArrayEntity(data)));
        } else {
            request.setEntity(new ByteArrayEntity(data));
        }
    }
}
 
Example #6
Source File: SimpleHttpClient.java    From vespa with Apache License 2.0 4 votes vote down vote up
public RequestExecutor setGzipContent(String content) {
    this.entity = new GzipCompressingEntity(new StringEntity(content, StandardCharsets.UTF_8));
    return this;
}