Package software.amazon.awssdk.crt.http
Class HttpClientConnection
- java.lang.Object
-
- software.amazon.awssdk.crt.CrtResource
-
- software.amazon.awssdk.crt.http.HttpClientConnection
-
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
Http2ClientConnection
public class HttpClientConnection extends CrtResource
This class wraps aws-c-http to provide the basic HTTP request/response functionality via the AWS Common Runtime. HttpClientConnection represents a single connection to a HTTP service endpoint. This class is not thread safe and should not be called from different threads.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class software.amazon.awssdk.crt.CrtResource
CrtResource.ResourceInstance
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
HttpClientConnection(long connectionBinding)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
canReleaseReferencesImmediately()
Determines whether a resource releases its dependencies at the same time the native handle is released or if it waits.HttpVersion
getVersion()
static boolean
isErrorRetryable(HttpException exception)
Certain exceptions thrown by this HTTP API are from invalid boundary conditions that, if the request isn't altered, will never succeed.boolean
isOpen()
Check the underlying http connection is still open or not.HttpStreamBase
makeRequest(HttpRequestBase request, HttpStreamBaseResponseHandler streamHandler)
Schedules an HttpRequestBase on the Native EventLoop for this HttpClientConnection applies to both HTTP/2 and HTTP/1.1 connection.HttpStream
makeRequest(HttpRequest request, HttpStreamResponseHandler streamHandler)
Schedules an HttpRequest on the Native EventLoop for this HttpClientConnection specific to HTTP/1.1 connection.protected void
releaseNativeHandle()
Releases this HttpClientConnection back into the Connection Pool, and allows another Request to acquire this connection.void
shutdown()
Shuts down the underlying http connection.-
Methods inherited from class software.amazon.awssdk.crt.CrtResource
acquireNativeHandle, addRef, addReferenceTo, close, collectNativeResource, collectNativeResources, decRef, getNativeHandle, getResourceLogDescription, isNull, logNativeResources, logNativeResources, releaseReferences, removeReferenceTo, setDescription, swapReferenceTo, waitForNoResources
-
-
-
-
Method Detail
-
makeRequest
public HttpStream makeRequest(HttpRequest request, HttpStreamResponseHandler streamHandler) throws CrtRuntimeException
Schedules an HttpRequest on the Native EventLoop for this HttpClientConnection specific to HTTP/1.1 connection.- Parameters:
request
- The Request to make to the Server.streamHandler
- The Stream Handler to be called from the Native EventLoop- Returns:
- The HttpStream that represents this Request/Response Pair. It can be closed at any time during the request/response, but must be closed by the user thread making this request when it's done.
- Throws:
CrtRuntimeException
- if stream creation fails
-
makeRequest
public HttpStreamBase makeRequest(HttpRequestBase request, HttpStreamBaseResponseHandler streamHandler) throws CrtRuntimeException
Schedules an HttpRequestBase on the Native EventLoop for this HttpClientConnection applies to both HTTP/2 and HTTP/1.1 connection.- Parameters:
request
- The Request to make to the Server.streamHandler
- The Stream Handler to be called from the Native EventLoop- Returns:
- The HttpStream that represents this Request/Response Pair. It can be closed at any time during the request/response, but must be closed by the user thread making this request when it's done.
- Throws:
CrtRuntimeException
- if stream creation fails
-
canReleaseReferencesImmediately
protected boolean canReleaseReferencesImmediately()
Determines whether a resource releases its dependencies at the same time the native handle is released or if it waits. Resources that wait are responsible for calling releaseReferences() manually.- Specified by:
canReleaseReferencesImmediately
in classCrtResource
- Returns:
- true if this resource releases synchronously, false if this resource performs async shutdown
-
releaseNativeHandle
protected void releaseNativeHandle()
Releases this HttpClientConnection back into the Connection Pool, and allows another Request to acquire this connection.- Specified by:
releaseNativeHandle
in classCrtResource
-
shutdown
public void shutdown()
Shuts down the underlying http connection. Even if this function is called, you still need to properly close the connection as well in order to release the native resources.
-
isOpen
public boolean isOpen()
Check the underlying http connection is still open or not.- Returns:
- true unless the underlying http connection is shutting down, or has been shutdown.
-
getVersion
public HttpVersion getVersion()
-
isErrorRetryable
public static boolean isErrorRetryable(HttpException exception)
Certain exceptions thrown by this HTTP API are from invalid boundary conditions that, if the request isn't altered, will never succeed. This function returns false if the exception is caused by such a condition.It does not mean the request that generated the error SHOULD be retried: only that as far as this client is concerned, the request might, possibly succeed with a subsequent attempt.
- Parameters:
exception
- , an exception thrown by the CRT HTTP API--for any reason.- Returns:
- true if the error that generated the exception makes sense for a retry, and false otherwise.
-
-