public abstract class HttpClient extends Object
HttpRequest
s. All requests are associated with, and created from a
HttpClient
.
HttpClient
s are immutable and created from a builder returned
from create()
. Request builders that are associated with
an application created client, are created by calling request(URI)
.
It is also possible to create a request builder directly which is associated
with the default HttpClient
by calling HttpRequest.create(URI)
.
The HTTP API functions asynchronously (using CompletableFuture
) and also in a simple synchronous
mode, where all work may be done on the calling thread. In asynchronous mode,
work is done on the threads supplied by the client's ExecutorService
.
The default HttpClient
is
used whenever a request is created without specifying a client explicitly
(by calling HttpRequest.create
).
There is only one static instance of this HttpClient
. A reference to
the default client can be obtained by calling getDefault()
. If a
security manager is set, then a permission is required for this.
See HttpRequest
for examples of usage of this API.
Modifier and Type | Class | Description |
---|---|---|
static class |
HttpClient.Builder |
A builder of immutable
HttpClient s. |
static class |
HttpClient.Redirect |
Defines automatic redirection policy.
|
static class |
HttpClient.Version |
The HTTP protocol version.
|
Modifier and Type | Method | Description |
---|---|---|
abstract Optional<Authenticator> |
authenticator() |
Returns an
Optional containing the Authenticator set on
this client. |
abstract Optional<CookieManager> |
cookieManager() |
Returns an
Optional which contains this client's CookieManager . |
static HttpClient.Builder |
create() |
Creates a new
HttpClient builder. |
abstract ExecutorService |
executorService() |
Returns the
ExecutorService set on this client. |
abstract HttpClient.Redirect |
followRedirects() |
Returns the follow-redirects setting for this client.
|
static HttpClient |
getDefault() |
Returns the default
HttpClient that is used when a HttpRequest is created without specifying a client. |
abstract boolean |
pipelining() |
Returns whether this client supports HTTP/1.1 pipelining.
|
abstract Optional<ProxySelector> |
proxy() |
Returns an
Optional containing the ProxySelector for this client. |
abstract HttpRequest.Builder |
request() |
Creates a
HttpRequest builder associated with this client. |
abstract HttpRequest.Builder |
request(URI uri) |
Creates a
HttpRequest builder associated with this client and
using the given request URI. |
abstract SSLContext |
sslContext() |
Returns the SSLContext, if one was set on this client.
|
abstract Optional<SSLParameters> |
sslParameters() |
Returns an
Optional containing the SSLParameters set on
this client. |
abstract HttpClient.Version |
version() |
Returns the HTTP protocol version requested for this client.
|
public static HttpClient.Builder create()
HttpClient
builder.HttpClient.Builder
public static HttpClient getDefault()
HttpClient
that is used when a HttpRequest
is created without specifying a client. If a security
manager is set, then its checkPermission
method is called with a
NetPermission
specifying the name "getDefaultHttpClient".
If the caller does not possess this permission a SecurityException
is thrown.HttpClient
explicitly.HttpClient
SecurityException
- if the caller does not have the required
permissionpublic abstract HttpRequest.Builder request()
HttpRequest
builder associated with this client.public abstract HttpRequest.Builder request(URI uri)
HttpRequest
builder associated with this client and
using the given request URI.uri
- the request URIpublic abstract Optional<CookieManager> cookieManager()
Optional
which contains this client's CookieManager
. If no CookieManager was set in this client's builder,
then the Optional
is empty.Optional
containing this client's CookieManagerpublic abstract HttpClient.Redirect followRedirects()
HttpClient.Redirect.NEVER
public abstract Optional<ProxySelector> proxy()
Optional
containing the ProxySelector for this client.
If no proxy is set then the Optional
is empty.Optional
containing this client's proxy selectorpublic abstract SSLContext sslContext()
NetPermission
("getSSLContext") permission.
If no SSLContext was set, then the default context is returned.public abstract Optional<SSLParameters> sslParameters()
Optional
containing the SSLParameters
set on
this client. If no SSLParameters
were set in the client's builder,
then the Optional
is empty.Optional
containing this client's SSLParameterspublic abstract Optional<Authenticator> authenticator()
Optional
containing the Authenticator
set on
this client. If no Authenticator
was set in the client's builder,
then the Optional
is empty.Optional
containing this client's Authenticatorpublic abstract HttpClient.Version version()
HttpClient.Version.HTTP_1_1
public abstract boolean pipelining()
public abstract ExecutorService executorService()
ExecutorService
set on this client. If an
ExecutorService
was not set on the client's builder, then a default
object is returned. The default ExecutorService is created independently
for each client. Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2016, Oracle and/or its affiliates. All rights reserved.
DRAFT 9-Ubuntu+0-9b144-1