Top Description Fields Constructors Methods
jdk.internal.net.http

public final Class HttpClientFacade

extends HttpClient
implements Trackable
Class Inheritance
All Implemented Interfaces
jdk.internal.net.http.common.OperationTrackers.Trackable
Imports
java.io.IOException, java.lang.ref.Cleaner, .Reference, java.net.Authenticator, .CookieHandler, .ProxySelector, java.time.Duration, java.util.Optional, java.util.concurrent.CompletableFuture, .Executor, javax.net.ssl.SSLContext, .SSLParameters, java.net.http.HttpClient, .HttpRequest, .HttpResponse, .HttpResponse.BodyHandler, .HttpResponse.PushPromiseHandler, .WebSocket, jdk.internal.net.http.common.OperationTrackers.Trackable, .OperationTrackers.Tracker, jdk.internal.ref.CleanerFactory

An HttpClientFacade is a simple class that wraps an HttpClient implementation and delegates everything to its implementation delegate.

Implementation Specification

Though the facade strongly reference its implementation, the implementation MUST NOT strongly reference the facade. It MAY use weak references if needed.

Field Summary

Modifier and TypeField and Description
pack-priv static final Cleaner
pack-priv final HttpClientImpl

Constructor Summary

AccessConstructor and Description
pack-priv
HttpClientFacade(HttpClientImpl impl)

Creates an HttpClientFacade.

Method Summary

Modifier and TypeMethod and Description
public Optional<Authenticator>
authenticator()

Implements abstract java.net.http.HttpClient.authenticator.

Returns an Optional containing the Authenticator set on this client.

public boolean
awaitTermination(Duration
the maximum time to wait
duration
)

Overrides java.net.http.HttpClient.awaitTermination.

Blocks until all operations have completed execution after a shutdown request, or the duration elapses, or the current thread is interrupted, whichever happens first.

public void
close()

Overrides java.net.http.HttpClient.close.

Implements java.lang.AutoCloseable.close.

Initiates an orderly shutdown in which requests previously submitted to send or sendAsync are run to completion, but no new request will be accepted.

public Optional<Duration>
connectTimeout()

Implements abstract java.net.http.HttpClient.connectTimeout.

Returns an Optional containing the connect timeout duration for this client.

public Optional<CookieHandler>
cookieHandler()

Implements abstract java.net.http.HttpClient.cookieHandler.

Returns an Optional containing this client's CookieHandler.

public Optional<Executor>
executor()

Implements abstract java.net.http.HttpClient.executor.

Returns an Optional containing this client's Executor.

public HttpClient.Redirect
followRedirects()

Implements abstract java.net.http.HttpClient.followRedirects.

Returns the follow redirects policy for this client.

public OperationTrackers.Tracker
public boolean
isTerminated()

Overrides java.net.http.HttpClient.isTerminated.

Returns true if all operations have completed following a shutdown.

public WebSocket.Builder
newWebSocketBuilder()

Overrides java.net.http.HttpClient.newWebSocketBuilder.

Creates a new WebSocket builder (optional operation).

public Optional<ProxySelector>
proxy()

Implements abstract java.net.http.HttpClient.proxy.

Returns an Optional containing the ProxySelector supplied to this client.

public <T> HttpResponse<T>
send(HttpRequest
the request
req
,
HttpResponse.BodyHandler<T>
the response body handler
responseBodyHandler
)

Implements abstract java.net.http.HttpClient.send.

Sends the given request using this client, blocking if necessary to get the response.

public <T> CompletableFuture<HttpResponse<T>>
sendAsync(HttpRequest
the request
req
,
HttpResponse.BodyHandler<T>
the response body handler
responseBodyHandler
)

Implements abstract java.net.http.HttpClient.sendAsync.

Sends the given request asynchronously using this client with the given response body handler.

public <T> CompletableFuture<HttpResponse<T>>
sendAsync(HttpRequest
the request
req
,
HttpResponse.BodyHandler<T>
the response body handler
responseBodyHandler
,
HttpResponse.PushPromiseHandler<T>
push promise handler, may be null
pushPromiseHandler
)

Implements abstract java.net.http.HttpClient.sendAsync.

Sends the given request asynchronously using this client with the given response body handler and push promise handler.

public void
shutdown()

Overrides java.net.http.HttpClient.shutdown.

Initiates an orderly shutdown in which requests previously submitted with send or sendAsync are run to completion, but no new request will be accepted.

public void
shutdownNow()

Overrides java.net.http.HttpClient.shutdownNow.

This method attempts to initiate an immediate shutdown.

public SSLContext
sslContext()

Implements abstract java.net.http.HttpClient.sslContext.

Returns this client's SSLContext.

public SSLParameters
sslParameters()

Implements abstract java.net.http.HttpClient.sslParameters.

Returns a copy of this client's SSLParameters.

public Executor
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public HttpClient.Version
version()

Implements abstract java.net.http.HttpClient.version.

Returns the preferred HTTP protocol version for this client.

Inherited from java.net.http.HttpClient:
newBuildernewHttpClient

Field Detail

cleanerback to summary
pack-priv static final Cleaner cleaner
implback to summary
pack-priv final HttpClientImpl impl

Constructor Detail

HttpClientFacadeback to summary
pack-priv HttpClientFacade(HttpClientImpl impl)

Creates an HttpClientFacade.

Method Detail

authenticatorback to summary
public Optional<Authenticator> authenticator()

Implements abstract java.net.http.HttpClient.authenticator.

Doc from java.net.http.HttpClient.authenticator.

Returns an Optional containing the Authenticator set on this client. If no Authenticator was set in the client's builder, then the Optional is empty.

Returns:Optional<Authenticator>

an Optional containing this client's Authenticator

Annotations
@Override
awaitTerminationback to summary
public boolean awaitTermination(Duration duration) throws InterruptedException

Overrides java.net.http.HttpClient.awaitTermination.

Doc from java.net.http.HttpClient.awaitTermination.

Blocks until all operations have completed execution after a shutdown request, or the duration elapses, or the current thread is interrupted, whichever happens first. Operations are any tasks required to run a request previously submitted with send or sendAsync to completion.

This method does not wait if the duration to wait is less than or equal to zero. In this case, the method just tests if the thread has terminated.

Parameters
duration:Duration

the maximum time to wait

Returns:boolean

true if this client terminated and false if the timeout elapsed before termination

Annotations
@Override
Exceptions
InterruptedException:
if interrupted while waiting
closeback to summary
public void close()

Overrides java.net.http.HttpClient.close.

Implements java.lang.AutoCloseable.close.

Doc from java.net.http.HttpClient.close.

Initiates an orderly shutdown in which requests previously submitted to send or sendAsync are run to completion, but no new request will be accepted. Running a request to completion may involve running several operations in the background, including waiting for responses to be delivered. This method waits until all operations have completed execution and the client has terminated.

If interrupted while waiting, this method may attempt to stop all operations by calling shutdownNow(). It then continues to wait until all actively executing operations have completed. The interrupt status will be re-asserted before this method returns.

If already terminated, invoking this method has no effect.

Annotations
@Override
connectTimeoutback to summary
public Optional<Duration> connectTimeout()

Implements abstract java.net.http.HttpClient.connectTimeout.

Doc from java.net.http.HttpClient.connectTimeout.

Returns an Optional containing the connect timeout duration for this client. If the connect timeout duration was not set in the client's builder, then the Optional is empty.

Returns:Optional<Duration>

an Optional containing this client's connect timeout duration

Annotations
@Override
cookieHandlerback to summary
public Optional<CookieHandler> cookieHandler()

Implements abstract java.net.http.HttpClient.cookieHandler.

Doc from java.net.http.HttpClient.cookieHandler.

Returns an Optional containing this client's CookieHandler. If no CookieHandler was set in this client's builder, then the Optional is empty.

Returns:Optional<CookieHandler>

an Optional containing this client's CookieHandler

Annotations
@Override
executorback to summary
public Optional<Executor> executor()

Implements abstract java.net.http.HttpClient.executor.

Doc from java.net.http.HttpClient.executor.

Returns an Optional containing this client's Executor. If no Executor was set in the client's builder, then the Optional is empty.

Even though this method may return an empty optional, the HttpClient may still have an non-exposed default executor that is used for executing asynchronous and dependent tasks.

Returns:Optional<Executor>

an Optional containing this client's Executor

Annotations
@Override
followRedirectsback to summary
public HttpClient.Redirect followRedirects()

Implements abstract java.net.http.HttpClient.followRedirects.

Doc from java.net.http.HttpClient.followRedirects.

Returns the follow redirects policy for this client. The default value for client's built by builders that do not specify a redirect policy is NEVER.

Returns:HttpClient.Redirect

this client's follow redirects setting

Annotations
@Override
getOperationsTrackerback to summary
public OperationTrackers.Tracker getOperationsTracker()

Implements jdk.internal.net.http.common.OperationTrackers.Trackable.getOperationsTracker.

Annotations
@Override
isTerminatedback to summary
public boolean isTerminated()

Overrides java.net.http.HttpClient.isTerminated.

Doc from java.net.http.HttpClient.isTerminated.

Returns true if all operations have completed following a shutdown. Operations are any tasks required to run a request previously submitted with send or sendAsync to completion.

Note that isTerminated is never true unless either shutdown or shutdownNow was called first.

Returns:boolean

true if all tasks have completed following a shutdown

Annotations
@Override
newWebSocketBuilderback to summary
public WebSocket.Builder newWebSocketBuilder()

Overrides java.net.http.HttpClient.newWebSocketBuilder.

Doc from java.net.http.HttpClient.newWebSocketBuilder.

Creates a new WebSocket builder (optional operation).

Example

HttpClient client = HttpClient.newHttpClient(); CompletableFuture<WebSocket> ws = client.newWebSocketBuilder() .buildAsync(URI.create("ws://websocket.example.com"), listener);
HttpClient client = HttpClient.newHttpClient();
CompletableFuture<WebSocket> ws = client.newWebSocketBuilder()
   .buildAsync(URI.create("ws://websocket.example.com"), listener);

Finer control over the WebSocket Opening Handshake can be achieved by using a custom HttpClient.

Example

InetSocketAddress addr = new InetSocketAddress("proxy.example.com", 80); HttpClient client = HttpClient.newBuilder() .proxy(ProxySelector.of(addr)) .build(); CompletableFuture<WebSocket> ws = client.newWebSocketBuilder() .buildAsync(URI.create("ws://websocket.example.com"), listener);
InetSocketAddress addr = new InetSocketAddress("proxy.example.com", 80);
HttpClient client = HttpClient.newBuilder()
        .proxy(ProxySelector.of(addr))
        .build();

CompletableFuture<WebSocket> ws = client.newWebSocketBuilder()
        .buildAsync(URI.create("ws://websocket.example.com"), listener);
Returns:WebSocket.Builder

a WebSocket.Builder

Annotations
@Override
proxyback to summary
public Optional<ProxySelector> proxy()

Implements abstract java.net.http.HttpClient.proxy.

Doc from java.net.http.HttpClient.proxy.

Returns an Optional containing the ProxySelector supplied to this client. If no proxy selector was set in this client's builder, then the Optional is empty.

Even though this method may return an empty optional, the HttpClient may still have a non-exposed default proxy selector that is used for sending HTTP requests.

Returns:Optional<ProxySelector>

an Optional containing the proxy selector supplied to this client.

Annotations
@Override
sendback to summary
public <T> HttpResponse<T> send(HttpRequest req, HttpResponse.BodyHandler<T> responseBodyHandler) throws IOException, InterruptedException

Implements abstract java.net.http.HttpClient.send.

Doc from java.net.http.HttpClient.send.

Sends the given request using this client, blocking if necessary to get the response. The returned HttpResponse<T> contains the response status, headers, and body ( as handled by given response body handler ).

If the operation is interrupted, the default HttpClient implementation attempts to cancel the HTTP exchange and InterruptedException is thrown. No guarantee is made as to exactly when the cancellation request may be taken into account. In particular, the request might still get sent to the server, as its processing might already have started asynchronously in another thread, and the underlying resources may only be released asynchronously.

  • With HTTP/1.1, an attempt to cancel may cause the underlying connection to be closed abruptly.
  • With HTTP/2, an attempt to cancel may cause the stream to be reset, or in certain circumstances, may also cause the connection to be closed abruptly, if, for instance, the thread is currently trying to write to the underlying socket.
Parameters
<T>
the response body type
req:HttpRequest

the request

responseBodyHandler:HttpResponse.BodyHandler<T>

the response body handler

Returns:HttpResponse<T>

the response

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs when sending or receiving, or the client has shut down
InterruptedException:
if the operation is interrupted
sendAsyncback to summary
public <T> CompletableFuture<HttpResponse<T>> sendAsync(HttpRequest req, HttpResponse.BodyHandler<T> responseBodyHandler)

Implements abstract java.net.http.HttpClient.sendAsync.

Doc from java.net.http.HttpClient.sendAsync.

Sends the given request asynchronously using this client with the given response body handler.

Equivalent to: sendAsync(request, responseBodyHandler, null).

Parameters
<T>
the response body type
req:HttpRequest

the request

responseBodyHandler:HttpResponse.BodyHandler<T>

the response body handler

Returns:CompletableFuture<HttpResponse<T>>

a CompletableFuture<HttpResponse<T>>

Annotations
@Override
sendAsyncback to summary
public <T> CompletableFuture<HttpResponse<T>> sendAsync(HttpRequest req, HttpResponse.BodyHandler<T> responseBodyHandler, HttpResponse.PushPromiseHandler<T> pushPromiseHandler)

Implements abstract java.net.http.HttpClient.sendAsync.

Doc from java.net.http.HttpClient.sendAsync.

Sends the given request asynchronously using this client with the given response body handler and push promise handler.

The returned completable future, if completed successfully, completes with an HttpResponse<T> that contains the response status, headers, and body ( as handled by given response body handler ).

Push promises received, if any, are handled by the given pushPromiseHandler. A null valued pushPromiseHandler rejects any push promises.

The returned completable future completes exceptionally with:

The default HttpClient implementation returns CompletableFuture objects that are cancelable. CompletableFuture objects derived from cancelable futures are themselves cancelable. Invoking cancel(true) on a cancelable future that is not completed, attempts to cancel the HTTP exchange in an effort to release underlying resources as soon as possible. No guarantee is made as to exactly when the cancellation request may be taken into account. In particular, the request might still get sent to the server, as its processing might already have started asynchronously in another thread, and the underlying resources may only be released asynchronously.

  • With HTTP/1.1, an attempt to cancel may cause the underlying connection to be closed abruptly.
  • With HTTP/2, an attempt to cancel may cause the stream to be reset.
Parameters
<T>
the response body type
req:HttpRequest

the request

responseBodyHandler:HttpResponse.BodyHandler<T>

the response body handler

pushPromiseHandler:HttpResponse.PushPromiseHandler<T>

push promise handler, may be null

Returns:CompletableFuture<HttpResponse<T>>

a CompletableFuture<HttpResponse<T>>

Annotations
@Override
shutdownback to summary
public void shutdown()

Overrides java.net.http.HttpClient.shutdown.

Doc from java.net.http.HttpClient.shutdown.

Initiates an orderly shutdown in which requests previously submitted with send or sendAsync are run to completion, but no new request will be accepted. Running a request to completion may involve running several operations in the background, including waiting for responses to be delivered, which will all have to run to completion until the request is considered completed. Invocation has no additional effect if already shut down.

This method does not wait for previously submitted request to complete execution. Use awaitTermination or close to do that.

Annotations
@Override
shutdownNowback to summary
public void shutdownNow()

Overrides java.net.http.HttpClient.shutdownNow.

Doc from java.net.http.HttpClient.shutdownNow.

This method attempts to initiate an immediate shutdown. An implementation of this method may attempt to interrupt operations that are actively running. Operations are any tasks required to run a request previously submitted with send or sendAsync to completion. The behavior of actively running operations when interrupted is undefined. In particular, there is no guarantee that interrupted operations will terminate, or that code waiting on these operations will ever be notified.

Annotations
@Override
sslContextback to summary
public SSLContext sslContext()

Implements abstract java.net.http.HttpClient.sslContext.

Doc from java.net.http.HttpClient.sslContext.

Returns this client's SSLContext.

If no SSLContext was set in this client's builder, then the default context is returned.

Returns:SSLContext

this client's SSLContext

Annotations
@Override
sslParametersback to summary
public SSLParameters sslParameters()

Implements abstract java.net.http.HttpClient.sslParameters.

Doc from java.net.http.HttpClient.sslParameters.

Returns a copy of this client's SSLParameters.

If no SSLParameters were set in the client's builder, then an implementation specific default set of parameters, that the client will use, is returned.

Returns:SSLParameters

this client's SSLParameters

Annotations
@Override
theExecutorback to summary
public Executor theExecutor()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
versionback to summary
public HttpClient.Version version()

Implements abstract java.net.http.HttpClient.version.

Doc from java.net.http.HttpClient.version.

Returns the preferred HTTP protocol version for this client. The default value is HttpClient.Version#HTTP_2

Returns:HttpClient.Version

the HTTP protocol version requested

Annotations
@Override