public class ApiClient extends Object
Constructor and Description |
---|
ApiClient() |
Modifier and Type | Method and Description |
---|---|
ApiClient |
addDefaultHeader(String key,
String value)
Add a default header.
|
<T> T |
deserialize(jakarta.ws.rs.core.Response response,
jakarta.ws.rs.core.GenericType<T> returnType)
Deserialize response body to Java object according to the Content-Type.
|
File |
downloadFileFromResponse(jakarta.ws.rs.core.Response response)
Download file from the given response.
|
String |
escapeString(String str)
Escape the given string to be used as URL query value.
|
String |
formatDate(Date date)
Format the given Date object into string.
|
Authentication |
getAuthentication(String authName)
Get authentication for the given name.
|
Map<String,Authentication> |
getAuthentications()
Get authentications (key: authentication name, value: authentication).
|
String |
getBasePath() |
org.apache.http.pool.PoolStats |
getConnectionStats()
Get the connection pool statistics, only if maxConnections is set.
|
int |
getConnectTimeout()
Connect timeout (in milliseconds).
|
DateFormat |
getDateFormat()
Get the date format used to parse/format date parameters.
|
jakarta.ws.rs.client.Client |
getHttpClient() |
JSON |
getJSON()
Gets the JSON instance to do JSON serialization and deserialization.
|
long |
getKeepAliveDuration()
Custom connection keep alive duration in milliseconds.
|
int |
getMaxConnections()
Maximum http pooled connections to endpoint.
|
Map<String,List<String>> |
getResponseHeaders()
Gets the response headers of the previous request
|
int |
getStatusCode()
Gets the status code of the previous request
|
String |
getTempFolderPath()
The path of temporary folder used to store downloaded files from endpoints
with file response.
|
void |
graceFullShutdown() |
<T> T |
invokeAPI(String path,
String method,
List<Pair> queryParams,
Object body,
Map<String,String> headerParams,
Map<String,Object> formParams,
String accept,
String contentType,
String[] authNames,
jakarta.ws.rs.core.GenericType<T> returnType)
Invoke API by sending HTTP request with the given options.
|
com.fortanix.sdkms.v1.ApiClient.ResponseWithMetadata |
invokeAPIWithEndpoint(String endpoint,
String path,
jakarta.ws.rs.client.Entity entity,
String method,
List<Pair> queryParams,
Object body,
Map<String,String> headerParams,
Map<String,Object> formParams,
String accept,
String contentType,
String[] authNames)
Invoke API by sending HTTP request to a given endpoint with the given
options.
|
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.
|
List<Pair> |
parameterToPairs(String collectionFormat,
String name,
Object value) |
String |
parameterToString(Object param)
Format the given parameter object into string.
|
Date |
parseDate(String str)
Parse the given string into Date object.
|
File |
prepareDownloadFile(jakarta.ws.rs.core.Response response) |
<T> T |
processResponse(com.fortanix.sdkms.v1.ApiClient.ResponseWithMetadata responseWithMetadata,
jakarta.ws.rs.core.GenericType<T> returnType)
Deserialize the HTTP response to the provided type,
also closes the HTTP response at the end of the function
|
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.
|
jakarta.ws.rs.client.Entity<?> |
serialize(Object obj,
Map<String,Object> formParams,
String contentType)
Serialize the given Java object into string entity according the given
Content-Type (only JSON is supported for now).
|
void |
setAccessToken(String accessToken)
Helper method to set access token for the first OAuth2 authentication.
|
void |
setApiKey(String apiKey)
Helper method to set API key value for the first API key authentication.
|
void |
setApiKeyPrefix(String apiKeyPrefix)
Helper method to set API key prefix for the first API key authentication.
|
ApiClient |
setBasePath(String basePath) |
void |
setBasicAuthString(String authString)
Helper method to set username:password pair for the first HTTP basic authentication.
|
ApiClient |
setClientSideFailoverEnabled(boolean isEnabled) |
ApiClient |
setConnectTimeout(int connectionTimeout)
Set the connect timeout (in milliseconds).
|
ApiClient |
setDateFormat(DateFormat dateFormat)
Set the date format used to parse/format date parameters.
|
ApiClient |
setDebugging(boolean debugging)
Enable/disable debugging for this API client.
|
ApiClient |
setEndpointHealthCheckInterval(int milliseconds) |
ApiClient |
setHostsResolutionStrategy(HostsResolutionStrategy resolutionStrategy) |
ApiClient |
setHttpClient(jakarta.ws.rs.client.Client httpClient) |
ApiClient |
setKeepAliveDuration(long keepAliveDuration)
Set the connection keep alive duration.
|
ApiClient |
setMaxConnections(int maxConnections)
Set the maximum http pooled connections to endpoint.
|
ApiClient |
setMaxRequestRetries(int numRetries) |
void |
setPassword(String password)
Helper method to set password for the first HTTP basic authentication.
|
ApiClient |
setRequestRetryInterval(int milliseconds) |
ApiClient |
setTempFolderPath(String tempFolderPath)
Set temp folder path
|
ApiClient |
setUserAgent(String userAgent)
Set the User-Agent header's value (by adding to the default header map).
|
void |
setUsername(String username)
Helper method to set username for the first HTTP basic authentication.
|
void |
shutdownExecutor(ExecutorService executor) |
public JSON getJSON()
public jakarta.ws.rs.client.Client getHttpClient()
public ApiClient setHttpClient(jakarta.ws.rs.client.Client httpClient)
public String getBasePath()
public int getStatusCode()
public Map<String,List<String>> getResponseHeaders()
public Map<String,Authentication> getAuthentications()
public Authentication getAuthentication(String authName)
authName
- The authentication namepublic void setUsername(String username)
username
- Usernamepublic void setPassword(String password)
password
- Passwordpublic void setBasicAuthString(String authString)
authString
- Base-64 encoding of username:passwordpublic void setApiKey(String apiKey)
apiKey
- API keypublic void setApiKeyPrefix(String apiKeyPrefix)
apiKeyPrefix
- API key prefixpublic void setAccessToken(String accessToken)
accessToken
- Access tokenpublic ApiClient setUserAgent(String userAgent)
userAgent
- Http user agentpublic 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
- Temp folder pathpublic int getConnectTimeout()
public ApiClient setConnectTimeout(int connectionTimeout)
Integer.MAX_VALUE
.connectionTimeout
- Connection timeout in millisecondspublic long getKeepAliveDuration()
public ApiClient setKeepAliveDuration(long keepAliveDuration)
keepAliveDuration
- Keep-alive duration in milliseconspublic int getMaxConnections()
public ApiClient setMaxConnections(int maxConnections)
maxConnections
- Maximum http pooled connectionspublic ApiClient setRequestRetryInterval(int milliseconds)
public ApiClient setMaxRequestRetries(int numRetries)
public ApiClient setClientSideFailoverEnabled(boolean isEnabled)
public ApiClient setHostsResolutionStrategy(HostsResolutionStrategy resolutionStrategy)
public ApiClient setEndpointHealthCheckInterval(int milliseconds)
public org.apache.http.pool.PoolStats getConnectionStats()
public DateFormat getDateFormat()
public ApiClient setDateFormat(DateFormat dateFormat)
dateFormat
- Date formatpublic Date parseDate(String str)
str
- Stringpublic String formatDate(Date date)
date
- Datepublic String parameterToString(Object param)
param
- Objectpublic List<Pair> parameterToPairs(String collectionFormat, String name, Object value)
public boolean isJsonMime(String mime)
mime
- MIMEpublic 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
- Stringpublic jakarta.ws.rs.client.Entity<?> serialize(Object obj, Map<String,Object> formParams, String contentType) throws ApiException
obj
- ObjectformParams
- Form parameterscontentType
- Context typeApiException
- API exceptionpublic <T> T deserialize(jakarta.ws.rs.core.Response response, jakarta.ws.rs.core.GenericType<T> returnType) throws ApiException
T
- Typeresponse
- ResponsereturnType
- Return typeApiException
- API exceptionpublic File downloadFileFromResponse(jakarta.ws.rs.core.Response response) throws ApiException
response
- ResponseApiException
- If fail to read file content from response and write to diskpublic File prepareDownloadFile(jakarta.ws.rs.core.Response response) throws IOException
IOException
public com.fortanix.sdkms.v1.ApiClient.ResponseWithMetadata invokeAPIWithEndpoint(String endpoint, String path, jakarta.ws.rs.client.Entity entity, String method, List<Pair> queryParams, Object body, Map<String,String> headerParams, Map<String,Object> formParams, String accept, String contentType, String[] authNames)
endpoint
- The endpoint to which the request has to be made.path
- The sub-path of the HTTP URLmethod
- The request method, one of "GET", "POST", "PUT", and
"DELETE"queryParams
- The query parametersbody
- The request body objectheaderParams
- The header parametersformParams
- The form parametersaccept
- The request's Accept headercontentType
- The request's Content-Type headerauthNames
- The authentications to applypublic <T> T processResponse(com.fortanix.sdkms.v1.ApiClient.ResponseWithMetadata responseWithMetadata, jakarta.ws.rs.core.GenericType<T> returnType)
T
- TyperesponseWithMetadata
- The data structure that contains the HTTP
response along with some other metadata essential
for loggingreturnType
- The return type into which to deserialize the
responsepublic <T> T invokeAPI(String path, String method, List<Pair> queryParams, Object body, Map<String,String> headerParams, Map<String,Object> formParams, String accept, String contentType, String[] authNames, jakarta.ws.rs.core.GenericType<T> returnType) throws ApiException
T
- Typepath
- The sub-path of the HTTP URLmethod
- The request method, one of "GET", "POST", "PUT", and
"DELETE"queryParams
- The query parametersbody
- The request body objectheaderParams
- The header parametersformParams
- The form parametersaccept
- The request's Accept headercontentType
- The request's Content-Type headerauthNames
- The authentications to applyreturnType
- The return type into which to deserialize the responseApiException
- API exceptionpublic void shutdownExecutor(ExecutorService executor)
public void graceFullShutdown()
Copyright © 2017-2025 Fortanix Inc. All Rights Reserved