Class RetryHttpClient

java.lang.Object
com.datastax.astra.internal.http.RetryHttpClient

public class RetryHttpClient extends Object
Http Client using JDK11 client with a retry mechanism.
  • Field Details

    • CONTENT_TYPE_JSON

      public static final String CONTENT_TYPE_JSON
      Headers, Api is usig JSON
      See Also:
    • CONTENT_TYPE_GRAPHQL

      public static final String CONTENT_TYPE_GRAPHQL
      Headers, Api is usig JSON
      See Also:
    • HEADER_ACCEPT

      public static final String HEADER_ACCEPT
      Header param.
      See Also:
    • HEADER_CASSANDRA

      public static final String HEADER_CASSANDRA
      Headers param to insert the token.
      See Also:
    • HEADER_REQUEST_ID

      public static final String HEADER_REQUEST_ID
      Headers param to insert the unique identifier for the request.
      See Also:
    • HEADER_CONTENT_TYPE

      public static final String HEADER_CONTENT_TYPE
      Headers param to insert the conte type.
      See Also:
    • HEADER_AUTHORIZATION

      public static final String HEADER_AUTHORIZATION
      Headers param to insert the token for devops API.
      See Also:
    • HEADER_USER_AGENT

      public static final String HEADER_USER_AGENT
      Headers name to insert the user agent identifying the client.
      See Also:
    • HEADER_REQUESTED_WITH

      public static final String HEADER_REQUESTED_WITH
      Headers param to insert the user agent identifying the client.
      See Also:
    • REQUEST_WITH

      public static final String REQUEST_WITH
      Value for the requested with.
      See Also:
    • httpClient

      protected final HttpClient httpClient
      JDK11 Http client.
    • httpClientOptions

      protected final HttpClientOptions httpClientOptions
      Http Options.
    • retryConfig

      protected final com.evanlennick.retry4j.config.RetryConfig retryConfig
      Default retry configuration.
    • userAgents

      public final Map<String,String> userAgents
      Default settings in Request and Retry
  • Constructor Details

    • RetryHttpClient

      public RetryHttpClient()
      Default initialization of http client.
    • RetryHttpClient

      public RetryHttpClient(HttpClientOptions config)
      Initialize the instance with all items
      Parameters:
      config - configuration of the HTTP CLIENT.
  • Method Details

    • getUserAgentHeader

      public String getUserAgentHeader()
      Give access to the user agent header.
      Returns:
      user agent header
    • getResponseTimeoutInSeconds

      public long getResponseTimeoutInSeconds()
      Return value for default response time.
      Returns:
      default response time
    • post

      public ApiResponseHttp post(String url, String token, String body)
      Helper to build the HTTP request.
      Parameters:
      url - target url
      token - authentication token
      body - request body
      Returns:
      http request
    • builtHttpRequest

      public HttpRequest builtHttpRequest(String method, String url, String token, String body, String contentType)
      Help to build the HTTP request.
      Parameters:
      method - http method name
      url - http url
      token - token for authorization header
      body - body of the request
      contentType - content type for the request
      Returns:
      the http request.
    • parseHttpResponse

      public ApiResponseHttp parseHttpResponse(HttpResponse<String> response)
      Parse HTTP response as a ApiResponseHttp.
      Parameters:
      response - http response from the JDK11 client
      Returns:
      the response as an ApiResponseHttp
    • executeHttp

      public ApiResponseHttp executeHttp(String method, String url, String token, String body, String contentType)
      Main Method executing HTTP Request.
      Parameters:
      method - http method
      url - url
      token - authentication token
      body - request body
      contentType - request content type
      Returns:
      basic request
    • executeHttpRequest

      public com.evanlennick.retry4j.Status<HttpResponse<String>> executeHttpRequest(HttpRequest req)
      Implementing retries.
      Parameters:
      req - current request
      Returns:
      the closeable response