Class HttpClientConnection

  • All Implemented Interfaces:
    java.lang.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.
    • 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
      • 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.
      • 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.