Package io.stargate.sdk.http
Class RetryHttpClient
java.lang.Object
io.stargate.sdk.http.RetryHttpClient
- All Implemented Interfaces:
ApiConstants
Wrapping the HttpClient and provide helpers
- Author:
- Cedrick LUNVEN (@clunven)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static Map<String, ServiceCallObserver<?, ?, ?>> Observers.static final intDefault settings in Request and Retrystatic final DurationDefault settings in Request and Retrystatic final intDefault settings in Request and Retrystatic final intDefault settings in Request and Retryprotected org.apache.hc.client5.http.impl.classic.CloseableHttpClientHttpComponent5.protected static org.apache.hc.client5.http.config.RequestConfigDefault request configuration.protected static com.evanlennick.retry4j.config.RetryConfigDefault retry configuration.static LinkedHashMap<String, String> Default settings in Request and RetryFields inherited from interface io.stargate.sdk.api.ApiConstants
CONTENT_TYPE_GRAPHQL, CONTENT_TYPE_JSON, HEADER_ACCEPT, HEADER_AUTHORIZATION, HEADER_CASSANDRA, HEADER_CONTENT_TYPE, HEADER_REQUEST_ID, HEADER_REQUESTED_WITH, HEADER_USER_AGENT, REQUEST_WITH -
Method Summary
Modifier and TypeMethodDescriptionDELETE(ServiceHttp sHttp, String url, String token) Helper to build the HTTP request.executeHttp(ServiceHttp sHttp, org.apache.hc.client5.http.classic.methods.HttpUriRequestBase req, boolean mandatory) Execute a request coming from elsewhere.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.GET(ServiceHttp sHttp, String url, String token) Helper to build the HTTP request.static RetryHttpClientSingleton Pattern.static org.apache.hc.client5.http.config.RequestConfigGetter accessor for attribute 'requestConfig'.static com.evanlennick.retry4j.config.RetryConfigGetter accessor for attribute 'retryConfig'.Give access to the user agent header.HEAD(ServiceHttp sHttp, String url, String token) Helper to build the HTTP request.PATCH(ServiceHttp sHttp, String url, String token, String body) Helper to build the HTTP request.POST(ServiceHttp sHttp, String url, String token) Helper to build the HTTP request.POST(ServiceHttp sHttp, String url, String token, String body) Helper to build the HTTP request.POST_GRAPHQL(ServiceHttp sHttp, String url, String token, String body) Helper to build the HTTP request.voidpushUserAgent(String component, String version) Add an item to the user agent chain.PUT(ServiceHttp sHttp, String url, String token, String body) Helper to build the HTTP request.static voidregisterListener(String name, ServiceCallObserver<?, ?, ?> listener) Register a new listener.static voidwithRequestConfig(org.apache.hc.client5.http.config.RequestConfig conf) Update RequestConfig configuration of the HTTPClient.static voidwithRetryConfig(com.evanlennick.retry4j.config.RetryConfig conf) Update Retry configuration of the HTTPClient.
-
Field Details
-
DEFAULT_TIMEOUT_REQUEST
public static final int DEFAULT_TIMEOUT_REQUESTDefault settings in Request and Retry- See Also:
-
DEFAULT_TIMEOUT_CONNECT
public static final int DEFAULT_TIMEOUT_CONNECTDefault settings in Request and Retry- See Also:
-
DEFAULT_RETRY_COUNT
public static final int DEFAULT_RETRY_COUNTDefault settings in Request and Retry- See Also:
-
DEFAULT_RETRY_DELAY
Default settings in Request and Retry -
userAgents
Default settings in Request and Retry -
httpClient
protected org.apache.hc.client5.http.impl.classic.CloseableHttpClient httpClientHttpComponent5. -
apiInvocationsObserversMap
Observers. -
requestConfig
protected static org.apache.hc.client5.http.config.RequestConfig requestConfigDefault request configuration. -
retryConfig
protected static com.evanlennick.retry4j.config.RetryConfig retryConfigDefault 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
Register a new listener.- Parameters:
name- current namelistener- current listener
-
getInstance
Singleton Pattern.- Returns:
- singleton for the class
-
pushUserAgent
Add an item to the user agent chain.- Parameters:
component- componentversion- version number
-
getUserAgentHeader
Give access to the user agent header.- Returns:
- user agent header
-
GET
Helper to build the HTTP request.- Parameters:
sHttp- service httpurl- target urltoken- authentication token- Returns:
- http request
-
HEAD
Helper to build the HTTP request.- Parameters:
sHttp- service httpurl- target urltoken- authentication token- Returns:
- http request
-
POST
Helper to build the HTTP request.- Parameters:
sHttp- service httpurl- target urltoken- authentication token- Returns:
- http request
-
POST
Helper to build the HTTP request.- Parameters:
sHttp- service httpurl- target urltoken- authentication tokenbody- request body- Returns:
- http request
-
POST_GRAPHQL
Helper to build the HTTP request.- Parameters:
sHttp- service httpurl- target urltoken- authentication tokenbody- request body- Returns:
- http request
-
DELETE
Helper to build the HTTP request.- Parameters:
sHttp- service httpurl- target urltoken- authentication token- Returns:
- http request
-
PUT
Helper to build the HTTP request.- Parameters:
sHttp- service httpurl- target urltoken- authentication tokenbody- request body- Returns:
- http request
-
PATCH
Helper to build the HTTP request.- Parameters:
sHttp- service httpurl- target urltoken- authentication tokenbody- 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 httpmethod- http methodurl- urltoken- authentication tokenreqBody- request bodycontentType- request content typemandatory- 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 httpreq- current requestmandatory- 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'
-