public class ApiClient extends BaseClient
| Constructor and Description |
|---|
ApiClient() |
| Modifier and Type | Method and Description |
|---|---|
ApiClient |
addDefaultHeader(String key,
String value)
Add a default header.
|
ServiceInfo |
addPairAndGetServiceInfo(String path,
List<Pair> queryParams,
Map<String,String> headerParams) |
ApiClient |
addRetryErrorCode(String retryErrorCode) |
ApiClient |
addRetryErrorCodes(Set<String> retryErrorCodes) |
InterceptorContext |
buildCall(String path,
String method,
List<Pair> queryParams,
List<Pair> collectionQueryParams,
Object body,
Map<String,String> headerParams,
Map<String,Object> formParams,
String[] authNames,
ProgressRequestBody.ProgressRequestListener progressRequestListener,
boolean... isCommon)
Build HTTP call with the given options.
|
void |
buildQueryParams(String path,
StringBuilder url,
List<Pair> queryParams) |
com.squareup.okhttp.Request |
buildRequest(String path,
String method,
List<Pair> queryParams,
List<Pair> collectionQueryParams,
Object body,
Map<String,String> headerParams,
Map<String,Object> formParams,
String[] authNames,
ProgressRequestBody.ProgressRequestListener progressRequestListener,
boolean... isCommon)
Build an HTTP request with the given options.
|
com.squareup.okhttp.RequestBody |
buildRequestBodyFormEncoding(Map<String,Object> formParams)
Build a form-encoding request body with the given form parameters.
|
com.squareup.okhttp.RequestBody |
buildRequestBodyMultipart(Map<String,Object> formParams)
Build a multipart (file uploading) request body with the given form parameters,
which could contain text fields and file fields.
|
void |
buildSimpleRequest(Object body,
List<Pair> queryParams,
Map<String,String> headerParams,
StringBuilder builder,
com.squareup.okhttp.FormEncodingBuilder formBuilder,
String chain,
boolean... isCommon) |
String |
buildUrl(String path,
List<Pair> queryParams,
List<Pair> collectionQueryParams)
Build full URL by concatenating base path, the given sub path and query parameters.
|
<T> T |
deserialize(com.squareup.okhttp.Response response,
Type returnType,
boolean... isCommon)
Deserialize response body to Java object, according to the return type and
the Content-Type response header.
|
File |
downloadFileFromResponse(com.squareup.okhttp.Response response)
Download file from the given response.
|
String |
escapeString(String str)
Escape the given string to be used as URL query value.
|
<T> ApiResponse<T> |
execute(com.squareup.okhttp.Call call)
|
<T> ApiResponse<T> |
execute(com.squareup.okhttp.Call call,
Type returnType,
boolean... isCommon)
Execute HTTP call and deserialize the HTTP response body into the given return type.
|
<T> void |
executeAsync(com.squareup.okhttp.Call call,
ApiCallback<T> callback)
|
<T> void |
executeAsync(com.squareup.okhttp.Call call,
Type returnType,
ApiCallback<T> callback)
Execute HTTP call asynchronously.
|
Authentication |
getAuthentication(String authName)
Get authentication for the given name.
|
Map<String,Authentication> |
getAuthentications()
Get authentications (key: authentication name, value: authentication).
|
BackoffStrategy |
getBackoffStrategy() |
int |
getConnectTimeout()
Get connection timeout (in milliseconds).
|
CredentialProvider |
getCredentialProvider() |
Credentials |
getCredentials()
Get credentials
|
Set<String> |
getCustomBootstrapRegion()
Get the custom bootstrapping regions.
|
DateFormat |
getDateFormat() |
void |
getDefaultContentType(Map<String,String> headerParams) |
boolean |
getDisableSSL()
Get disableSSL
|
String |
getEndpoint()
Get base path
|
EndpointResolver |
getEndpointResolver() |
com.squareup.okhttp.OkHttpClient |
getHttpClient()
Get HTTP client
|
String |
getHttpProxy()
Get the http proxy.
|
String |
getHttpsProxy()
Get the https proxy.
|
JSON |
getJSON()
Get JSON
|
Integer |
getKeepAliveDurationMs() |
KeyManager[] |
getKeyManagers() |
Integer |
getMaxIdleConns() |
long |
getMaxRetryDelayMs() |
long |
getMinRetryDelayMs() |
int |
getNumMaxRetries() |
com.squareup.okhttp.OkHttpClient |
getOkHttpClient() |
int |
getReadTimeout()
Get read timeout (in milliseconds).
|
String |
getRegion()
Get region
|
RetryCondition |
getRetryCondition() |
Set<String> |
getRetryErrorCodes() |
InputStream |
getSslCaCert()
Get SSL CA cert.
|
String |
getTempFolderPath()
The path of temporary folder used to store downloaded files from endpoints
with file response.
|
String |
getTruePath(String path,
Map<String,String> headerParams) |
Boolean |
getUseDualStack()
Get the use dual stack flag.
|
int |
getWriteTimeout()
Get write timeout (in milliseconds).
|
String |
guessContentTypeFromFile(File file)
Guess Content-Type header from the given file (defaults to "application/octet-stream").
|
<T> T |
handleResponse(com.squareup.okhttp.Response response,
Type returnType,
boolean... isCommon)
Handle the given response, return the deserialized object when the response is successful.
|
boolean |
isApplicationJsonBody(Map<String,String> headerParams) |
boolean |
isAutoRetry() |
boolean |
isDebugging()
Check that whether debugging is enabled for this API client.
|
boolean |
isJsonMime(String mime)
Check if the given MIME is a JSON MIME.
|
boolean |
isPostBody(Map<String,String> headerParams) |
boolean |
isVerifyingSsl()
True if isVerifyingSsl flag is on
|
List<Pair> |
parameterToPair(String name,
Object value)
Formats the specified query parameter to a list containing a single
Pair object. |
List<Pair> |
parameterToPairs(String collectionFormat,
String name,
Collection value)
Formats the specified collection query parameters to a list of
Pair objects. |
String |
parameterToString(Object param)
Format the given parameter object into string.
|
File |
prepareDownloadFile(com.squareup.okhttp.Response response)
Prepare file for download
|
void |
processDefaultHeader(Map<String,String> headerParams) |
void |
processHeaderParams(Map<String,String> headerParams,
com.squareup.okhttp.Request.Builder reqBuilder)
Set header parameters to the request builder, including default headers.
|
String |
sanitizeFilename(String filename)
Sanitize filename by removing path.
|
String |
selectHeaderAccept(String[] accepts)
Select the Accept header's value from the given accepts array:
if JSON exists in the given array, use it;
otherwise use all of them (joining into a string)
|
String |
selectHeaderContentType(String[] contentTypes)
Select the Content-Type header's value from the given array:
if JSON exists in the given array, use it;
otherwise use the first one of the array.
|
com.squareup.okhttp.RequestBody |
serialize(Object obj,
String contentType)
Serialize the given Java object into request body according to the object's
class and the request Content-Type.
|
ApiClient |
setAutoRetry(boolean autoRetry) |
ApiClient |
setBackoffStrategy(BackoffStrategy backoffStrategy) |
ApiClient |
setConnectTimeout(int connectionTimeout)
Sets the connect timeout (in milliseconds).
|
ApiClient |
setCredentialProvider(CredentialProvider credentialProvider) |
ApiClient |
setCredentials(Credentials credentials)
Set credentials
|
ApiClient |
setCustomBootstrapRegion(Set<String> customBootstrapRegion)
Set the custom bootstrapping regions.
|
ApiClient |
setDateFormat(DateFormat dateFormat) |
ApiClient |
setDebugging(boolean debugging)
Enable/disable debugging for this API client.
|
ApiClient |
setDisableSSL(boolean disableSSL)
Set disableSSL
|
ApiClient |
setEndpoint(String endpoint)
Set base path
|
ApiClient |
setEndpointResolver(EndpointResolver endpointResolver) |
ApiClient |
setHttpClient(com.squareup.okhttp.OkHttpClient httpClient)
Set HTTP client
|
ApiClient |
setHttpProxy(String httpProxy)
Set the http proxy.
|
ApiClient |
setHttpsProxy(String httpsProxy)
Set the https proxy.
|
ApiClient |
setJSON(JSON json)
Set JSON
|
ApiClient |
setKeepAliveDurationMs(Integer keepAliveDurationMs) |
ApiClient |
setKeyManagers(KeyManager[] managers)
Configure client keys to use for authorization in an SSL session.
|
ApiClient |
setLenientOnJson(boolean lenientOnJson) |
ApiClient |
setLocalDateFormat(org.threeten.bp.format.DateTimeFormatter dateFormat) |
ApiClient |
setMaxIdleConns(Integer maxIdleConns) |
ApiClient |
setMaxRetryDelayMs(long maxRetryDelayMs) |
ApiClient |
setMinRetryDelayMs(long minRetryDelayMs) |
ApiClient |
setNumMaxRetries(int numMaxRetries) |
ApiClient |
setOffsetDateTimeFormat(org.threeten.bp.format.DateTimeFormatter dateFormat) |
ApiClient |
setReadTimeout(int readTimeout)
Sets the read timeout (in milliseconds).
|
ApiClient |
setRegion(String region)
Set region
|
ApiClient |
setRetryCondition(RetryCondition retryCondition) |
ApiClient |
setSqlDateFormat(DateFormat dateFormat) |
ApiClient |
setSslCaCert(InputStream sslCaCert)
Configure the CA certificate to be trusted when making https requests.
|
ApiClient |
setTempFolderPath(String tempFolderPath)
Set the temporary folder path (for downloading files)
|
ApiClient |
setUseDualStack(boolean useDualStack)
Set the use dual stack flag.
|
ApiClient |
setUserAgent(String userAgent)
Set the User-Agent header's value (by adding to the default header map).
|
ApiClient |
setVerifyingSsl(boolean verifyingSsl)
Configure whether to verify certificate and hostname when making https requests.
|
ApiClient |
setWriteTimeout(int writeTimeout)
Sets the write timeout (in milliseconds).
|
void |
updateParamsForAuth(String[] authNames,
List<Pair> queryParams,
Map<String,String> headerParams)
Update query and header parameters based on authentication settings.
|
void |
updateParamsForAuth(String[] authNames,
List<Pair> queryParams,
Map<String,String> headerParams,
ServiceInfo serviceInfo,
String payload) |
void |
updateQueryParams(List<Pair> queryParams,
String[] param) |
public ApiClient setUserAgent(String userAgent)
userAgent - HTTP request's user agentpublic String getEndpoint()
public ApiClient setEndpoint(String endpoint)
endpoint - endpoint of the URLpublic boolean getDisableSSL()
public ApiClient setDisableSSL(boolean disableSSL)
disableSSL - public String getRegion()
public ApiClient setRegion(String region)
region - public Credentials getCredentials()
public ApiClient setCredentials(Credentials credentials)
credentials - public com.squareup.okhttp.OkHttpClient getHttpClient()
public ApiClient setHttpClient(com.squareup.okhttp.OkHttpClient httpClient)
httpClient - An instance of OkHttpClientpublic JSON getJSON()
public ApiClient setJSON(JSON json)
json - JSON objectpublic boolean isVerifyingSsl()
public ApiClient setVerifyingSsl(boolean verifyingSsl)
verifyingSsl - True to verify TLS/SSL connectionpublic InputStream getSslCaCert()
public ApiClient setSslCaCert(InputStream sslCaCert)
sslCaCert - input stream for SSL CA certpublic KeyManager[] getKeyManagers()
public ApiClient setKeyManagers(KeyManager[] managers)
managers - The KeyManagers to usepublic DateFormat getDateFormat()
public ApiClient setDateFormat(DateFormat dateFormat)
public ApiClient setSqlDateFormat(DateFormat dateFormat)
public ApiClient setOffsetDateTimeFormat(org.threeten.bp.format.DateTimeFormatter dateFormat)
public ApiClient setLocalDateFormat(org.threeten.bp.format.DateTimeFormatter dateFormat)
public ApiClient setLenientOnJson(boolean lenientOnJson)
public Map<String,Authentication> getAuthentications()
public Authentication getAuthentication(String authName)
authName - The authentication namepublic ApiClient addDefaultHeader(String key, String value)
key - The header's keyvalue - The header's valuepublic boolean isDebugging()
public ApiClient setDebugging(boolean debugging)
debugging - To enable (true) or disable (false) debuggingpublic String getTempFolderPath()
null, i.e. using
the system's default tempopary folder.public ApiClient setTempFolderPath(String tempFolderPath)
tempFolderPath - Temporary folder pathpublic int getConnectTimeout()
public ApiClient setConnectTimeout(int connectionTimeout)
connectionTimeout - connection timeout in millisecondspublic int getReadTimeout()
public ApiClient setReadTimeout(int readTimeout)
Integer.MAX_VALUE.readTimeout - read timeout in millisecondspublic int getWriteTimeout()
public ApiClient setWriteTimeout(int writeTimeout)
Integer.MAX_VALUE.writeTimeout - connection timeout in millisecondspublic Set<String> getCustomBootstrapRegion()
public ApiClient setCustomBootstrapRegion(Set<String> customBootstrapRegion)
customBootstrapRegion - Set of custom bootstrapping regionspublic Boolean getUseDualStack()
public ApiClient setUseDualStack(boolean useDualStack)
useDualStack - booleanpublic String getHttpProxy()
public ApiClient setHttpProxy(String httpProxy)
public String getHttpsProxy()
public ApiClient setHttpsProxy(String httpsProxy)
public String parameterToString(Object param)
param - Parameterpublic List<Pair> parameterToPair(String name, Object value)
Pair object.
Note that value must not be a collection.
name - The name of the parameter.value - The value of the parameter.Pair object.public List<Pair> parameterToPairs(String collectionFormat, String name, Collection value)
Pair objects.
Note that the values of each of the returned Pair objects are percent-encoded.
collectionFormat - The collection format of the parameter.name - The name of the parameter.value - The value of the parameter.Pair objects.public String sanitizeFilename(String filename)
filename - The filename to be sanitizedpublic boolean isJsonMime(String mime)
mime - MIME (Multipurpose Internet Mail Extensions)public String selectHeaderAccept(String[] accepts)
accepts - The accepts array to select frompublic String selectHeaderContentType(String[] contentTypes)
contentTypes - The Content-Type array to select frompublic String escapeString(String str)
str - String to be escapedpublic <T> T deserialize(com.squareup.okhttp.Response response,
Type returnType,
boolean... isCommon)
throws ApiException
T - Typeresponse - HTTP responsereturnType - The type of the Java objectisCommon - The flag for UniversalApiException - If fail to deserialize response body, i.e. cannot read response body
or the Content-Type of the response is not supported.public com.squareup.okhttp.RequestBody serialize(Object obj, String contentType) throws ApiException
obj - The Java objectcontentType - The request Content-TypeApiException - If fail to serialize the given objectpublic File downloadFileFromResponse(com.squareup.okhttp.Response response) throws ApiException
response - An instance of the Response objectApiException - If fail to read file content from response and write to diskpublic File prepareDownloadFile(com.squareup.okhttp.Response response) throws IOException
response - An instance of the Response objectIOException - If fail to prepare file for downloadpublic <T> ApiResponse<T> execute(com.squareup.okhttp.Call call) throws ApiException
T - Typecall - An instance of the Call objectApiException - If fail to execute the callpublic <T> ApiResponse<T> execute(com.squareup.okhttp.Call call, Type returnType, boolean... isCommon) throws ApiException
T - The return type corresponding to (same with) returnTypereturnType - The return type used to deserialize HTTP response bodycall - CallisCommon - The flag for UniversalApiException - If fail to execute the callpublic <T> void executeAsync(com.squareup.okhttp.Call call,
ApiCallback<T> callback)
T - Typecall - An instance of the Call objectcallback - ApiCallback<T>public <T> void executeAsync(com.squareup.okhttp.Call call,
Type returnType,
ApiCallback<T> callback)
T - Typecall - The callback to be executed when the API call finishesreturnType - Return typecallback - ApiCallbackexecute(Call, Type, boolean...)public <T> T handleResponse(com.squareup.okhttp.Response response,
Type returnType,
boolean... isCommon)
throws ApiException
T - Typeresponse - ResponsereturnType - Return typeisCommon - The flag for UniversalApiException - If the response has a unsuccessful status code or
fail to deserialize the response bodypublic InterceptorContext buildCall(String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, Object body, Map<String,String> headerParams, Map<String,Object> formParams, String[] authNames, ProgressRequestBody.ProgressRequestListener progressRequestListener, boolean... isCommon) throws ApiException
buildCall in class BaseClientpath - The sub-path of the HTTP URLmethod - The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE"queryParams - The query parameterscollectionQueryParams - The collection query parametersbody - The request body objectheaderParams - The header parametersformParams - The form parametersauthNames - The authentications to applyprogressRequestListener - Progress request listenerisCommon - The flag for UniversalApiException - If fail to serialize the request body objectpublic ServiceInfo addPairAndGetServiceInfo(String path, List<Pair> queryParams, Map<String,String> headerParams)
public void buildSimpleRequest(Object body, List<Pair> queryParams, Map<String,String> headerParams, StringBuilder builder, com.squareup.okhttp.FormEncodingBuilder formBuilder, String chain, boolean... isCommon) throws Exception
Exceptionpublic com.squareup.okhttp.Request buildRequest(String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, Object body, Map<String,String> headerParams, Map<String,Object> formParams, String[] authNames, ProgressRequestBody.ProgressRequestListener progressRequestListener, boolean... isCommon) throws ApiException
path - The sub-path of the HTTP URLmethod - The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE"queryParams - The query parameterscollectionQueryParams - The collection query parametersbody - The request body objectheaderParams - The header parametersformParams - The form parametersauthNames - The authentications to applyprogressRequestListener - Progress request listenerisCommon - The flag for UniversalApiException - If fail to serialize the request body objectpublic String buildUrl(String path, List<Pair> queryParams, List<Pair> collectionQueryParams)
path - The sub pathqueryParams - The query parameterscollectionQueryParams - The collection query parameterspublic void buildQueryParams(String path, StringBuilder url, List<Pair> queryParams)
public void processHeaderParams(Map<String,String> headerParams, com.squareup.okhttp.Request.Builder reqBuilder)
headerParams - Header parameters in the ofrm of MapreqBuilder - Reqeust.Builderpublic void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String,String> headerParams)
authNames - The authentications to applyqueryParams - List of query parametersheaderParams - Map of header parameterspublic void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String,String> headerParams, ServiceInfo serviceInfo, String payload)
public com.squareup.okhttp.RequestBody buildRequestBodyFormEncoding(Map<String,Object> formParams)
formParams - Form parameters in the form of Mappublic com.squareup.okhttp.RequestBody buildRequestBodyMultipart(Map<String,Object> formParams)
formParams - Form parameters in the form of Mappublic String guessContentTypeFromFile(File file)
file - The given filepublic CredentialProvider getCredentialProvider()
public ApiClient setCredentialProvider(CredentialProvider credentialProvider)
public EndpointResolver getEndpointResolver()
public ApiClient setEndpointResolver(EndpointResolver endpointResolver)
public Integer getMaxIdleConns()
public Integer getKeepAliveDurationMs()
public boolean isAutoRetry()
public ApiClient setAutoRetry(boolean autoRetry)
public int getNumMaxRetries()
public ApiClient setNumMaxRetries(int numMaxRetries)
public long getMinRetryDelayMs()
public ApiClient setMinRetryDelayMs(long minRetryDelayMs)
public long getMaxRetryDelayMs()
public ApiClient setMaxRetryDelayMs(long maxRetryDelayMs)
public RetryCondition getRetryCondition()
public ApiClient setRetryCondition(RetryCondition retryCondition) throws ApiException
ApiExceptionpublic BackoffStrategy getBackoffStrategy()
public ApiClient setBackoffStrategy(BackoffStrategy backoffStrategy) throws ApiException
ApiExceptionpublic com.squareup.okhttp.OkHttpClient getOkHttpClient()
getOkHttpClient in class BaseClientCopyright © 2025. All rights reserved.