Package com.docspring
Class ApiClient
java.lang.Object
com.docspring.JavaTimeFormatter
com.docspring.ApiClient
@Generated(value="org.openapitools.codegen.languages.JavaClientCodegen",
comments="Generator version: 7.16.0-DOCSPRING")
public class ApiClient
extends JavaTimeFormatter
ApiClient class.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Map<String,Authentication> protected Stringprotected org.glassfish.jersey.client.ClientConfigprotected intprotected DateFormatprotected booleanprotected javax.ws.rs.client.Clientprotected JSONprotected static final Patternprotected static final Loggerprotected Map<String,List<ServerConfiguration>> protected intprotected Integerprotected List<ServerConfiguration>protected Stringprotected String -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new ApiClient with default parameters.ApiClient(Map<String, Authentication> authMap) Constructs a new ApiClient with the specified authentication parameters. -
Method Summary
Modifier and TypeMethodDescriptionaddDefaultCookie(String key, String value) Add a default cookie.addDefaultHeader(String key, String value) Add a default header.protected voidaddParamToMultipart(Object value, String key, org.glassfish.jersey.media.multipart.MultiPart multiPart) Adds the object with the provided key to the MultiPart.protected voidapplyDebugSetting(org.glassfish.jersey.client.ClientConfig clientConfig) protected javax.ws.rs.client.ClientBuild the Client used to make HTTP requests.buildResponseHeaders(javax.ws.rs.core.Response response) Build the response headers.configureApiKeys(Map<String, String> secrets) Helper method to configure authentications which respects aliases of API keys.protected voidcustomizeClientBuilder(javax.ws.rs.client.ClientBuilder clientBuilder) Customize the client builder.<T> Tdeserialize(javax.ws.rs.core.Response response, javax.ws.rs.core.GenericType<T> returnType) Deserialize response body to Java object according to the Content-Type.protected voiddisableCertificateValidation(javax.ws.rs.client.ClientBuilder clientBuilder) Disable X.509 certificate validation in TLS connections.downloadFileFromResponse(javax.ws.rs.core.Response response) Download file from the given response.escapeString(String str) Escape the given string to be used as URL query value.formatDate(Date date) Format the given Date object into string.getAuthentication(String authName) Get authentication for the given name.Get authentications (key: authentication name, value: authentication).Returns the base URL to the location where the OpenAPI document is being served.org.glassfish.jersey.client.ClientConfigGets the client config.intConnect timeout (in milliseconds).Get the date format used to parse/format date parameters.org.glassfish.jersey.client.ClientConfigGet the default client config.javax.ws.rs.client.ClientGetter for the fieldhttpClient.getJSON()Gets the JSON instance to do JSON serialization and deserialization.intread timeout (in milliseconds).Getter for the fieldserverIndex.Getter for the fieldservers.Getter for the fieldserverVariables.The path of temporary folder used to store downloaded files from endpoints with file response.Get the User-Agent header's value.<T> ApiResponse<T>invokeAPI(String operation, String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> cookieParams, Map<String, Object> formParams, String accept, String contentType, String[] authNames, javax.ws.rs.core.GenericType<T> returnType, boolean isBodyNullable) Invoke API by sending HTTP request with the given options.<T> ApiResponse<T>invokeAPI(String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> cookieParams, Map<String, Object> formParams, String accept, String contentType, String[] authNames, javax.ws.rs.core.GenericType<T> returnType, boolean isBodyNullable) Deprecated.Add qualified name of the operation as a first parameter.booleanCheck that whether debugging is enabled for this API client.booleanisJsonMime(String mime) Check if the given MIME is a JSON MIME.parameterToPairs(String collectionFormat, String name, Object value) parameterToString(Object param) Format the given parameter object into string.Parse the given string into Date object.prepareDownloadFile(javax.ws.rs.core.Response response) Prepare the file for download from the response.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)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.protected javax.ws.rs.core.ResponsesendRequest(String method, javax.ws.rs.client.Invocation.Builder invocationBuilder, javax.ws.rs.client.Entity<?> entity) javax.ws.rs.client.Entity<?>Serialize the given Java object into string entity according the given Content-Type (only JSON is supported for now).serializeToString(Object obj, Map<String, Object> formParams, String contentType, boolean isBodyNullable) Serialize the given Java object into string according the given Content-Type (only JSON, HTTP form is supported for now).Helper method to set API key value for the first API key authentication.setApiKeyPrefix(String apiKeyPrefix) Helper method to set API key prefix for the first API key authentication.setBasePath(String basePath) Sets the base URL to the location where the OpenAPI document is being served.setBearerToken(String bearerToken) Helper method to set bearer token for the first Bearer authentication.setClientConfig(org.glassfish.jersey.client.ClientConfig clientConfig) Set the client config.setConnectTimeout(int connectionTimeout) Set the connect timeout (in milliseconds).setDateFormat(DateFormat dateFormat) Set the date format used to parse/format date parameters.setDebugging(boolean debugging) Enable/disable debugging for this API client.setHttpClient(javax.ws.rs.client.Client httpClient) Setter for the fieldhttpClient.setPassword(String password) Helper method to set password for the first HTTP basic authentication.setReadTimeout(int readTimeout) Set the read timeout (in milliseconds).setServerIndex(Integer serverIndex) Setter for the fieldserverIndex.setServers(List<ServerConfiguration> servers) Setter for the fieldservers.setServerVariables(Map<String, String> serverVariables) Setter for the fieldserverVariables.setTempFolderPath(String tempFolderPath) Set temp folder pathsetUserAgent(String userAgent) Set the User-Agent header's value (by adding to the default header map).setUsername(String username) Helper method to set username for the first HTTP basic authentication.protected voidprotected voidupdateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams, String payload, String method, URI uri) Update query and header parameters based on authentication settings.Methods inherited from class com.docspring.JavaTimeFormatter
formatOffsetDateTime, getOffsetDateTimeFormatter, parseOffsetDateTime, setOffsetDateTimeFormatter
-
Field Details
-
JSON_MIME_PATTERN
-
defaultHeaderMap
-
defaultCookieMap
-
basePath
-
userAgent
-
log
-
servers
-
serverIndex
-
serverVariables
-
operationServers
-
operationServerIndex
-
operationServerVariables
-
debugging
protected boolean debugging -
clientConfig
protected org.glassfish.jersey.client.ClientConfig clientConfig -
connectionTimeout
protected int connectionTimeout -
readTimeout
protected int readTimeout -
httpClient
protected javax.ws.rs.client.Client httpClient -
json
-
tempFolderPath
-
authentications
-
authenticationLookup
-
dateFormat
-
-
Constructor Details
-
ApiClient
public ApiClient()Constructs a new ApiClient with default parameters. -
ApiClient
Constructs a new ApiClient with the specified authentication parameters.- Parameters:
authMap- A hash map containing authentication parameters.
-
-
Method Details
-
getJSON
Gets the JSON instance to do JSON serialization and deserialization.- Returns:
- JSON
-
getHttpClient
public javax.ws.rs.client.Client getHttpClient()Getter for the field
httpClient.- Returns:
- a
Clientobject.
-
setHttpClient
Setter for the field
httpClient.- Parameters:
httpClient- aClientobject.- Returns:
- a
ApiClientobject.
-
getBasePath
Returns the base URL to the location where the OpenAPI document is being served.- Returns:
- The base URL to the target host.
-
setBasePath
Sets the base URL to the location where the OpenAPI document is being served.- Parameters:
basePath- The base URL to the target host.- Returns:
- a
ApiClientobject.
-
getServers
Getter for the field
servers.- Returns:
- a
Listof servers.
-
setServers
Setter for the field
servers. -
getServerIndex
Getter for the field
serverIndex.- Returns:
- a
Integerobject.
-
setServerIndex
Setter for the field
serverIndex.- Parameters:
serverIndex- the server index- Returns:
- a
ApiClientobject.
-
getServerVariables
Getter for the field
serverVariables.- Returns:
- a
Mapof server variables.
-
setServerVariables
Setter for the field
serverVariables. -
updateBasePath
protected void updateBasePath() -
getAuthentications
Get authentications (key: authentication name, value: authentication).- Returns:
- Map of authentication object
-
getAuthentication
Get authentication for the given name.- Parameters:
authName- The authentication name- Returns:
- The authentication, null if not found
-
setUsername
Helper method to set username for the first HTTP basic authentication.- Parameters:
username- Username- Returns:
- a
ApiClientobject.
-
setPassword
Helper method to set password for the first HTTP basic authentication.- Parameters:
password- Password- Returns:
- a
ApiClientobject.
-
setApiKey
Helper method to set API key value for the first API key authentication.- Parameters:
apiKey- API key- Returns:
- a
ApiClientobject.
-
configureApiKeys
Helper method to configure authentications which respects aliases of API keys.- Parameters:
secrets- Hash map from authentication name to its secret.- Returns:
- a
ApiClientobject.
-
setApiKeyPrefix
Helper method to set API key prefix for the first API key authentication.- Parameters:
apiKeyPrefix- API key prefix- Returns:
- a
ApiClientobject.
-
setBearerToken
Helper method to set bearer token for the first Bearer authentication.- Parameters:
bearerToken- Bearer token- Returns:
- a
ApiClientobject.
-
setUserAgent
Set the User-Agent header's value (by adding to the default header map).- Parameters:
userAgent- Http user agent- Returns:
- a
ApiClientobject.
-
getUserAgent
Get the User-Agent header's value.- Returns:
- User-Agent string
-
addDefaultHeader
Add a default header.- Parameters:
key- The header's keyvalue- The header's value- Returns:
- a
ApiClientobject.
-
addDefaultCookie
Add a default cookie.- Parameters:
key- The cookie's keyvalue- The cookie's value- Returns:
- a
ApiClientobject.
-
getClientConfig
public org.glassfish.jersey.client.ClientConfig getClientConfig()Gets the client config.- Returns:
- Client config
-
setClientConfig
Set the client config.- Parameters:
clientConfig- Set the client config- Returns:
- a
ApiClientobject.
-
isDebugging
public boolean isDebugging()Check that whether debugging is enabled for this API client.- Returns:
- True if debugging is switched on
-
setDebugging
Enable/disable debugging for this API client.- Parameters:
debugging- To enable (true) or disable (false) debugging- Returns:
- a
ApiClientobject.
-
getTempFolderPath
The path of temporary folder used to store downloaded files from endpoints with file response. The default value isnull, i.e. using the system's default temporary folder.- Returns:
- Temp folder path
-
setTempFolderPath
Set temp folder path- Parameters:
tempFolderPath- Temp folder path- Returns:
- a
ApiClientobject.
-
getConnectTimeout
public int getConnectTimeout()Connect timeout (in milliseconds).- Returns:
- Connection timeout
-
setConnectTimeout
Set the connect timeout (in milliseconds). A value of 0 means no timeout, otherwise values must be between 1 andInteger.MAX_VALUE.- Parameters:
connectionTimeout- Connection timeout in milliseconds- Returns:
- a
ApiClientobject.
-
getReadTimeout
public int getReadTimeout()read timeout (in milliseconds).- Returns:
- Read timeout
-
setReadTimeout
Set the read timeout (in milliseconds). A value of 0 means no timeout, otherwise values must be between 1 andInteger.MAX_VALUE.- Parameters:
readTimeout- Read timeout in milliseconds- Returns:
- a
ApiClientobject.
-
getDateFormat
Get the date format used to parse/format date parameters.- Returns:
- Date format
-
setDateFormat
Set the date format used to parse/format date parameters.- Parameters:
dateFormat- Date format- Returns:
- a
ApiClientobject.
-
parseDate
Parse the given string into Date object.- Parameters:
str- String- Returns:
- Date
-
formatDate
Format the given Date object into string.- Parameters:
date- Date- Returns:
- Date in string format
-
parameterToString
Format the given parameter object into string.- Parameters:
param- Object- Returns:
- Object in string format
-
parameterToPairs
-
isJsonMime
Check if the given MIME is a JSON MIME. JSON MIME examples: application/json application/json; charset=UTF8 APPLICATION/JSON application/vnd.company+json "*/*" is also considered JSON by this method.- Parameters:
mime- MIME- Returns:
- True if the MIME type is JSON
-
selectHeaderAccept
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)- Parameters:
accepts- The accepts array to select from- Returns:
- The Accept header to use. If the given array is empty, null will be returned (not to set the Accept header explicitly).
-
selectHeaderContentType
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.- Parameters:
contentTypes- The Content-Type array to select from- Returns:
- The Content-Type header to use. If the given array is empty, JSON will be used.
-
escapeString
Escape the given string to be used as URL query value.- Parameters:
str- String- Returns:
- Escaped string
-
serialize
public javax.ws.rs.client.Entity<?> serialize(Object obj, Map<String, Object> formParams, String contentType, boolean isBodyNullable) throws ApiExceptionSerialize the given Java object into string entity according the given Content-Type (only JSON is supported for now).- Parameters:
obj- ObjectformParams- Form parameterscontentType- Context type- Returns:
- Entity
- Throws:
ApiException- API exception
-
addParamToMultipart
protected void addParamToMultipart(Object value, String key, org.glassfish.jersey.media.multipart.MultiPart multiPart) Adds the object with the provided key to the MultiPart. Based on the object type sets Content-Disposition and Content-Type.- Parameters:
obj- Objectkey- Key of the objectmultiPart- MultiPart to add the form param to
-
serializeToString
public String serializeToString(Object obj, Map<String, Object> formParams, String contentType, boolean isBodyNullable) throws ApiExceptionSerialize the given Java object into string according the given Content-Type (only JSON, HTTP form is supported for now).- Parameters:
obj- ObjectformParams- Form parameterscontentType- Context typeisBodyNullable- True if the body is nullable- Returns:
- String
- Throws:
ApiException- API exception
-
deserialize
public <T> T deserialize(javax.ws.rs.core.Response response, javax.ws.rs.core.GenericType<T> returnType) throws ApiException Deserialize response body to Java object according to the Content-Type.- Type Parameters:
T- Type- Parameters:
response- ResponsereturnType- Return type- Returns:
- Deserialize object
- Throws:
ApiException- API exception
-
downloadFileFromResponse
Download file from the given response.- Parameters:
response- Response- Returns:
- File
- Throws:
ApiException- If fail to read file content from response and write to disk
-
prepareDownloadFile
Prepare the file for download from the response.
- Parameters:
response- aResponseobject.- Returns:
- a
Fileobject. - Throws:
IOException- if any.
-
invokeAPI
public <T> ApiResponse<T> invokeAPI(String operation, String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, throws ApiExceptionString> cookieParams, Map<String, Object> formParams, String accept, String contentType, String[] authNames, javax.ws.rs.core.GenericType<T> returnType, boolean isBodyNullable) Invoke API by sending HTTP request with the given options.- Type Parameters:
T- Type- Parameters:
operation- The qualified name of the operationpath- The sub-path of the HTTP URLmethod- The request method, one of "GET", "POST", "PUT", "HEAD" and "DELETE"queryParams- The query parametersbody- The request body objectheaderParams- The header parameterscookieParams- The cookie 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 responseisBodyNullable- True if the body is nullable- Returns:
- The response body in type of string
- Throws:
ApiException- API exception
-
sendRequest
protected javax.ws.rs.core.Response sendRequest(String method, javax.ws.rs.client.Invocation.Builder invocationBuilder, javax.ws.rs.client.Entity<?> entity) -
invokeAPI
@Deprecated public <T> ApiResponse<T> invokeAPI(String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, throws ApiExceptionString> cookieParams, Map<String, Object> formParams, String accept, String contentType, String[] authNames, javax.ws.rs.core.GenericType<T> returnType, boolean isBodyNullable) Deprecated.Add qualified name of the operation as a first parameter.- Throws:
ApiException
-
buildHttpClient
protected javax.ws.rs.client.Client buildHttpClient()Build the Client used to make HTTP requests.- Returns:
- Client
-
getDefaultClientConfig
public org.glassfish.jersey.client.ClientConfig getDefaultClientConfig()Get the default client config.- Returns:
- Client config
-
applyDebugSetting
protected void applyDebugSetting(org.glassfish.jersey.client.ClientConfig clientConfig) -
customizeClientBuilder
protected void customizeClientBuilder(javax.ws.rs.client.ClientBuilder clientBuilder) Customize the client builder. This method can be overridden to customize the API client. For example, this can be used to: 1. Set the hostname verifier to be used by the client to verify the endpoint's hostname against its identification information. 2. Set the client-side key store. 3. Set the SSL context that will be used when creating secured transport connections to server endpoints from web targets created by the client instance that is using this SSL context. 4. Set the client-side trust store. To completely disable certificate validation (at your own risk), you can override this method and invoke disableCertificateValidation(clientBuilder).- Parameters:
clientBuilder- aClientBuilderobject.
-
disableCertificateValidation
protected void disableCertificateValidation(javax.ws.rs.client.ClientBuilder clientBuilder) throws KeyManagementException, NoSuchAlgorithmException Disable X.509 certificate validation in TLS connections. Please note that trusting all certificates is extremely risky. This may be useful in a development environment with self-signed certificates.- Parameters:
clientBuilder- aClientBuilderobject.- Throws:
KeyManagementException- if any.NoSuchAlgorithmException- if any.
-
buildResponseHeaders
Build the response headers.
- Parameters:
response- aResponseobject.- Returns:
- a
Mapof response headers.
-
updateParamsForAuth
protected void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams, Map<String, throws ApiExceptionString> cookieParams, String payload, String method, URI uri) Update query and header parameters based on authentication settings.- Parameters:
authNames- The authentications to applyqueryParams- List of query parametersheaderParams- Map of header parameterscookieParams- Map of cookie parametersmethod- HTTP method (e.g. POST)uri- HTTP URI- Throws:
ApiException
-