com.sun.jersey.api.client.filter.GZIPContentEncodingFilter Java Examples

The following examples show how to use com.sun.jersey.api.client.filter.GZIPContentEncodingFilter. 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: ApiClient.java    From forge-api-java-client with Apache License 2.0 6 votes vote down vote up
/**
 * Build the Client used to make HTTP requests with the latest settings,
 * i.e. objectMapper and debugging.
 * TODO: better to use the Builder Pattern?
 */
public ApiClient rebuildHttpClient() {
  // Add the JSON serialization support to Jersey
  JacksonJsonProvider jsonProvider = new JacksonJsonProvider(objectMapper);
  DefaultClientConfig conf = new DefaultClientConfig();
  conf.getSingletons().add(jsonProvider);
  Client client = Client.create(conf);
  if (debugging) {
    client.addFilter(new LoggingFilter());
  }
  
  //to solve the issue of GET:metadata/:guid with accepted encodeing is 'gzip' 
  //in the past, when clients use gzip header, actually it doesn't trigger a gzip encoding... So everything is fine 
  //After the release, the content is return in gzip, while the sdk doesn't handle it correctly
  client.addFilter(new GZIPContentEncodingFilter(false));

  this.httpClient = client;
  return this;
}
 
Example #2
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Build the Client used to make HTTP requests with the latest settings,
 * i.e. objectMapper and debugging.
 * TODO: better to use the Builder Pattern?
 * @return API client
 */
public ApiClient rebuildHttpClient() {
  // Add the JSON serialization support to Jersey
  JacksonJsonProvider jsonProvider = new JacksonJsonProvider(objectMapper);
  DefaultClientConfig conf = new DefaultClientConfig();
  conf.getSingletons().add(jsonProvider);
  Client client = Client.create(conf);
  client.addFilter(new GZIPContentEncodingFilter(false));
  if (debugging) {
    client.addFilter(new LoggingFilter());
  }
  this.httpClient = client;
  return this;
}
 
Example #3
Source File: HmacClientFilterTest.java    From jersey-hmac-auth with Apache License 2.0 5 votes vote down vote up
@Test
public void validateSignatureWhenContentIsPojo() throws Exception {
    Connection connection = null;
    try {
        // Start the server
        RequestConfiguration requestConfiguration =
            RequestConfiguration.builder().withApiKeyQueryParamName("passkey")
                    .withSignatureHttpHeader("duck-duck-signature-header")
                    .withTimestampHttpHeader("duck-duck-timestamp-header")
                    .withVersionHttpHeader("duck-duck-version-header")
                    .build();
        ValidatingHttpServer server = new SignatureValidatingHttpServer(port, secretKey, requestConfiguration);
        connection = server.connect();

        // Create a client with the filter that is under test
        Client client = createClient();
        client.addFilter(new HmacClientFilter(apiKey, secretKey, client.getMessageBodyWorkers(), requestConfiguration));
        client.addFilter(new GZIPContentEncodingFilter(true));

        // Send a pizza in the request body
        Pizza pizza = new Pizza();
        pizza.setTopping("olive");
        client.resource(server.getUri())
                .type(MediaType.APPLICATION_JSON_TYPE)
                .put(pizza);

    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}
 
Example #4
Source File: ApiClient.java    From docusign-java-client with MIT License 5 votes vote down vote up
/**
 * Build the Client used to make HTTP requests with the latest settings,
 * i.e. objectMapper and debugging.
 * TODO: better to use the Builder Pattern?
 * @return API client
 */
public ApiClient rebuildHttpClient() {
  // Add the JSON serialization support to Jersey
  JacksonJsonProvider jsonProvider = new JacksonJsonProvider(objectMapper);
  DefaultClientConfig conf = new DefaultClientConfig();
  conf.getSingletons().add(jsonProvider);
  Client client = Client.create(conf);
  client.addFilter(new GZIPContentEncodingFilter(false));
  if (debugging) {
    client.addFilter(new LoggingFilter());
  }
  this.httpClient = client;
  return this;
}
 
Example #5
Source File: ThreadPoolRequestReplicator.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
private WebResource.Builder createResourceBuilder() {
    // convert parameters to a more convenient data structure
    final MultivaluedMap<String, String> map = new MultivaluedMapImpl();

    if (entity instanceof MultivaluedMap) {
        map.putAll((Map) entity);
    }

    // create the resource
    WebResource resource = client.resource(uri);

    if (responseMapper.isResponseInterpreted(uri, method)) {
        resource.addFilter(new GZIPContentEncodingFilter(false));
    }

    // set the parameters as either query parameters or as request body
    final WebResource.Builder builder;
    if (HttpMethod.DELETE.equalsIgnoreCase(method) || HttpMethod.HEAD.equalsIgnoreCase(method) || HttpMethod.GET.equalsIgnoreCase(method) || HttpMethod.OPTIONS.equalsIgnoreCase(method)) {
        resource = resource.queryParams(map);
        builder = resource.getRequestBuilder();
    } else {
        if (entity == null) {
            builder = resource.entity(map);
        } else {
            builder = resource.entity(entity);
        }
    }

    // set headers
    boolean foundContentType = false;
    for (final Map.Entry<String, String> entry : headers.entrySet()) {
        builder.header(entry.getKey(), entry.getValue());
        if (entry.getKey().equalsIgnoreCase("content-type")) {
            foundContentType = true;
        }
    }

    // set default content type
    if (!foundContentType) {
        // set default content type
        builder.type(MediaType.APPLICATION_FORM_URLENCODED);
    }

    return builder;
}