Package io.dropwizard.client
Class JerseyClientBuilder
- java.lang.Object
-
- io.dropwizard.client.JerseyClientBuilder
-
public class JerseyClientBuilder extends Object
A convenience class for buildingClientinstances.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:
HttpClientBuilder
-
-
Constructor Summary
Constructors Constructor Description JerseyClientBuilder(com.codahale.metrics.MetricRegistry metricRegistry)JerseyClientBuilder(Environment environment)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description jakarta.ws.rs.client.Clientbuild(String name)Builds theClientinstance.<RX extends jakarta.ws.rs.client.RxInvokerProvider<?>>
jakarta.ws.rs.client.ClientbuildRx(String name, Class<RX> invokerType)Builds 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.JerseyClientBuildername(String environmentName)Use the given environment name.voidsetApacheHttpClientBuilder(HttpClientBuilder apacheHttpClientBuilder)JerseyClientBuilderusing(com.codahale.metrics.httpclient5.HttpClientMetricNameStrategy metricNameStrategy)Use the givenHttpClientMetricNameStrategyinstance.JerseyClientBuilderusing(com.fasterxml.jackson.databind.ObjectMapper objectMapper)Uses the givenObjectMapper.JerseyClientBuilderusing(JerseyClientConfiguration configuration)Uses the givenJerseyClientConfiguration.JerseyClientBuilderusing(Environment environment)Uses the givenEnvironment.JerseyClientBuilderusing(jakarta.validation.Validator validator)Use the givenValidatorinstance.JerseyClientBuilderusing(ExecutorService executorService)Uses the givenExecutorService.JerseyClientBuilderusing(ExecutorService executorService, com.fasterxml.jackson.databind.ObjectMapper objectMapper)Uses the givenExecutorServiceandObjectMapper.JerseyClientBuilderusing(HostnameVerifier verifier)Use the givenHostnameVerifierinstance.JerseyClientBuilderusing(org.apache.hc.client5.http.auth.CredentialsStore credentialsStore)Use the givenCredentialsStoreinstance.JerseyClientBuilderusing(org.apache.hc.client5.http.DnsResolver resolver)Use the givenDnsResolverinstance.JerseyClientBuilderusing(org.apache.hc.client5.http.HttpRequestRetryStrategy httpRequestRetryStrategy)Uses theHttpRequestRetryStrategyfor handling request retries.JerseyClientBuilderusing(org.apache.hc.client5.http.routing.HttpRoutePlanner routePlanner)Use the givenHttpRoutePlannerinstance.JerseyClientBuilderusing(org.apache.hc.core5.http.config.Registry<org.apache.hc.client5.http.socket.ConnectionSocketFactory> registry)Use the givenRegistryinstance of connection socket factories.JerseyClientBuilderusing(org.glassfish.jersey.client.spi.ConnectorProvider connectorProvider)Use the givenConnectorProviderinstance.JerseyClientBuilderwithProperty(String propertyName, Object propertyValue)Sets the state of the given Jersey property.JerseyClientBuilderwithProvider(Class<?> klass)Adds the given class as a Jersey provider.JerseyClientBuilderwithProvider(Object provider)Adds the given object as a Jersey provider.
-
-
-
Constructor Detail
-
JerseyClientBuilder
public JerseyClientBuilder(Environment environment)
-
JerseyClientBuilder
public JerseyClientBuilder(com.codahale.metrics.MetricRegistry metricRegistry)
-
-
Method Detail
-
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. UseJerseyClientConfigurationinstead.- Parameters:
propertyName- the name of the Jersey propertypropertyValue- the state of the Jersey property- Returns:
this
-
using
public JerseyClientBuilder using(JerseyClientConfiguration configuration)
Uses the givenJerseyClientConfiguration.- Parameters:
configuration- a configuration object- Returns:
this
-
using
public JerseyClientBuilder using(Environment environment)
Uses the givenEnvironment.- Parameters:
environment- a DropwizardEnvironment- Returns:
this- See Also:
using(java.util.concurrent.ExecutorService, com.fasterxml.jackson.databind.ObjectMapper)
-
using
public JerseyClientBuilder using(jakarta.validation.Validator validator)
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(Environment)
-
using
public JerseyClientBuilder using(ExecutorService executorService)
Uses the givenExecutorService.- Parameters:
executorService- a thread pool- Returns:
this- See Also:
using(Environment)
-
using
public JerseyClientBuilder using(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Uses the givenObjectMapper.- Parameters:
objectMapper- an object mapper- Returns:
this- See Also:
using(Environment)
-
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
public JerseyClientBuilder using(org.apache.hc.client5.http.DnsResolver resolver)
Use the givenDnsResolverinstance.- Parameters:
resolver- aDnsResolverinstance- Returns:
this
-
using
public JerseyClientBuilder using(HostnameVerifier verifier)
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
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 givenHttpRoutePlannerinstance.- Parameters:
routePlanner- aHttpRoutePlannerinstance- Returns:
this
-
using
public JerseyClientBuilder using(org.apache.hc.client5.http.auth.CredentialsStore credentialsStore)
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
public jakarta.ws.rs.client.Client build(String name)
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.
-
-