Class HttpClients
HttpClient (and other API variations) instances.-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionCreates aMultiAddressHttpClientBuilderfor clients capable of parsing an absolute-form URL, connecting to multiple addresses with defaultLoadBalancerand DNSServiceDiscovererusingbackgrounddiscovery strategy.forMultiAddressUrl(ServiceDiscoverer<HostAndPort, InetSocketAddress, ServiceDiscovererEvent<InetSocketAddress>> serviceDiscoverer) Deprecated.Creates aMultiAddressHttpClientBuilderfor clients capable of parsing an absolute-form URL, connecting to multiple addresses with defaultLoadBalancerand DNSServiceDiscovererusingbackgrounddiscovery strategy.forMultiAddressUrl(String id, ServiceDiscoverer<HostAndPort, InetSocketAddress, ServiceDiscovererEvent<InetSocketAddress>> serviceDiscoverer, HttpClients.DiscoveryStrategy discoveryStrategy) Creates aMultiAddressHttpClientBuilderfor clients capable of parsing an absolute-form URL, connecting to multiple addresses with defaultLoadBalancer, using the specifiedServiceDiscovererandHttpClients.DiscoveryStrategy.forMultiAddressUrl(String id, HttpClients.DiscoveryStrategy discoveryStrategy) Creates aMultiAddressHttpClientBuilderfor clients capable of parsing an absolute-form URL, connecting to multiple addresses with defaultLoadBalancerand DNSServiceDiscovererusing the specifiedHttpClients.DiscoveryStrategy.static <U,R> PartitionedHttpClientBuilder<U, R> forPartitionedAddress(ServiceDiscoverer<U, R, PartitionedServiceDiscovererEvent<R>> serviceDiscoverer, U address, Function<HttpRequestMetaData, PartitionAttributesBuilder> partitionAttributesBuilderFactory) Deprecated.We are unaware of anyone using "partition" feature and plan to remove it in future releases.forResolvedAddress(HostAndPort address) Creates aSingleAddressHttpClientBuilderfor an address with defaultLoadBalancer.forResolvedAddress(String host, int port) Creates aSingleAddressHttpClientBuilderfor a resolved address with defaultLoadBalancer.static <R extends SocketAddress>
SingleAddressHttpClientBuilder<R,R> forResolvedAddress(R address) Creates aSingleAddressHttpClientBuilderfor an address with defaultLoadBalancer.forServiceAddress(String serviceName) Creates aSingleAddressHttpClientBuilderfor the passedserviceNamewith defaultLoadBalancerand a DNSServiceDiscovererusing SRV record lookups withbackgrounddiscovery strategy.static <U,R> SingleAddressHttpClientBuilder<U, R> forSingleAddress(ServiceDiscoverer<U, R, ? extends ServiceDiscovererEvent<R>> serviceDiscoverer, U address) Creates aSingleAddressHttpClientBuilderfor a custom address type with defaultLoadBalancerand user providedServiceDiscovererusingbackgrounddiscovery strategy.static <U,R> SingleAddressHttpClientBuilder<U, R> forSingleAddress(ServiceDiscoverer<U, R, ? extends ServiceDiscovererEvent<R>> serviceDiscoverer, U address, HttpClients.DiscoveryStrategy discoveryStrategy) Creates aSingleAddressHttpClientBuilderfor a custom address type with defaultLoadBalancerand user providedServiceDiscovererusing the specifiedHttpClients.DiscoveryStrategy.forSingleAddress(HostAndPort address) Creates aSingleAddressHttpClientBuilderfor an address with defaultLoadBalancerand DNSServiceDiscovererusingbackgrounddiscovery strategy.forSingleAddress(HostAndPort address, HttpClients.DiscoveryStrategy discoveryStrategy) Creates aSingleAddressHttpClientBuilderfor an address with defaultLoadBalancerand DNSServiceDiscovererusing the specifiedHttpClients.DiscoveryStrategy.forSingleAddress(String host, int port) Creates aSingleAddressHttpClientBuilderfor an address with defaultLoadBalancerand DNSServiceDiscovererusingbackgrounddiscovery strategy.forSingleAddress(String host, int port, HttpClients.DiscoveryStrategy discoveryStrategy) Creates aSingleAddressHttpClientBuilderfor an address with defaultLoadBalancerand DNSServiceDiscovererusing the specifiedHttpClients.DiscoveryStrategy.
-
Method Details
-
forMultiAddressUrl
Creates aMultiAddressHttpClientBuilderfor clients capable of parsing an absolute-form URL, connecting to multiple addresses with defaultLoadBalancerand DNSServiceDiscovererusingbackgrounddiscovery strategy.When a relative URL is passed in the
StreamingHttpRequest.requestTarget(String)this client requires aHttpHeaderNames.HOSTpresent in order to infer the remote address.The returned builder can be customized using
HttpProviders.MultiAddressHttpClientBuilderProvider.- Returns:
- new builder with default configuration
- See Also:
-
forMultiAddressUrl
public static MultiAddressHttpClientBuilder<HostAndPort,InetSocketAddress> forMultiAddressUrl(String id) Creates aMultiAddressHttpClientBuilderfor clients capable of parsing an absolute-form URL, connecting to multiple addresses with defaultLoadBalancerand DNSServiceDiscovererusingbackgrounddiscovery strategy.When a relative URL is passed in the
StreamingHttpRequest.requestTarget(String)this client requires aHttpHeaderNames.HOSTpresent in order to infer the remote address.The returned builder can be customized using
HttpProviders.MultiAddressHttpClientBuilderProvider.- Parameters:
id- a (unique) ID to identify the createdMultiAddressHttpClientBuilder, like a name or a purpose of the future client that will be built. This helpsHttpProviders.MultiAddressHttpClientBuilderProviderto distinguish this builder from others.- Returns:
- new builder with default configuration
- See Also:
-
forMultiAddressUrl
public static MultiAddressHttpClientBuilder<HostAndPort,InetSocketAddress> forMultiAddressUrl(String id, HttpClients.DiscoveryStrategy discoveryStrategy) Creates aMultiAddressHttpClientBuilderfor clients capable of parsing an absolute-form URL, connecting to multiple addresses with defaultLoadBalancerand DNSServiceDiscovererusing the specifiedHttpClients.DiscoveryStrategy.When a relative URL is passed in the
StreamingHttpRequest.requestTarget(String)this client requires aHttpHeaderNames.HOSTpresent in order to infer the remote address.The returned builder can be customized using
HttpProviders.MultiAddressHttpClientBuilderProvider.- Parameters:
id- a (unique) ID to identify the createdMultiAddressHttpClientBuilder, like a name or a purpose of the future client that will be built. This helpsHttpProviders.MultiAddressHttpClientBuilderProviderto distinguish this builder from others.discoveryStrategy-HttpClients.DiscoveryStrategyto use- Returns:
- new builder with default configuration
- See Also:
-
forMultiAddressUrl
public static MultiAddressHttpClientBuilder<HostAndPort,InetSocketAddress> forMultiAddressUrl(String id, ServiceDiscoverer<HostAndPort, InetSocketAddress, ServiceDiscovererEvent<InetSocketAddress>> serviceDiscoverer, HttpClients.DiscoveryStrategy discoveryStrategy) Creates aMultiAddressHttpClientBuilderfor clients capable of parsing an absolute-form URL, connecting to multiple addresses with defaultLoadBalancer, using the specifiedServiceDiscovererandHttpClients.DiscoveryStrategy.When a relative URL is passed in the
StreamingHttpRequest.requestTarget(String)this client requires aHttpHeaderNames.HOSTpresent in order to infer the remote address.The returned builder can be customized using
HttpProviders.MultiAddressHttpClientBuilderProvider.- Parameters:
id- a (unique) ID to identify the createdMultiAddressHttpClientBuilder, like a name or a purpose of the future client that will be built. This helpsHttpProviders.MultiAddressHttpClientBuilderProviderto distinguish this builder from others.serviceDiscoverer- TheServiceDiscovererto resolve addresses of remote servers to connect to. The lifecycle of the providedServiceDiscoverershould be managed by the caller.discoveryStrategy-HttpClients.DiscoveryStrategyto use.- Returns:
- new builder with default configuration.
- See Also:
-
forMultiAddressUrl
@Deprecated public static MultiAddressHttpClientBuilder<HostAndPort,InetSocketAddress> forMultiAddressUrl(ServiceDiscoverer<HostAndPort, InetSocketAddress, ServiceDiscovererEvent<InetSocketAddress>> serviceDiscoverer) Deprecated.UseforMultiAddressUrl()to createMultiAddressHttpClientBuilder, then useMultiAddressHttpClientBuilder.initializer(SingleAddressInitializer)to overrideServiceDiscovererusingSingleAddressHttpClientBuilder.serviceDiscoverer(ServiceDiscoverer)for all or some of the internal clients.Creates aMultiAddressHttpClientBuilderfor clients capable of parsing an absolute-form URL, connecting to multiple addresses with defaultLoadBalancerand user providedServiceDiscoverer.When a relative URL is passed in the
StreamingHttpRequest.requestTarget(String)this client requires aHttpHeaderNames.HOSTpresent in order to infer the remote address.The returned builder can be customized using
HttpProviders.MultiAddressHttpClientBuilderProvider.- Parameters:
serviceDiscoverer- TheServiceDiscovererto resolve addresses of remote servers to connect to. The lifecycle of the providedServiceDiscoverershould be managed by the caller.- Returns:
- new builder with default configuration
- See Also:
-
forSingleAddress
public static SingleAddressHttpClientBuilder<HostAndPort,InetSocketAddress> forSingleAddress(String host, int port) Creates aSingleAddressHttpClientBuilderfor an address with defaultLoadBalancerand DNSServiceDiscovererusingbackgrounddiscovery strategy.The returned builder can be customized using
HttpProviders.SingleAddressHttpClientBuilderProvider.- Parameters:
host- host to connect to, resolved by default using a DNSServiceDiscoverer. This will also be used for theHttpHeaderNames.HOSTtogether with theport. UseSingleAddressHttpClientBuilder.unresolvedAddressToHost(Function)if you want to override that value orSingleAddressHttpClientBuilder.hostHeaderFallback(boolean)if you want to disable this behavior.port- port to connect to- Returns:
- new builder for the address
- See Also:
-
forSingleAddress
public static SingleAddressHttpClientBuilder<HostAndPort,InetSocketAddress> forSingleAddress(HostAndPort address) Creates aSingleAddressHttpClientBuilderfor an address with defaultLoadBalancerand DNSServiceDiscovererusingbackgrounddiscovery strategy.The returned builder can be customized using
HttpProviders.SingleAddressHttpClientBuilderProvider.- Parameters:
address- theUnresolvedAddressto connect to, resolved by default using a DNSServiceDiscoverer. This address will also be used for theHttpHeaderNames.HOST. UseSingleAddressHttpClientBuilder.unresolvedAddressToHost(Function)if you want to override that value orSingleAddressHttpClientBuilder.hostHeaderFallback(boolean)if you want to disable this behavior.- Returns:
- new builder for the address
- See Also:
-
forSingleAddress
public static SingleAddressHttpClientBuilder<HostAndPort,InetSocketAddress> forSingleAddress(String host, int port, HttpClients.DiscoveryStrategy discoveryStrategy) Creates aSingleAddressHttpClientBuilderfor an address with defaultLoadBalancerand DNSServiceDiscovererusing the specifiedHttpClients.DiscoveryStrategy.The returned builder can be customized using
HttpProviders.SingleAddressHttpClientBuilderProvider.- Parameters:
host- host to connect to, resolved by default using a DNSServiceDiscoverer. This will also be used for theHttpHeaderNames.HOSTtogether with theport. UseSingleAddressHttpClientBuilder.unresolvedAddressToHost(Function)if you want to override that value orSingleAddressHttpClientBuilder.hostHeaderFallback(boolean)if you want to disable this behavior.port- port to connect todiscoveryStrategy-HttpClients.DiscoveryStrategyto use- Returns:
- new builder for the address
- See Also:
-
forSingleAddress
public static SingleAddressHttpClientBuilder<HostAndPort,InetSocketAddress> forSingleAddress(HostAndPort address, HttpClients.DiscoveryStrategy discoveryStrategy) Creates aSingleAddressHttpClientBuilderfor an address with defaultLoadBalancerand DNSServiceDiscovererusing the specifiedHttpClients.DiscoveryStrategy.The returned builder can be customized using
HttpProviders.SingleAddressHttpClientBuilderProvider.- Parameters:
address- theUnresolvedAddressto connect to, resolved by default using a DNSServiceDiscoverer. This address will also be used for theHttpHeaderNames.HOST. UseSingleAddressHttpClientBuilder.unresolvedAddressToHost(Function)if you want to override that value orSingleAddressHttpClientBuilder.hostHeaderFallback(boolean)if you want to disable this behavior.discoveryStrategy-HttpClients.DiscoveryStrategyto use- Returns:
- new builder for the address
- See Also:
-
forServiceAddress
public static SingleAddressHttpClientBuilder<String,InetSocketAddress> forServiceAddress(String serviceName) Creates aSingleAddressHttpClientBuilderfor the passedserviceNamewith defaultLoadBalancerand a DNSServiceDiscovererusing SRV record lookups withbackgrounddiscovery strategy.The returned builder can be customized using
HttpProviders.SingleAddressHttpClientBuilderProvider.- Parameters:
serviceName- The service name to resolve with SRV DNS.- Returns:
- new builder for the address
- See Also:
-
forResolvedAddress
public static SingleAddressHttpClientBuilder<HostAndPort,InetSocketAddress> forResolvedAddress(String host, int port) Creates aSingleAddressHttpClientBuilderfor a resolved address with defaultLoadBalancer.- Parameters:
host- resolved host address to connect. This will also be used for theHttpHeaderNames.HOSTtogether with theport. UseSingleAddressHttpClientBuilder.unresolvedAddressToHost(Function)if you want to override that value orSingleAddressHttpClientBuilder.hostHeaderFallback(boolean)if you want to disable this behavior.Note, if
a proxyis configured for this client, the proxy address also needs to be already resolved. Otherwise, runtime exceptions will be thrown when the client is built.The returned builder can be customized using
HttpProviders.SingleAddressHttpClientBuilderProvider.port- port to connect to- Returns:
- new builder for the address
- See Also:
-
forResolvedAddress
public static SingleAddressHttpClientBuilder<HostAndPort,InetSocketAddress> forResolvedAddress(HostAndPort address) Creates aSingleAddressHttpClientBuilderfor an address with defaultLoadBalancer.- Parameters:
address- theResolvedAddressto connect. This address will also be used for theHttpHeaderNames.HOST. UseSingleAddressHttpClientBuilder.unresolvedAddressToHost(Function)if you want to override that value orSingleAddressHttpClientBuilder.hostHeaderFallback(boolean)if you want to disable this behavior.Note, if
a proxyis configured for this client, the proxy address also needs to be already resolved. Otherwise, runtime exceptions will be thrown when the client is built.The returned builder can be customized using
HttpProviders.SingleAddressHttpClientBuilderProvider.- Returns:
- new builder for the address
- See Also:
-
forResolvedAddress
public static <R extends SocketAddress> SingleAddressHttpClientBuilder<R,R> forResolvedAddress(R address) Creates aSingleAddressHttpClientBuilderfor an address with defaultLoadBalancer.The returned builder can be customized using
HttpProviders.SingleAddressHttpClientBuilderProvider.- Type Parameters:
R- The type of resolvedSocketAddress.- Parameters:
address- theResolvedAddressto connect. This address will also be used for theHttpHeaderNames.HOST. UseSingleAddressHttpClientBuilder.unresolvedAddressToHost(Function)if you want to override that value orSingleAddressHttpClientBuilder.hostHeaderFallback(boolean)if you want to disable this behavior.- Returns:
- new builder for the address
- See Also:
-
forSingleAddress
public static <U,R> SingleAddressHttpClientBuilder<U,R> forSingleAddress(ServiceDiscoverer<U, R, ? extends ServiceDiscovererEvent<R>> serviceDiscoverer, U address) Creates aSingleAddressHttpClientBuilderfor a custom address type with defaultLoadBalancerand user providedServiceDiscovererusingbackgrounddiscovery strategy.The returned builder can be customized using
HttpProviders.SingleAddressHttpClientBuilderProvider.- Type Parameters:
U- the type of address before resolution (unresolved address)R- the type of address after resolution (resolved address)- Parameters:
serviceDiscoverer- TheServiceDiscovererto resolve addresses of remote servers to connect to. The lifecycle of the providedServiceDiscoverershould be managed by the caller.address- theUnresolvedAddressto connect to resolved using the providedserviceDiscoverer. This address will also be used for theHttpHeaderNames.HOSTusing a best effort conversion. UseSingleAddressHttpClientBuilder.unresolvedAddressToHost(Function)if you want to override that value orSingleAddressHttpClientBuilder.hostHeaderFallback(boolean)if you want to disable this behavior.- Returns:
- new builder with provided configuration
- See Also:
-
forSingleAddress
public static <U,R> SingleAddressHttpClientBuilder<U,R> forSingleAddress(ServiceDiscoverer<U, R, ? extends ServiceDiscovererEvent<R>> serviceDiscoverer, U address, HttpClients.DiscoveryStrategy discoveryStrategy) Creates aSingleAddressHttpClientBuilderfor a custom address type with defaultLoadBalancerand user providedServiceDiscovererusing the specifiedHttpClients.DiscoveryStrategy.The returned builder can be customized using
HttpProviders.SingleAddressHttpClientBuilderProvider.- Type Parameters:
U- the type of address before resolution (unresolved address)R- the type of address after resolution (resolved address)- Parameters:
serviceDiscoverer- TheServiceDiscovererto resolve addresses of remote servers to connect to. The lifecycle of the providedServiceDiscoverershould be managed by the caller.address- theUnresolvedAddressto connect to resolved using the providedserviceDiscoverer. This address will also be used for theHttpHeaderNames.HOSTusing a best effort conversion. UseSingleAddressHttpClientBuilder.unresolvedAddressToHost(Function)if you want to override that value orSingleAddressHttpClientBuilder.hostHeaderFallback(boolean)if you want to disable this behavior.discoveryStrategy-HttpClients.DiscoveryStrategyto use- Returns:
- new builder with provided configuration
- See Also:
-
forPartitionedAddress
@Deprecated public static <U,R> PartitionedHttpClientBuilder<U,R> forPartitionedAddress(ServiceDiscoverer<U, R, PartitionedServiceDiscovererEvent<R>> serviceDiscoverer, U address, Function<HttpRequestMetaData, PartitionAttributesBuilder> partitionAttributesBuilderFactory) Deprecated.We are unaware of anyone using "partition" feature and plan to remove it in future releases. If you depend on it, consider usingClientGroupas an alternative or reach out to the maintainers describing the use-case.Creates aPartitionedHttpClientBuilderfor a custom address type with defaultLoadBalancerand user providedServiceDiscoverer.- Type Parameters:
U- the type of address before resolution (unresolved address)R- the type of address after resolution (resolved address)- Parameters:
serviceDiscoverer- TheServiceDiscovererto resolve addresses of remote servers to connect to. The lifecycle of the providedServiceDiscoverershould be managed by the caller.address- theUnresolvedAddressto resolve using the providedserviceDiscoverer. This address will also be used for theHttpHeaderNames.HOSTusing a best effort conversion. UsePartitionedHttpClientBuilder.initializer(PartitionedHttpClientBuilder.SingleAddressInitializer)andSingleAddressHttpClientBuilder.unresolvedAddressToHost(Function)if you want to override that value orSingleAddressHttpClientBuilder.hostHeaderFallback(boolean)if you want to disable this behavior.partitionAttributesBuilderFactory- The factoryFunctionused to buildPartitionAttributesfromHttpRequestMetaData.- Returns:
- new builder with provided configuration
-
forMultiAddressUrl()to createMultiAddressHttpClientBuilder, then useMultiAddressHttpClientBuilder.initializer(SingleAddressInitializer)to overrideServiceDiscovererusingSingleAddressHttpClientBuilder.serviceDiscoverer(ServiceDiscoverer)for all or some of the internal clients.