public abstract static class HttpClient.Builder extends Object
HttpClient
s. HttpClient.Builder
s
are created by calling HttpClient.newBuilder()
Each of the setter methods in this class modifies the state of the builder and returns this (ie. the same instance). The methods are not synchronized and should not be called from multiple threads without external synchronization.
build()
returns a new HttpClient
each time it is
called.
Modifier | Constructor | Description |
---|---|---|
protected |
Builder() |
Modifier and Type | Method | Description |
---|---|---|
abstract HttpClient.Builder |
authenticator(Authenticator a) |
Sets an authenticator to use for HTTP authentication.
|
abstract HttpClient |
build() |
Returns a
HttpClient built from the current state of this
builder. |
abstract HttpClient.Builder |
cookieManager(CookieManager cookieManager) |
Sets a cookie manager.
|
abstract HttpClient.Builder |
executor(Executor executor) |
Sets the executor to be used for asynchronous tasks.
|
abstract HttpClient.Builder |
followRedirects(HttpClient.Redirect policy) |
Specifies whether requests will automatically follow redirects issued
by the server.
|
abstract HttpClient.Builder |
priority(int priority) |
Sets the default priority for any HTTP/2 requests sent from this
client.
|
abstract HttpClient.Builder |
proxy(ProxySelector selector) |
Sets a
ProxySelector for this client. |
abstract HttpClient.Builder |
sslContext(SSLContext sslContext) |
Sets an
SSLContext . |
abstract HttpClient.Builder |
sslParameters(SSLParameters sslParameters) |
Sets an
SSLParameters . |
abstract HttpClient.Builder |
version(HttpClient.Version version) |
Requests a specific HTTP protocol version where possible.
|
public abstract HttpClient.Builder cookieManager(CookieManager cookieManager)
cookieManager
- the cookie managerpublic abstract HttpClient.Builder sslContext(SSLContext sslContext)
SSLContext
. If a security manager is set, then the caller
must have the NetPermission
("setSSLContext"
)
The effect of not calling this method, is that a default SSLContext
is used, which is normally adequate for
client applications that do not need to specify protocols, or require
client authentication.
sslContext
- the SSLContextSecurityException
- if a security manager is set and the
caller does not have any required permissionpublic abstract HttpClient.Builder sslParameters(SSLParameters sslParameters)
SSLParameters
. If this method is not called, then a default
set of parameters are used. The contents of the given object are
copied. Some parameters which are used internally by the HTTP protocol
implementation (such as application protocol list) should not be set
by callers, as they are ignored.sslParameters
- the SSLParameterspublic abstract HttpClient.Builder executor(Executor executor)
Executors.newCachedThreadPool
.executor
- the Executorpublic abstract HttpClient.Builder followRedirects(HttpClient.Redirect policy)
NEVER
policy
- the redirection policypublic abstract HttpClient.Builder version(HttpClient.Version version)
HttpClient.Version.HTTP_1_1
. If
HttpClient.Version.HTTP_2
is set, then each request will
attempt to upgrade to HTTP/2. If the upgrade succeeds, then the
response to this request will use HTTP/2 and all subsequent requests
and responses to the same
origin server
will use HTTP/2. If the upgrade fails, then the response will be
handled using HTTP/1.1version
- the requested HTTP protocol versionpublic abstract HttpClient.Builder priority(int priority)
1
and 256
(inclusive).priority
- the priority weightingIllegalArgumentException
- if the given priority is out of rangepublic abstract HttpClient.Builder proxy(ProxySelector selector)
ProxySelector
for this client. If no selector
is set, then no proxies are used. If a null
parameter is
given then the system wide default proxy selector is used.ProxySelector.of(InetSocketAddress)
provides a ProxySelector
which uses one proxy for all requests.selector
- the ProxySelectorpublic abstract HttpClient.Builder authenticator(Authenticator a)
a
- the Authenticatorpublic abstract HttpClient build()
HttpClient
built from the current state of this
builder. Submit a bug or feature
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 2015, 2017, Oracle and/or its affiliates. 500 Oracle Parkway
Redwood Shores, CA 94065 USA. All rights reserved.
DRAFT 9-Debian+0-9b153-2