APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.internal.net.http

pack-priv abstract Class ExchangeImpl<T>

extends Object
Class Inheritance
Known Direct Subclasses
jdk.internal.net.http.Http1Exchange, jdk.internal.net.http.Http3Stream, jdk.internal.net.http.Stream
Imports
java.io.IOException, java.net.ConnectException, .InetSocketAddress, java.net.http.HttpConnectTimeoutException, .HttpOption.Http3DiscoveryMode, .HttpResponse, .HttpResponse.ResponseInfo, .UnsupportedProtocolVersionException, java.util.concurrent.CompletableFuture, .Executor, java.util.function.Supplier, jdk.internal.net.http.Http2Connection.ALPNException, jdk.internal.net.http.common.HttpBodySubscriberWrapper, .Logger, .MinimalFuture, .Utils

Splits request so that headers and body can be sent separately with optional (multiple) responses in between (e.g. 100 Continue). Also request and response always sent/received in different calls. Synchronous and asynchronous versions of each method are provided. Separate implementations of this class exist for HTTP/1.1 and HTTP/2 Http1Exchange (HTTP/1.1) Stream (HTTP/2) These implementation classes are where work is allocated to threads.

Field Summary

Modifier and TypeField and Description
private static final Logger
pack-priv final Exchange<T>
private volatile boolean

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private static <U> CompletableFuture<? extends ExchangeImpl<U>>
attemptHttp2Exchange(Exchange<U> exchange, HttpConnection connection)

private static <U> CompletableFuture<? extends ExchangeImpl<U>>
attemptHttp3Exchange(Exchange<U> exchange, HttpConnection connection)

pack-priv abstract void
cancel()

Cancels a request.

pack-priv abstract void
cancel(IOException cause)

Cancels a request with a cause.

pack-priv static boolean

Returns:

true, if it is allowed to cancel the request timer on response body subscriber termination; false, otherwise
cancelTimerOnResponseBodySubscriberTermination
(boolean
indicates if the associated request is a WebSocket handshake
webSocket
,
int
the status code of the associated response
statusCode
)

Returns true, if it is allowed to cancel the request timer on response body subscriber termination; false, otherwise.

private static <U, T extends ExchangeImpl<U>> T
checkCancelled(T exchangeImpl)

pack-priv HttpClientImpl
pack-priv abstract void
completed()

Called when the exchange is completed, so that cleanup actions may be performed - such as deregistering callbacks.

pack-priv abstract HttpConnection
connection()

Returns the HttpConnection instance to which this exchange is assigned.

private static <U> CompletableFuture<? extends ExchangeImpl<U>>
private static <U> CompletableFuture<? extends ExchangeImpl<U>>
private static <T> CompletableFuture<Http1Exchange<T>>
pack-priv HttpBodySubscriberWrapper<T>

Returns:

a new HttpBodySubscriberWrapper to handle the response
createResponseSubscriber
(HttpResponse.BodyHandler<T>
a body handler
handler
,
HttpResponse.ResponseInfo
a response info
response
)

Creates and wraps an HttpResponse.BodySubscriber from a HttpResponse.BodyHandler for the given ResponseInfo.

pack-priv void
pack-priv final boolean
private static <U> CompletableFuture<? extends ExchangeImpl<U>>
private static <U> CompletableFuture<? extends ExchangeImpl<U>>
pack-priv static <U> CompletableFuture<? extends ExchangeImpl<U>>
get(Exchange<U> exchange, HttpConnection connection)

Initiates a new exchange and assigns it to a connection if one exists already.

pack-priv abstract Throwable

Returns:

the cause for which this exchange was canceled, if available.
getCancelCause
()

Returns the cause for which this exchange was canceled, if available.

pack-priv final Exchange<T>
pack-priv abstract CompletableFuture<Response>
getResponseAsync(Executor executor)

Gets the response headers.

pack-priv abstract CompletableFuture<Void>
ignoreBody()

Ignore/consume the body.

pack-priv abstract boolean

Returns:

true if this exchange was canceled.
isCanceled
()

Returns true if this exchange was canceled.

private static boolean
isTCP(HttpConnection connection)

pack-priv void
pack-priv abstract void
onProtocolError(IOException
The cause of the protocol violation
cause
)

Invoked whenever there is a (HTTP) protocol error when dealing with the response from the server.

pack-priv abstract CompletableFuture<T>
readBodyAsync(HttpResponse.BodyHandler<T> handler, boolean returnConnectionToPool, Executor executor)

pack-priv abstract void
released()

Called when the exchange is released, so that cleanup actions may be performed - such as deregistering callbacks.

pack-priv abstract CompletableFuture<ExchangeImpl<T>>
sendBodyAsync()

Sends a request body, after request headers have been sent.

pack-priv abstract CompletableFuture<ExchangeImpl<T>>
pack-priv final void
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

debugback to summary
private static final Logger debug
exchangeback to summary
pack-priv final Exchange<T> exchange
expectTimeoutRaisedback to summary
private volatile boolean expectTimeoutRaised

Constructor Detail

ExchangeImplback to summary
pack-priv ExchangeImpl(Exchange<T> e)

Method Detail

attemptHttp2Exchangeback to summary
private static <U> CompletableFuture<? extends ExchangeImpl<U>> attemptHttp2Exchange(Exchange<U> exchange, HttpConnection connection)
attemptHttp3Exchangeback to summary
private static <U> CompletableFuture<? extends ExchangeImpl<U>> attemptHttp3Exchange(Exchange<U> exchange, HttpConnection connection)
cancelback to summary
pack-priv abstract void cancel()

Cancels a request. Not currently exposed through API.

cancelback to summary
pack-priv abstract void cancel(IOException cause)

Cancels a request with a cause. Not currently exposed through API.

cancelTimerOnResponseBodySubscriberTerminationback to summary
pack-priv static boolean cancelTimerOnResponseBodySubscriberTermination(boolean webSocket, int statusCode)

Returns true, if it is allowed to cancel the request timer on response body subscriber termination; false, otherwise.

Parameters
webSocket:boolean

indicates if the associated request is a WebSocket handshake

statusCode:int

the status code of the associated response

Returns:boolean

true, if it is allowed to cancel the request timer on response body subscriber termination; false, otherwise

checkCancelledback to summary
private static <U, T extends ExchangeImpl<U>> T checkCancelled(T exchangeImpl)
clientback to summary
pack-priv HttpClientImpl client()
completedback to summary
pack-priv abstract void completed()

Called when the exchange is completed, so that cleanup actions may be performed - such as deregistering callbacks. Typically, completed is called at the end of the exchange, when the final response body has been received (or an error has caused the completion of the exchange).

connectionback to summary
pack-priv abstract HttpConnection connection()

Returns the HttpConnection instance to which this exchange is assigned.

createExchangeImplback to summary
private static <U> CompletableFuture<? extends ExchangeImpl<U>> createExchangeImpl(Http3Connection c, Throwable t, Exchange<U> exchange, HttpConnection connection)
createExchangeImplback to summary
private static <U> CompletableFuture<? extends ExchangeImpl<U>> createExchangeImpl(Http2Connection c, Throwable t, Exchange<U> exchange, HttpConnection connection)
createHttp1Exchangeback to summary
private static <T> CompletableFuture<Http1Exchange<T>> createHttp1Exchange(Exchange<T> ex, HttpConnection as)
createResponseSubscriberback to summary
pack-priv HttpBodySubscriberWrapper<T> createResponseSubscriber(HttpResponse.BodyHandler<T> handler, HttpResponse.ResponseInfo response)

Creates and wraps an HttpResponse.BodySubscriber from a HttpResponse.BodyHandler for the given ResponseInfo. An HttpBodySubscriberWrapper wraps a response body subscriber and makes sure its completed/onError methods are called only once, and that its onSusbscribe is called before onError. This is useful when errors occur asynchronously, and most typically when the error occurs before the BodySubscriber has subscribed.

Parameters
handler:HttpResponse.BodyHandler<T>

a body handler

response:HttpResponse.ResponseInfo

a response info

Returns:HttpBodySubscriberWrapper<T>

a new HttpBodySubscriberWrapper to handle the response

expectContinueFailedback to summary
pack-priv void expectContinueFailed(int rcode)
expectTimeoutRaisedback to summary
pack-priv final boolean expectTimeoutRaised()
fallbackToHttp1OnTimeoutback to summary
private static <U> CompletableFuture<? extends ExchangeImpl<U>> fallbackToHttp1OnTimeout(Http3Connection c, Throwable t, Exchange<U> exchange, HttpConnection connection)
firstToCompleteback to summary
private static <U> CompletableFuture<? extends ExchangeImpl<U>> firstToComplete(Exchange<U> exchange, HttpConnection connection, Supplier<CompletableFuture<Http2Connection>> c2fs, CompletableFuture<Http3Connection> c3f)
getback to summary
pack-priv static <U> CompletableFuture<? extends ExchangeImpl<U>> get(Exchange<U> exchange, HttpConnection connection)

Initiates a new exchange and assigns it to a connection if one exists already. connection usually null.

getCancelCauseback to summary
pack-priv abstract Throwable getCancelCause()

Returns the cause for which this exchange was canceled, if available.

Returns:Throwable

the cause for which this exchange was canceled, if available.

getExchangeback to summary
pack-priv final Exchange<T> getExchange()
getResponseAsyncback to summary
pack-priv abstract CompletableFuture<Response> getResponseAsync(Executor executor)

Gets the response headers. Completes before body is read.

ignoreBodyback to summary
pack-priv abstract CompletableFuture<Void> ignoreBody()

Ignore/consume the body.

isCanceledback to summary
pack-priv abstract boolean isCanceled()

Returns true if this exchange was canceled.

Returns:boolean

true if this exchange was canceled.

isTCPback to summary
private static boolean isTCP(HttpConnection connection)
nullBodyback to summary
pack-priv void nullBody(HttpResponse<T> resp, Throwable t)
onProtocolErrorback to summary
pack-priv abstract void onProtocolError(IOException cause)

Invoked whenever there is a (HTTP) protocol error when dealing with the response from the server. The implementations of ExchangeImpl are then expected to take necessary action that is expected by the corresponding specifications whenever a protocol error happens. For example, in HTTP/1.1, such protocol error would result in the connection being closed.

Parameters
cause:IOException

The cause of the protocol violation

readBodyAsyncback to summary
pack-priv abstract CompletableFuture<T> readBodyAsync(HttpResponse.BodyHandler<T> handler, boolean returnConnectionToPool, Executor executor)
releasedback to summary
pack-priv abstract void released()

Called when the exchange is released, so that cleanup actions may be performed - such as deregistering callbacks. Typically released is called during upgrade, when an HTTP/2 stream takes over from an Http1Exchange, or when a new exchange is created during a multi exchange before the final response body was received.

sendBodyAsyncback to summary
pack-priv abstract CompletableFuture<ExchangeImpl<T>> sendBodyAsync()

Sends a request body, after request headers have been sent.

sendHeadersAsyncback to summary
pack-priv abstract CompletableFuture<ExchangeImpl<T>> sendHeadersAsync()
setExpectTimeoutRaisedback to summary
pack-priv final void setExpectTimeoutRaised()
upgradedback to summary
pack-priv void upgraded()