public final class WebClientBuilder extends Object
URI using the builder pattern.
Use the factory methods in WebClient if you do not have many options to override.
Please refer to ClientBuilder for how decorators and HTTP headers are configured| Modifier and Type | Method and Description |
|---|---|
WebClientBuilder |
addHttpHeader(CharSequence name,
Object value)
Adds the specified HTTP header.
|
WebClientBuilder |
addHttpHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> httpHeaders)
Adds the specified HTTP headers.
|
WebClient |
build()
Returns a newly-created web client based on the properties of this builder.
|
WebClientBuilder |
decorator(DecoratingHttpClientFunction decorator)
Adds the specified HTTP-level
decorator. |
WebClientBuilder |
decorator(Function<? super HttpClient,? extends HttpClient> decorator)
Adds the specified HTTP-level
decorator. |
WebClientBuilder |
defaultMaxResponseLength(long maxResponseLength)
Deprecated.
|
WebClientBuilder |
defaultResponseTimeout(Duration responseTimeout)
Deprecated.
|
WebClientBuilder |
defaultResponseTimeoutMillis(long responseTimeoutMillis)
Deprecated.
|
WebClientBuilder |
defaultWriteTimeout(Duration writeTimeout)
Deprecated.
|
WebClientBuilder |
defaultWriteTimeoutMillis(long writeTimeoutMillis)
Deprecated.
|
WebClientBuilder |
endpointRemapper(Function<? super Endpoint,? extends EndpointGroup> endpointRemapper)
|
WebClientBuilder |
factory(ClientFactory factory)
Sets the
ClientFactory used for creating a client. |
WebClientBuilder |
maxResponseLength(long maxResponseLength)
Sets the maximum allowed length of a server response in bytes.
|
<T> WebClientBuilder |
option(ClientOption<T> option,
T value)
Adds the specified
ClientOption and its value. |
<T> WebClientBuilder |
option(ClientOptionValue<T> optionValue)
Adds the specified
ClientOptionValue. |
WebClientBuilder |
options(ClientOptions options)
Adds the specified
ClientOptions. |
WebClientBuilder |
options(ClientOptionValue<?>... options)
Adds the specified
ClientOptionValues. |
WebClientBuilder |
options(Iterable<ClientOptionValue<?>> options)
Adds the specified
ClientOptionValues. |
WebClientBuilder |
path(String path)
Sets the
path of the client. |
WebClientBuilder |
requestIdGenerator(Supplier<RequestId> requestIdGenerator)
|
WebClientBuilder |
responseTimeout(Duration responseTimeout)
Sets the timeout of a response.
|
WebClientBuilder |
responseTimeoutMillis(long responseTimeoutMillis)
Sets the timeout of a response in milliseconds.
|
WebClientBuilder |
rpcDecorator(DecoratingRpcClientFunction decorator)
Adds the specified RPC-level
decorator. |
WebClientBuilder |
rpcDecorator(Function<? super RpcClient,? extends RpcClient> decorator)
Adds the specified RPC-level
decorator. |
WebClientBuilder |
setHttpHeader(CharSequence name,
Object value)
Sets the specified HTTP header.
|
WebClientBuilder |
setHttpHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> httpHeaders)
Sets the specified HTTP headers.
|
WebClientBuilder |
writeTimeout(Duration writeTimeout)
Sets the timeout of a socket write attempt.
|
WebClientBuilder |
writeTimeoutMillis(long writeTimeoutMillis)
Sets the timeout of a socket write attempt in milliseconds.
|
public WebClientBuilder path(String path)
path of the client.public WebClient build()
IllegalArgumentException - if the scheme of the uri specified in
WebClient.builder(String) or
WebClient.builder(URI) is not an HTTP schemepublic WebClientBuilder rpcDecorator(Function<? super RpcClient,? extends RpcClient> decorator)
decorator.public WebClientBuilder rpcDecorator(DecoratingRpcClientFunction decorator)
decorator.decorator - the DecoratingRpcClientFunction that intercepts an invocationpublic WebClientBuilder options(ClientOptions options)
ClientOptions.public WebClientBuilder options(ClientOptionValue<?>... options)
ClientOptionValues.public WebClientBuilder options(Iterable<ClientOptionValue<?>> options)
ClientOptionValues.public <T> WebClientBuilder option(ClientOption<T> option, T value)
ClientOption and its value.public <T> WebClientBuilder option(ClientOptionValue<T> optionValue)
ClientOptionValue.public WebClientBuilder factory(ClientFactory factory)
ClientFactory used for creating a client.
The default is ClientFactory.ofDefault().@Deprecated public WebClientBuilder defaultWriteTimeout(Duration writeTimeout)
writeTimeout - the timeout. 0 disables the timeout.@Deprecated public WebClientBuilder defaultWriteTimeoutMillis(long writeTimeoutMillis)
writeTimeoutMillis - the timeout in milliseconds. 0 disables the timeout.public WebClientBuilder writeTimeout(Duration writeTimeout)
writeTimeout - the timeout. 0 disables the timeout.public WebClientBuilder writeTimeoutMillis(long writeTimeoutMillis)
writeTimeoutMillis - the timeout in milliseconds. 0 disables the timeout.@Deprecated public WebClientBuilder defaultResponseTimeout(Duration responseTimeout)
responseTimeout - the timeout. 0 disables the timeout.@Deprecated public WebClientBuilder defaultResponseTimeoutMillis(long responseTimeoutMillis)
responseTimeoutMillis - the timeout in milliseconds. 0 disables the timeout.public WebClientBuilder responseTimeout(Duration responseTimeout)
responseTimeout - the timeout. 0 disables the timeout.public WebClientBuilder responseTimeoutMillis(long responseTimeoutMillis)
responseTimeoutMillis - the timeout in milliseconds. 0 disables the timeout.@Deprecated public WebClientBuilder defaultMaxResponseLength(long maxResponseLength)
maxResponseLength - the maximum length in bytes. 0 disables the limit.public WebClientBuilder maxResponseLength(long maxResponseLength)
maxResponseLength - the maximum length in bytes. 0 disables the limit.public WebClientBuilder requestIdGenerator(Supplier<RequestId> requestIdGenerator)
public WebClientBuilder endpointRemapper(Function<? super Endpoint,? extends EndpointGroup> endpointRemapper)
Function that remaps an Endpoint into an EndpointGroup.
This ClientOption is useful when you need to override a single target host into
a group of hosts to enable client-side load-balancing, e.g.
MyService.Iface client =
Clients.newClient("tbinary+http://example.com/api",
MyService.Iface.class);
EndpointGroup myGroup = EndpointGroup.of(Endpoint.of("node-1.example.com")),
Endpoint.of("node-2.example.com")));
MyService.Iface derivedClient =
Clients.newDerivedClient(client, options -> {
return options.toBuilder()
.endpointRemapper(endpoint -> {
if (endpoint.host().equals("example.com")) {
return myGroup;
} else {
return endpoint;
}
})
.build();
});
// This request goes to 'node-1.example.com' or 'node-2.example.com'.
derivedClient.call();
Note that the remapping does not occur recursively but only once.
public WebClientBuilder decorator(Function<? super HttpClient,? extends HttpClient> decorator)
decorator.decorator - the Function that transforms an HttpClient to anotherpublic WebClientBuilder decorator(DecoratingHttpClientFunction decorator)
decorator.decorator - the DecoratingHttpClientFunction that intercepts an invocationpublic WebClientBuilder addHttpHeader(CharSequence name, Object value)
public WebClientBuilder addHttpHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> httpHeaders)
public WebClientBuilder setHttpHeader(CharSequence name, Object value)
public WebClientBuilder setHttpHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> httpHeaders)
Copyright © 2020 LeanCloud. All rights reserved.