Class JerseyClientBuilder

java.lang.Object
io.dropwizard.client.JerseyClientBuilder

public class JerseyClientBuilder extends Object
A convenience class for building Client instances.

Among other things,

  • Backed by Apache HttpClient
  • Disables stale connection checks
  • Disables Nagle's algorithm
  • Disables cookie management by default
  • Compress requests and decompress responses using GZIP
  • Supports parsing and generating JSON data using Jackson

See Also:
  • Constructor Details

    • JerseyClientBuilder

      public JerseyClientBuilder(io.dropwizard.core.setup.Environment environment)
    • JerseyClientBuilder

      public JerseyClientBuilder(com.codahale.metrics.MetricRegistry metricRegistry)
  • Method Details

    • setApacheHttpClientBuilder

      public void setApacheHttpClientBuilder(HttpClientBuilder apacheHttpClientBuilder)
    • withProvider

      public JerseyClientBuilder withProvider(Object provider)
      Adds the given object as a Jersey provider.
      Parameters:
      provider - a Jersey provider
      Returns:
      this
    • withProvider

      public JerseyClientBuilder withProvider(Class<?> klass)
      Adds the given class as a Jersey provider.

      N.B.: This class must either have a no-args constructor or use Jersey's built-in dependency injection.

      Parameters:
      klass - a Jersey provider class
      Returns:
      this
    • withProperty

      public JerseyClientBuilder withProperty(String propertyName, Object propertyValue)
      Sets the state of the given Jersey property.

      WARNING: The default connector ignores Jersey properties. Use JerseyClientConfiguration instead.

      Parameters:
      propertyName - the name of the Jersey property
      propertyValue - the state of the Jersey property
      Returns:
      this
    • using

      public JerseyClientBuilder using(JerseyClientConfiguration configuration)
      Parameters:
      configuration - a configuration object
      Returns:
      this
    • using

      public JerseyClientBuilder using(io.dropwizard.core.setup.Environment environment)
      Uses the given Environment.
      Parameters:
      environment - a Dropwizard Environment
      Returns:
      this
      See Also:
    • using

      public JerseyClientBuilder using(jakarta.validation.Validator validator)
      Use the given Validator instance.
      Parameters:
      validator - a Validator instance
      Returns:
      this
    • using

      public JerseyClientBuilder using(ExecutorService executorService, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Uses the given ExecutorService and ObjectMapper.
      Parameters:
      executorService - a thread pool
      objectMapper - an object mapper
      Returns:
      this
      See Also:
    • using

      public JerseyClientBuilder using(ExecutorService executorService)
      Uses the given ExecutorService.
      Parameters:
      executorService - a thread pool
      Returns:
      this
      See Also:
    • using

      public JerseyClientBuilder using(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Uses the given ObjectMapper.
      Parameters:
      objectMapper - an object mapper
      Returns:
      this
      See Also:
    • using

      public JerseyClientBuilder using(org.glassfish.jersey.client.spi.ConnectorProvider connectorProvider)
      Use the given ConnectorProvider instance.

      WARNING: Use it with caution. Most features will not work in a custom connection provider.

      Parameters:
      connectorProvider - a ConnectorProvider instance
      Returns:
      this
    • using

      public JerseyClientBuilder using(org.apache.hc.client5.http.HttpRequestRetryStrategy httpRequestRetryStrategy)
      Uses the HttpRequestRetryStrategy for handling request retries.
      Parameters:
      httpRequestRetryStrategy - a HttpRequestRetryStrategy
      Returns:
      this
    • using

      public JerseyClientBuilder using(org.apache.hc.client5.http.DnsResolver resolver)
      Use the given DnsResolver instance.
      Parameters:
      resolver - a DnsResolver instance
      Returns:
      this
    • using

      public JerseyClientBuilder using(HostnameVerifier verifier)
      Use the given HostnameVerifier instance. Note that if TlsConfiguration.isVerifyHostname() returns false, all host name verification is bypassed, including host name verification performed by a verifier specified through this interface.
      Parameters:
      verifier - a HostnameVerifier instance
      Returns:
      this
    • using

      public JerseyClientBuilder using(org.apache.hc.core5.http.config.Registry<org.apache.hc.client5.http.socket.ConnectionSocketFactory> registry)
      Use the given Registry instance of connection socket factories.
      Parameters:
      registry - a Registry instance of connection socket factories
      Returns:
      this
    • using

      public JerseyClientBuilder using(com.codahale.metrics.httpclient5.HttpClientMetricNameStrategy metricNameStrategy)
      Use the given HttpClientMetricNameStrategy instance.
      Parameters:
      metricNameStrategy - a HttpClientMetricNameStrategy instance
      Returns:
      this
    • name

      public JerseyClientBuilder name(String environmentName)
      Use the given environment name. This is used in the user agent.
      Parameters:
      environmentName - an environment name to use in the user agent.
      Returns:
      this
    • using

      public JerseyClientBuilder using(org.apache.hc.client5.http.routing.HttpRoutePlanner routePlanner)
      Use the given HttpRoutePlanner instance.
      Parameters:
      routePlanner - a HttpRoutePlanner instance
      Returns:
      this
    • using

      public JerseyClientBuilder using(org.apache.hc.client5.http.auth.CredentialsStore credentialsStore)
      Use the given CredentialsStore instance.
      Parameters:
      credentialsStore - a CredentialsStore instance
      Returns:
      this
    • buildRx

      public <RX extends jakarta.ws.rs.client.RxInvokerProvider<?>> jakarta.ws.rs.client.Client buildRx(String name, Class<RX> invokerType)
      Builds the Client instance with a custom reactive client provider.
      Returns:
      a fully-configured Client
    • build

      public jakarta.ws.rs.client.Client build(String name)
      Builds the Client instance.
      Returns:
      a fully-configured Client
    • createDropwizardApacheConnector

      protected DropwizardApacheConnector createDropwizardApacheConnector(ConfiguredCloseableHttpClient configuredClient)
      Builds DropwizardApacheConnector based on the configured Apache HTTP client as ConfiguredCloseableHttpClient and the chunked encoding configuration set by the user.