public class ApiClient
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.Integer |
serverIndex |
protected java.util.List<ServerConfiguration> |
servers |
protected java.util.Map<java.lang.String,java.lang.String> |
serverVariables |
| Constructor and Description |
|---|
ApiClient()
Basic constructor for ApiClient
|
ApiClient(okhttp3.OkHttpClient client)
Basic constructor with custom OkHttpClient
|
| Modifier and Type | Method and Description |
|---|---|
ApiClient |
addDefaultCookie(java.lang.String key,
java.lang.String value)
Add a default cookie.
|
ApiClient |
addDefaultHeader(java.lang.String key,
java.lang.String value)
Add a default header.
|
okhttp3.Call |
buildCall(java.lang.String baseUrl,
java.lang.String path,
java.lang.String method,
java.util.List<Pair> queryParams,
java.util.List<Pair> collectionQueryParams,
java.lang.Object body,
java.util.Map<java.lang.String,java.lang.String> headerParams,
java.util.Map<java.lang.String,java.lang.String> cookieParams,
java.util.Map<java.lang.String,java.lang.Object> formParams,
java.lang.String[] authNames,
ApiCallback callback)
Build HTTP call with the given options.
|
okhttp3.Request |
buildRequest(java.lang.String baseUrl,
java.lang.String path,
java.lang.String method,
java.util.List<Pair> queryParams,
java.util.List<Pair> collectionQueryParams,
java.lang.Object body,
java.util.Map<java.lang.String,java.lang.String> headerParams,
java.util.Map<java.lang.String,java.lang.String> cookieParams,
java.util.Map<java.lang.String,java.lang.Object> formParams,
java.lang.String[] authNames,
ApiCallback callback)
Build an HTTP request with the given options.
|
okhttp3.RequestBody |
buildRequestBodyFormEncoding(java.util.Map<java.lang.String,java.lang.Object> formParams)
Build a form-encoding request body with the given form parameters.
|
okhttp3.RequestBody |
buildRequestBodyMultipart(java.util.Map<java.lang.String,java.lang.Object> formParams)
Build a multipart (file uploading) request body with the given form parameters, which could
contain text fields and file fields.
|
java.lang.String |
buildUrl(java.lang.String baseUrl,
java.lang.String path,
java.util.List<Pair> queryParams,
java.util.List<Pair> collectionQueryParams)
Build full URL by concatenating base path, the given sub path and query parameters.
|
java.lang.String |
collectionPathParameterToString(java.lang.String collectionFormat,
java.util.Collection value)
Formats the specified collection path parameter to a string value.
|
<T> T |
deserialize(okhttp3.Response response,
java.lang.reflect.Type returnType)
Deserialize response body to Java object, according to the return type and the Content-Type
response header.
|
java.io.File |
downloadFileFromResponse(okhttp3.Response response)
Download file from the given response.
|
java.lang.String |
escapeString(java.lang.String str)
Escape the given string to be used as URL query value.
|
<T> ApiResponse<T> |
execute(okhttp3.Call call)
|
<T> ApiResponse<T> |
execute(okhttp3.Call call,
java.lang.reflect.Type returnType)
Execute HTTP call and deserialize the HTTP response body into the given return type.
|
<T> void |
executeAsync(okhttp3.Call call,
ApiCallback<T> callback)
|
<T> void |
executeAsync(okhttp3.Call call,
java.lang.reflect.Type returnType,
ApiCallback<T> callback)
Execute HTTP call asynchronously.
|
java.util.List<Pair> |
freeFormParameterToPairs(java.lang.Object value)
Formats the specified free-form query parameters to a list of
Pair objects. |
Authentication |
getAuthentication(java.lang.String authName)
Get authentication for the given name.
|
java.util.Map<java.lang.String,Authentication> |
getAuthentications()
Get authentications (key: authentication name, value: authentication).
|
java.lang.String |
getBasePath()
Get base path
|
int |
getConnectTimeout()
Get connection timeout (in milliseconds).
|
java.text.DateFormat |
getDateFormat()
Getter for the field
dateFormat. |
okhttp3.OkHttpClient |
getHttpClient()
Get HTTP client
|
JSON |
getJSON()
Get JSON
|
javax.net.ssl.KeyManager[] |
getKeyManagers()
Getter for the field
keyManagers. |
int |
getReadTimeout()
Get read timeout (in milliseconds).
|
java.lang.Integer |
getServerIndex() |
java.util.List<ServerConfiguration> |
getServers() |
java.util.Map<java.lang.String,java.lang.String> |
getServerVariables() |
java.io.InputStream |
getSslCaCert()
Get SSL CA cert.
|
java.lang.String |
getTempFolderPath()
The path of temporary folder used to store downloaded files from endpoints with file response.
|
int |
getWriteTimeout()
Get write timeout (in milliseconds).
|
java.lang.String |
guessContentTypeFromFile(java.io.File file)
Guess Content-Type header from the given file (defaults to "application/octet-stream").
|
<T> T |
handleResponse(okhttp3.Response response,
java.lang.reflect.Type returnType)
Handle the given response, return the deserialized object when the response is successful.
|
boolean |
isDebugging()
Check that whether debugging is enabled for this API client.
|
boolean |
isJsonMime(java.lang.String mime)
Check if the given MIME is a JSON MIME.
|
boolean |
isVerifyingSsl()
True if isVerifyingSsl flag is on
|
java.util.List<Pair> |
parameterToPair(java.lang.String name,
java.lang.Object value)
Formats the specified query parameter to a list containing a single
Pair object. |
java.util.List<Pair> |
parameterToPairs(java.lang.String collectionFormat,
java.lang.String name,
java.util.Collection value)
Formats the specified collection query parameters to a list of
Pair objects. |
java.lang.String |
parameterToString(java.lang.Object param)
Format the given parameter object into string.
|
java.io.File |
prepareDownloadFile(okhttp3.Response response)
Prepare file for download
|
void |
processCookieParams(java.util.Map<java.lang.String,java.lang.String> cookieParams,
okhttp3.Request.Builder reqBuilder)
Set cookie parameters to the request builder, including default cookies.
|
void |
processHeaderParams(java.util.Map<java.lang.String,java.lang.String> headerParams,
okhttp3.Request.Builder reqBuilder)
Set header parameters to the request builder, including default headers.
|
java.lang.String |
sanitizeFilename(java.lang.String filename)
Sanitize filename by removing path.
|
java.lang.String |
selectHeaderAccept(java.lang.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)
|
java.lang.String |
selectHeaderContentType(java.lang.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.
|
okhttp3.RequestBody |
serialize(java.lang.Object obj,
java.lang.String contentType)
Serialize the given Java object into request body according to the object's class and the
request Content-Type.
|
void |
setAccessToken(java.lang.String accessToken)
Helper method to set access token for the first OAuth2 authentication.
|
void |
setAWS4Configuration(java.lang.String accessKey,
java.lang.String secretKey,
java.lang.String region,
java.lang.String service)
Helper method to set credentials for AWSV4 Signature
|
ApiClient |
setBasePath(java.lang.String basePath)
Set base path
|
ApiClient |
setConnectTimeout(int connectionTimeout)
Sets the connect timeout (in milliseconds).
|
ApiClient |
setDateFormat(java.text.DateFormat dateFormat)
Setter for the field
dateFormat. |
ApiClient |
setDebugging(boolean debugging)
Enable/disable debugging for this API client.
|
ApiClient |
setHttpClient(okhttp3.OkHttpClient newHttpClient)
Set HTTP client, which must never be null.
|
ApiClient |
setJSON(JSON json)
Set JSON
|
ApiClient |
setKeyManagers(javax.net.ssl.KeyManager[] managers)
Configure client keys to use for authorization in an SSL session.
|
ApiClient |
setLenientOnJson(boolean lenientOnJson)
Set LenientOnJson.
|
ApiClient |
setLocalDateFormat(java.time.format.DateTimeFormatter dateFormat)
Set LocalDateFormat.
|
ApiClient |
setOffsetDateTimeFormat(java.time.format.DateTimeFormatter dateFormat)
Set OffsetDateTimeFormat.
|
ApiClient |
setReadTimeout(int readTimeout)
Sets the read timeout (in milliseconds).
|
ApiClient |
setServerIndex(java.lang.Integer serverIndex) |
ApiClient |
setServers(java.util.List<ServerConfiguration> servers) |
ApiClient |
setServerVariables(java.util.Map<java.lang.String,java.lang.String> serverVariables) |
ApiClient |
setSqlDateFormat(java.text.DateFormat dateFormat)
Set SqlDateFormat.
|
ApiClient |
setSslCaCert(java.io.InputStream sslCaCert)
Configure the CA certificate to be trusted when making https requests.
|
ApiClient |
setTempFolderPath(java.lang.String tempFolderPath)
Set the temporary folder path (for downloading files)
|
ApiClient |
setUserAgent(java.lang.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(java.lang.String[] authNames,
java.util.List<Pair> queryParams,
java.util.Map<java.lang.String,java.lang.String> headerParams,
java.util.Map<java.lang.String,java.lang.String> cookieParams,
java.lang.String payload,
java.lang.String method,
java.net.URI uri)
Update query and header parameters based on authentication settings.
|
protected java.util.List<ServerConfiguration> servers
protected java.lang.Integer serverIndex
protected java.util.Map<java.lang.String,java.lang.String> serverVariables
public ApiClient()
public ApiClient(okhttp3.OkHttpClient client)
client - a OkHttpClient objectpublic java.lang.String getBasePath()
public ApiClient setBasePath(java.lang.String basePath)
basePath - Base path of the URL (e.g https://api-v2.fattureincloud.itpublic java.util.List<ServerConfiguration> getServers()
public ApiClient setServers(java.util.List<ServerConfiguration> servers)
public java.lang.Integer getServerIndex()
public ApiClient setServerIndex(java.lang.Integer serverIndex)
public java.util.Map<java.lang.String,java.lang.String> getServerVariables()
public ApiClient setServerVariables(java.util.Map<java.lang.String,java.lang.String> serverVariables)
public okhttp3.OkHttpClient getHttpClient()
public ApiClient setHttpClient(okhttp3.OkHttpClient newHttpClient)
newHttpClient - An instance of OkHttpClientjava.lang.NullPointerException - when newHttpClient is nullpublic JSON getJSON()
public ApiClient setJSON(JSON json)
json - JSON objectpublic boolean isVerifyingSsl()
public ApiClient setVerifyingSsl(boolean verifyingSsl)
verifyingSsl - True to verify TLS/SSL connectionpublic java.io.InputStream getSslCaCert()
public ApiClient setSslCaCert(java.io.InputStream sslCaCert)
sslCaCert - input stream for SSL CA certpublic javax.net.ssl.KeyManager[] getKeyManagers()
keyManagers.KeyManager objectspublic ApiClient setKeyManagers(javax.net.ssl.KeyManager[] managers)
managers - The KeyManagers to usepublic java.text.DateFormat getDateFormat()
dateFormat.DateFormat objectpublic ApiClient setDateFormat(java.text.DateFormat dateFormat)
dateFormat.dateFormat - a DateFormat objectApiClient objectpublic ApiClient setSqlDateFormat(java.text.DateFormat dateFormat)
dateFormat - a DateFormat objectApiClient objectpublic ApiClient setOffsetDateTimeFormat(java.time.format.DateTimeFormatter dateFormat)
dateFormat - a DateTimeFormatter objectApiClient objectpublic ApiClient setLocalDateFormat(java.time.format.DateTimeFormatter dateFormat)
dateFormat - a DateTimeFormatter objectApiClient objectpublic ApiClient setLenientOnJson(boolean lenientOnJson)
lenientOnJson - a booleanApiClient objectpublic java.util.Map<java.lang.String,Authentication> getAuthentications()
public Authentication getAuthentication(java.lang.String authName)
authName - The authentication namepublic void setAccessToken(java.lang.String accessToken)
accessToken - Access tokenpublic void setAWS4Configuration(java.lang.String accessKey,
java.lang.String secretKey,
java.lang.String region,
java.lang.String service)
accessKey - Access KeysecretKey - Secret Keyregion - Regionservice - Service to access topublic ApiClient setUserAgent(java.lang.String userAgent)
userAgent - HTTP request's user agentpublic ApiClient addDefaultHeader(java.lang.String key, java.lang.String value)
key - The header's keyvalue - The header's valuepublic ApiClient addDefaultCookie(java.lang.String key, java.lang.String value)
key - The cookie's keyvalue - The cookie's valuepublic boolean isDebugging()
public ApiClient setDebugging(boolean debugging)
debugging - To enable (true) or disable (false) debuggingpublic java.lang.String getTempFolderPath()
null, i.e. using the system's default temporary folder.public ApiClient setTempFolderPath(java.lang.String tempFolderPath)
tempFolderPath - Temporary folder pathpublic int getConnectTimeout()
public ApiClient setConnectTimeout(int connectionTimeout)
Integer.MAX_VALUE.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 java.lang.String parameterToString(java.lang.Object param)
param - Parameterpublic java.util.List<Pair> parameterToPair(java.lang.String name, java.lang.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 java.util.List<Pair> parameterToPairs(java.lang.String collectionFormat, java.lang.String name, java.util.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 java.util.List<Pair> freeFormParameterToPairs(java.lang.Object value)
Pair objects.value - The free-form query parameters.Pair objects.public java.lang.String collectionPathParameterToString(java.lang.String collectionFormat,
java.util.Collection value)
collectionFormat - The collection format of the parameter.value - The value of the parameter.public java.lang.String sanitizeFilename(java.lang.String filename)
filename - The filename to be sanitizedpublic boolean isJsonMime(java.lang.String mime)
mime - MIME (Multipurpose Internet Mail Extensions)public java.lang.String selectHeaderAccept(java.lang.String[] accepts)
accepts - The accepts array to select frompublic java.lang.String selectHeaderContentType(java.lang.String[] contentTypes)
contentTypes - The Content-Type array to select frompublic java.lang.String escapeString(java.lang.String str)
str - String to be escapedpublic <T> T deserialize(okhttp3.Response response,
java.lang.reflect.Type returnType)
throws ApiException
T - Typeresponse - HTTP responsereturnType - The type of the Java objectApiException - If fail to deserialize response body, i.e. cannot
read response body or the Content-Type of the response is not supported.public okhttp3.RequestBody serialize(java.lang.Object obj,
java.lang.String contentType)
throws ApiException
obj - The Java objectcontentType - The request Content-TypeApiException - If fail to serialize the given objectpublic java.io.File downloadFileFromResponse(okhttp3.Response response)
throws ApiException
response - An instance of the Response objectApiException - If fail to read file content from response and write
to diskpublic java.io.File prepareDownloadFile(okhttp3.Response response)
throws java.io.IOException
response - An instance of the Response objectjava.io.IOException - If fail to prepare file for downloadpublic <T> ApiResponse<T> execute(okhttp3.Call call) throws ApiException
T - Typecall - An instance of the Call objectApiException - If fail to execute the callpublic <T> ApiResponse<T> execute(okhttp3.Call call, java.lang.reflect.Type returnType) throws ApiException
T - The return type corresponding to (same with) returnTypereturnType - The return type used to deserialize HTTP response bodycall - CallApiException - If fail to execute the callpublic <T> void executeAsync(okhttp3.Call call,
ApiCallback<T> callback)
T - Typecall - An instance of the Call objectcallback - ApiCallback<T>public <T> void executeAsync(okhttp3.Call call,
java.lang.reflect.Type returnType,
ApiCallback<T> callback)
T - Typecall - The callback to be executed when the API call finishesreturnType - Return typecallback - ApiCallbackexecute(Call, Type)public <T> T handleResponse(okhttp3.Response response,
java.lang.reflect.Type returnType)
throws ApiException
T - Typeresponse - ResponsereturnType - Return typeApiException - If the response has an unsuccessful status code or
fail to deserialize the response bodypublic okhttp3.Call buildCall(java.lang.String baseUrl,
java.lang.String path,
java.lang.String method,
java.util.List<Pair> queryParams,
java.util.List<Pair> collectionQueryParams,
java.lang.Object body,
java.util.Map<java.lang.String,java.lang.String> headerParams,
java.util.Map<java.lang.String,java.lang.String> cookieParams,
java.util.Map<java.lang.String,java.lang.Object> formParams,
java.lang.String[] authNames,
ApiCallback callback)
throws ApiException
baseUrl - The base URLpath - 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 parameterscookieParams - The cookie parametersformParams - The form parametersauthNames - The authentications to applycallback - Callback for upload/download progressApiException - If fail to serialize the request body objectpublic okhttp3.Request buildRequest(java.lang.String baseUrl,
java.lang.String path,
java.lang.String method,
java.util.List<Pair> queryParams,
java.util.List<Pair> collectionQueryParams,
java.lang.Object body,
java.util.Map<java.lang.String,java.lang.String> headerParams,
java.util.Map<java.lang.String,java.lang.String> cookieParams,
java.util.Map<java.lang.String,java.lang.Object> formParams,
java.lang.String[] authNames,
ApiCallback callback)
throws ApiException
baseUrl - The base URLpath - 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 parameterscookieParams - The cookie parametersformParams - The form parametersauthNames - The authentications to applycallback - Callback for upload/download progressApiException - If fail to serialize the request body objectpublic java.lang.String buildUrl(java.lang.String baseUrl,
java.lang.String path,
java.util.List<Pair> queryParams,
java.util.List<Pair> collectionQueryParams)
baseUrl - The base URLpath - The sub pathqueryParams - The query parameterscollectionQueryParams - The collection query parameterspublic void processHeaderParams(java.util.Map<java.lang.String,java.lang.String> headerParams,
okhttp3.Request.Builder reqBuilder)
headerParams - Header parameters in the form of MapreqBuilder - Request.Builderpublic void processCookieParams(java.util.Map<java.lang.String,java.lang.String> cookieParams,
okhttp3.Request.Builder reqBuilder)
cookieParams - Cookie parameters in the form of MapreqBuilder - Request.Builderpublic void updateParamsForAuth(java.lang.String[] authNames,
java.util.List<Pair> queryParams,
java.util.Map<java.lang.String,java.lang.String> headerParams,
java.util.Map<java.lang.String,java.lang.String> cookieParams,
java.lang.String payload,
java.lang.String method,
java.net.URI uri)
throws ApiException
authNames - The authentications to applyqueryParams - List of query parametersheaderParams - Map of header parameterscookieParams - Map of cookie parameterspayload - HTTP request bodymethod - HTTP methoduri - URIApiException - If fails to update the parameterspublic okhttp3.RequestBody buildRequestBodyFormEncoding(java.util.Map<java.lang.String,java.lang.Object> formParams)
formParams - Form parameters in the form of Mappublic okhttp3.RequestBody buildRequestBodyMultipart(java.util.Map<java.lang.String,java.lang.Object> formParams)
formParams - Form parameters in the form of Mappublic java.lang.String guessContentTypeFromFile(java.io.File file)
file - The given file