Package io.dropwizard.client
Class JerseyClientBuilder
java.lang.Object
io.dropwizard.client.JerseyClientBuilder
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 Summary
ConstructorsConstructorDescriptionJerseyClientBuilder(com.codahale.metrics.MetricRegistry metricRegistry) JerseyClientBuilder(io.dropwizard.core.setup.Environment environment) -
Method Summary
Modifier and TypeMethodDescriptionjakarta.ws.rs.client.ClientBuilds theClientinstance.<RX extends jakarta.ws.rs.client.RxInvokerProvider<?>>
jakarta.ws.rs.client.ClientBuilds theClientinstance with a custom reactive client provider.protected DropwizardApacheConnectorcreateDropwizardApacheConnector(ConfiguredCloseableHttpClient configuredClient) BuildsDropwizardApacheConnectorbased on the configured Apache HTTP client asConfiguredCloseableHttpClientand the chunked encoding configuration set by the user.Use the given environment name.voidsetApacheHttpClientBuilder(HttpClientBuilder apacheHttpClientBuilder) using(com.codahale.metrics.httpclient5.HttpClientMetricNameStrategy metricNameStrategy) Use the givenHttpClientMetricNameStrategyinstance.using(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Uses the givenObjectMapper.using(JerseyClientConfiguration configuration) Uses the givenJerseyClientConfiguration.using(io.dropwizard.core.setup.Environment environment) Uses the givenEnvironment.using(jakarta.validation.Validator validator) Use the givenValidatorinstance.using(ExecutorService executorService) Uses the givenExecutorService.using(ExecutorService executorService, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Uses the givenExecutorServiceandObjectMapper.using(HostnameVerifier verifier) Use the givenHostnameVerifierinstance.using(org.apache.hc.client5.http.auth.CredentialsStore credentialsStore) Use the givenCredentialsStoreinstance.using(org.apache.hc.client5.http.DnsResolver resolver) Use the givenDnsResolverinstance.using(org.apache.hc.client5.http.HttpRequestRetryStrategy httpRequestRetryStrategy) Uses theHttpRequestRetryStrategyfor handling request retries.using(org.apache.hc.client5.http.routing.HttpRoutePlanner routePlanner) Use the givenHttpRoutePlannerinstance.using(org.apache.hc.core5.http.config.Registry<org.apache.hc.client5.http.socket.ConnectionSocketFactory> registry) Use the givenRegistryinstance of connection socket factories.using(org.glassfish.jersey.client.spi.ConnectorProvider connectorProvider) Use the givenConnectorProviderinstance.withProperty(String propertyName, Object propertyValue) Sets the state of the given Jersey property.withProvider(Class<?> klass) Adds the given class as a Jersey provider.withProvider(Object provider) Adds the given object as a Jersey provider.
-
Constructor Details
-
JerseyClientBuilder
public JerseyClientBuilder(io.dropwizard.core.setup.Environment environment) -
JerseyClientBuilder
public JerseyClientBuilder(com.codahale.metrics.MetricRegistry metricRegistry)
-
-
Method Details
-
setApacheHttpClientBuilder
-
withProvider
Adds the given object as a Jersey provider.- Parameters:
provider- a Jersey provider- Returns:
this
-
withProvider
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
Sets the state of the given Jersey property. WARNING: The default connector ignores Jersey properties. UseJerseyClientConfigurationinstead.- Parameters:
propertyName- the name of the Jersey propertypropertyValue- the state of the Jersey property- Returns:
this
-
using
Uses the givenJerseyClientConfiguration.- Parameters:
configuration- a configuration object- Returns:
this
-
using
Uses the givenEnvironment.- Parameters:
environment- a DropwizardEnvironment- Returns:
this- See Also:
-
using
Use the givenValidatorinstance.- Parameters:
validator- aValidatorinstance- Returns:
this
-
using
public JerseyClientBuilder using(ExecutorService executorService, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Uses the givenExecutorServiceandObjectMapper.- Parameters:
executorService- a thread poolobjectMapper- an object mapper- Returns:
this- See Also:
-
using
Uses the givenExecutorService.- Parameters:
executorService- a thread pool- Returns:
this- See Also:
-
using
Uses the givenObjectMapper.- Parameters:
objectMapper- an object mapper- Returns:
this- See Also:
-
using
public JerseyClientBuilder using(org.glassfish.jersey.client.spi.ConnectorProvider connectorProvider) Use the givenConnectorProviderinstance. WARNING: Use it with caution. Most features will not work in a custom connection provider.- Parameters:
connectorProvider- aConnectorProviderinstance- Returns:
this
-
using
public JerseyClientBuilder using(org.apache.hc.client5.http.HttpRequestRetryStrategy httpRequestRetryStrategy) Uses theHttpRequestRetryStrategyfor handling request retries.- Parameters:
httpRequestRetryStrategy- aHttpRequestRetryStrategy- Returns:
this
-
using
Use the givenDnsResolverinstance.- Parameters:
resolver- aDnsResolverinstance- Returns:
this
-
using
Use the givenHostnameVerifierinstance. Note that ifTlsConfiguration.isVerifyHostname()returns false, all host name verification is bypassed, including host name verification performed by a verifier specified through this interface.- Parameters:
verifier- aHostnameVerifierinstance- Returns:
this
-
using
public JerseyClientBuilder using(org.apache.hc.core5.http.config.Registry<org.apache.hc.client5.http.socket.ConnectionSocketFactory> registry) Use the givenRegistryinstance of connection socket factories.- Parameters:
registry- aRegistryinstance of connection socket factories- Returns:
this
-
using
public JerseyClientBuilder using(com.codahale.metrics.httpclient5.HttpClientMetricNameStrategy metricNameStrategy) Use the givenHttpClientMetricNameStrategyinstance.- Parameters:
metricNameStrategy- aHttpClientMetricNameStrategyinstance- Returns:
this
-
name
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
Use the givenHttpRoutePlannerinstance.- Parameters:
routePlanner- aHttpRoutePlannerinstance- Returns:
this
-
using
Use the givenCredentialsStoreinstance.- Parameters:
credentialsStore- aCredentialsStoreinstance- Returns:
this
-
buildRx
public <RX extends jakarta.ws.rs.client.RxInvokerProvider<?>> jakarta.ws.rs.client.Client buildRx(String name, Class<RX> invokerType) Builds theClientinstance with a custom reactive client provider.- Returns:
- a fully-configured
Client
-
build
Builds theClientinstance.- Returns:
- a fully-configured
Client
-
createDropwizardApacheConnector
protected DropwizardApacheConnector createDropwizardApacheConnector(ConfiguredCloseableHttpClient configuredClient) BuildsDropwizardApacheConnectorbased on the configured Apache HTTP client asConfiguredCloseableHttpClientand the chunked encoding configuration set by the user.
-