Class RetryHttpClient

java.lang.Object
io.stargate.sdk.http.RetryHttpClient
All Implemented Interfaces:
ApiConstants

public class RetryHttpClient extends Object implements ApiConstants
Wrapping the HttpClient and provide helpers
Author:
Cedrick LUNVEN (@clunven)
  • Field Details

    • DEFAULT_TIMEOUT_REQUEST

      public static final int DEFAULT_TIMEOUT_REQUEST
      Default settings in Request and Retry
      See Also:
    • DEFAULT_TIMEOUT_CONNECT

      public static final int DEFAULT_TIMEOUT_CONNECT
      Default settings in Request and Retry
      See Also:
    • DEFAULT_RETRY_COUNT

      public static final int DEFAULT_RETRY_COUNT
      Default settings in Request and Retry
      See Also:
    • DEFAULT_RETRY_DELAY

      public static final Duration DEFAULT_RETRY_DELAY
      Default settings in Request and Retry
    • userAgents

      public static LinkedHashMap<String,String> userAgents
      Default settings in Request and Retry
    • httpClient

      protected org.apache.hc.client5.http.impl.classic.CloseableHttpClient httpClient
      HttpComponent5.
    • apiInvocationsObserversMap

      protected static Map<String,ServiceCallObserver<?,?,?>> apiInvocationsObserversMap
      Observers.
    • requestConfig

      protected static org.apache.hc.client5.http.config.RequestConfig requestConfig
      Default request configuration.
    • retryConfig

      protected static com.evanlennick.retry4j.config.RetryConfig retryConfig
      Default retry configuration.
  • Method Details

    • withRetryConfig

      public static void withRetryConfig(com.evanlennick.retry4j.config.RetryConfig conf)
      Update Retry configuration of the HTTPClient.
      Parameters:
      conf - retryConfiguration
    • withRequestConfig

      public static void withRequestConfig(org.apache.hc.client5.http.config.RequestConfig conf)
      Update RequestConfig configuration of the HTTPClient.
      Parameters:
      conf - RequestConfig
    • registerListener

      public static void registerListener(String name, ServiceCallObserver<?,?,?> listener)
      Register a new listener.
      Parameters:
      name - current name
      listener - current listener
    • getInstance

      public static RetryHttpClient getInstance()
      Singleton Pattern.
      Returns:
      singleton for the class
    • pushUserAgent

      public void pushUserAgent(String component, String version)
      Add an item to the user agent chain.
      Parameters:
      component - component
      version - version number
    • getUserAgentHeader

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

      public ApiResponseHttp GET(ServiceHttp sHttp, String url, String token)
      Helper to build the HTTP request.
      Parameters:
      sHttp - service http
      url - target url
      token - authentication token
      Returns:
      http request
    • HEAD

      public ApiResponseHttp HEAD(ServiceHttp sHttp, String url, String token)
      Helper to build the HTTP request.
      Parameters:
      sHttp - service http
      url - target url
      token - authentication token
      Returns:
      http request
    • POST

      public ApiResponseHttp POST(ServiceHttp sHttp, String url, String token)
      Helper to build the HTTP request.
      Parameters:
      sHttp - service http
      url - target url
      token - authentication token
      Returns:
      http request
    • POST

      public ApiResponseHttp POST(ServiceHttp sHttp, String url, String token, String body)
      Helper to build the HTTP request.
      Parameters:
      sHttp - service http
      url - target url
      token - authentication token
      body - request body
      Returns:
      http request
    • POST_GRAPHQL

      public ApiResponseHttp POST_GRAPHQL(ServiceHttp sHttp, String url, String token, String body)
      Helper to build the HTTP request.
      Parameters:
      sHttp - service http
      url - target url
      token - authentication token
      body - request body
      Returns:
      http request
    • DELETE

      public ApiResponseHttp DELETE(ServiceHttp sHttp, String url, String token)
      Helper to build the HTTP request.
      Parameters:
      sHttp - service http
      url - target url
      token - authentication token
      Returns:
      http request
    • PUT

      public ApiResponseHttp PUT(ServiceHttp sHttp, String url, String token, String body)
      Helper to build the HTTP request.
      Parameters:
      sHttp - service http
      url - target url
      token - authentication token
      body - request body
      Returns:
      http request
    • PATCH

      public ApiResponseHttp PATCH(ServiceHttp sHttp, String url, String token, String body)
      Helper to build the HTTP request.
      Parameters:
      sHttp - service http
      url - target url
      token - authentication token
      body - request body
      Returns:
      http request
    • executeHttp

      public ApiResponseHttp executeHttp(ServiceHttp sHttp, org.apache.hc.core5.http.Method method, String url, String token, String reqBody, String contentType, boolean mandatory)
      Main Method executing HTTP Request.
      Parameters:
      sHttp - service http
      method - http method
      url - url
      token - authentication token
      reqBody - request body
      contentType - request content type
      mandatory - allow 404 errors
      Returns:
      basic request
    • executeHttp

      public ApiResponseHttp executeHttp(ServiceHttp sHttp, org.apache.hc.client5.http.classic.methods.HttpUriRequestBase req, boolean mandatory)
      Execute a request coming from elsewhere.
      Parameters:
      sHttp - service http
      req - current request
      mandatory - mandatory
      Returns:
      api response
    • getRequestConfig

      public static org.apache.hc.client5.http.config.RequestConfig getRequestConfig()
      Getter accessor for attribute 'requestConfig'.
      Returns:
      current value of 'requestConfig'
    • getRetryConfig

      public static com.evanlennick.retry4j.config.RetryConfig getRetryConfig()
      Getter accessor for attribute 'retryConfig'.
      Returns:
      current value of 'retryConfig'