public class ApiClient extends Object
Modifier and Type | Field and Description |
---|---|
protected Map<String,Authentication> |
authentications |
protected int |
connectionTimeout |
protected DateFormat |
dateFormat |
protected boolean |
debugging |
protected Map<String,String> |
defaultHeaderMap |
static String |
DEMO_REST_BASEPATH
sandbox/demo base path
|
protected javax.ws.rs.client.Client |
httpClient |
protected JSON |
json |
static String |
PRODUCTION_REST_BASEPATH
live/production base path
|
static String |
STAGE_REST_BASEPATH
stage base path
|
protected String |
tempFolderPath |
Constructor and Description |
---|
ApiClient() |
ApiClient(String basePath) |
ApiClient(String oAuthBasePath,
String authName)
Basic constructor for single auth name
|
ApiClient(String oAuthBasePath,
String[] authNames) |
ApiClient(String oAuthBasePath,
String authName,
String clientId,
String secret)
Helper constructor for OAuth2
|
Modifier and Type | Method and Description |
---|---|
void |
addAuthorization(String authName,
Authentication auth) |
ApiClient |
addDefaultHeader(String key,
String value)
Add a default header.
|
static DateFormat |
buildDefaultDateFormat() |
protected javax.ws.rs.client.Client |
buildHttpClient(boolean debugging)
Build the Client used to make HTTP requests.
|
protected Map<String,List<String>> |
buildResponseHeaders(javax.ws.rs.core.Response response) |
void |
configureAuthorizationFlow(String clientId,
String clientSecret,
String redirectURI)
Helper method to configure the OAuth accessCode/implicit flow parameters
|
void |
configureJWTAuthorizationFlow(String publicKeyFilename,
String privateKeyFilename,
String oAuthBasePath,
String clientId,
String userId,
long expiresIn)
Deprecated.
As of release 2.7.0, replaced by
requestJWTUserToken(String, String, List, byte[], long) ()} and requestJWTApplicationToken(String, List, byte[], long) |
<T> T |
deserialize(javax.ws.rs.core.Response response,
javax.ws.rs.core.GenericType<T> returnType)
Deserialize response body to Java object according to the Content-Type.
|
File |
downloadFileFromResponse(javax.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.
|
OAuth.OAuthToken |
generateAccessToken(String clientId,
String clientSecret,
String code) |
String |
getAccessToken() |
Authentication |
getAuthentication(String authName)
Get authentication for the given name.
|
Map<String,Authentication> |
getAuthentications()
Get authentications (key: authentication name, value: authentication).
|
org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder |
getAuthorizationEndPoint()
Helper method to configure authorization endpoint of the first oauth found in the authentications (there should be only one)
|
String |
getAuthorizationUri() |
URI |
getAuthorizationUri(String clientId,
List<String> scopes,
String redirectUri,
String responseType)
Helper method to configure the OAuth accessCode/implicit flow parameters
|
URI |
getAuthorizationUri(String clientId,
List<String> scopes,
String redirectUri,
String responseType,
String state)
Helper method to configure the OAuth accessCode/implicit flow parameters
|
String |
getBasePath() |
int |
getConnectTimeout()
Connect timeout (in milliseconds).
|
DateFormat |
getDateFormat()
Get the date format used to parse/format date parameters.
|
javax.ws.rs.client.Client |
getHttpClient() |
JSON |
getJSON()
Gets the JSON instance to do JSON serialization and deserialization.
|
String |
getJWTUri(String clientId,
String redirectURI,
String oAuthBasePath)
Helper method to build the OAuth JWT grant uri (used once to get a user consent for impersonation)
|
com.fasterxml.jackson.databind.ObjectMapper |
getObjectMapper()
Returns the current object mapper used for JSON serialization/deserialization.
|
int |
getReadTimeout()
read timeout (in milliseconds).
|
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.
|
org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder |
getTokenEndPoint()
Helper method to configure the token endpoint of the first oauth found in the authentications (there should be only one)
|
OAuth.UserInfo |
getUserInfo(String accessToken) |
<T> T |
invokeAPI(String path,
String method,
List<Pair> queryParams,
List<Pair> collectionQueryParams,
Object body,
Map<String,String> headerParams,
Map<String,Object> formParams,
String accept,
String contentType,
String[] authNames,
javax.ws.rs.core.GenericType<T> returnType)
Invoke API by sending HTTP request 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> |
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. |
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.
|
protected void |
performAdditionalClientConfiguration(org.glassfish.jersey.client.ClientConfig clientConfig) |
File |
prepareDownloadFile(javax.ws.rs.core.Response response) |
ApiClient |
rebuildHttpClient()
Build the Client used to make HTTP requests with the latest settings,
i.e.
|
void |
registerAccessTokenListener(AccessTokenListener accessTokenListener)
Configures a listener which is notified when a new access token is received.
|
OAuth.OAuthToken |
requestJWTApplicationToken(String clientId,
List<String> scopes,
byte[] rsaPrivateKey,
long expiresIn)
RESERVED FOR PARTNERS Request JWT Application Token
Configures the current instance of ApiClient with a fresh OAuth JWT access token from DocuSign
|
OAuth.OAuthToken |
requestJWTUserToken(String clientId,
String userId,
List<String> scopes,
byte[] rsaPrivateKey,
long expiresIn)
Configures the current instance of ApiClient with a fresh OAuth JWT access token from DocuSign
|
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.
|
javax.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).
|
Object |
serialize(Object obj,
String contentType,
Map<String,Object> formParams)
Serialize the given Java object into string according the given
Content-Type (only JSON is supported for now).
|
void |
setAccessToken(String accessToken,
Long expiresIn)
Helper method to preset the OAuth access token of the first OAuth found in the apiAuthorizations (there should be only one)
|
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) |
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 |
setHttpClient(javax.ws.rs.client.Client httpClient) |
ApiClient |
setOAuthBasePath(String oAuthBasePath)
Sets the OAuth base path.
|
ApiClient |
setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) |
void |
setPassword(String password)
Helper method to set password for the first HTTP basic authentication.
|
ApiClient |
setReadTimeout(int readTimeout)
Set the read timeout (in 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 |
updateAccessToken()
Helper method to set access token for the first OAuth2 authentication.
|
protected void |
updateParamsForAuth(String[] authNames,
List<Pair> queryParams,
Map<String,String> headerParams)
Update query and header parameters based on authentication settings.
|
public static final String PRODUCTION_REST_BASEPATH
public static final String DEMO_REST_BASEPATH
public static final String STAGE_REST_BASEPATH
protected boolean debugging
protected int connectionTimeout
protected javax.ws.rs.client.Client httpClient
protected JSON json
protected String tempFolderPath
protected Map<String,Authentication> authentications
protected DateFormat dateFormat
public ApiClient()
public ApiClient(String basePath)
public ApiClient(String oAuthBasePath, String authName)
authName
- public static DateFormat buildDefaultDateFormat()
public ApiClient rebuildHttpClient()
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
Note: If you make changes to the object mapper, remember to set it back via
setObjectMapper
in order to trigger HTTP client rebuilding.
public ApiClient setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
public JSON getJSON()
public javax.ws.rs.client.Client getHttpClient()
public ApiClient setHttpClient(javax.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 addAuthorization(String authName, Authentication auth)
public void setUsername(String username)
username
- Usernamepublic void setPassword(String password)
password
- Passwordpublic void setApiKey(String apiKey)
apiKey
- API keypublic void setApiKeyPrefix(String apiKeyPrefix)
apiKeyPrefix
- API key prefixpublic void updateAccessToken()
public void setAccessToken(String accessToken, Long expiresIn)
accessToken
- OAuth access tokenexpiresIn
- Validity period of the access token in secondspublic String getAccessToken()
public 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 int getReadTimeout()
public ApiClient setReadTimeout(int readTimeout)
Integer.MAX_VALUE
.readTimeout
- Read timeout in millisecondspublic DateFormat getDateFormat()
public ApiClient setDateFormat(DateFormat dateFormat)
dateFormat
- Date formatpublic org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder getTokenEndPoint()
public org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder getAuthorizationEndPoint()
public void configureAuthorizationFlow(String clientId, String clientSecret, String redirectURI)
clientId
- OAuth2 client IDclientSecret
- OAuth2 client secretredirectURI
- OAuth2 redirect uripublic String getAuthorizationUri() throws org.apache.oltu.oauth2.common.exception.OAuthSystemException
org.apache.oltu.oauth2.common.exception.OAuthSystemException
public URI getAuthorizationUri(String clientId, List<String> scopes, String redirectUri, String responseType, String state) throws IllegalArgumentException, javax.ws.rs.core.UriBuilderException
clientId
- OAuth2 client ID: Identifies the client making the request.
Client applications may be scoped to a limited set of system access.scopes
- the list of requested scopes. Values include OAuth.Scope_SIGNATURE
, OAuth.Scope_EXTENDED
, OAuth.Scope_IMPERSONATION
. You can also pass any advanced scope.redirectUri
- this determines where to deliver the response containing the authorization code or access token.responseType
- determines the response type of the authorization request.
state
- Allows for arbitrary state that may be useful to your application.
The value in this parameter will be round-tripped along with the response so you can make sure it didn't change.IllegalArgumentException
javax.ws.rs.core.UriBuilderException
public URI getAuthorizationUri(String clientId, List<String> scopes, String redirectUri, String responseType) throws IllegalArgumentException, javax.ws.rs.core.UriBuilderException
clientId
- OAuth2 client ID: Identifies the client making the request.
Client applications may be scoped to a limited set of system access.scopes
- the list of requested scopes. Values include OAuth.Scope_SIGNATURE
, OAuth.Scope_EXTENDED
, OAuth.Scope_IMPERSONATION
. You can also pass any advanced scope.redirectUri
- this determines where to deliver the response containing the authorization code or access token.responseType
- determines the response type of the authorization request.
IllegalArgumentException
javax.ws.rs.core.UriBuilderException
public ApiClient setOAuthBasePath(String oAuthBasePath)
OAuth.PRODUCTION_OAUTH_BASEPATH
, OAuth.DEMO_OAUTH_BASEPATH
and custom (e.g. "account-s.docusign.com")oAuthBasePath
- the new value for the OAuth base pathpublic OAuth.OAuthToken generateAccessToken(String clientId, String clientSecret, String code) throws ApiException, IOException
clientId
- OAuth2 client ID: Identifies the client making the request.
Client applications may be scoped to a limited set of system access.clientSecret
- the secret key you generated when you set up the integration in DocuSign Admin console.code
- The authorization code that you received from the getAuthorizationUri callback.ApiException
- if the HTTP call status is different than 2xx.IOException
- if there is a problem while parsing the reponse object.OAuth.OAuthToken
public OAuth.UserInfo getUserInfo(String accessToken) throws IllegalArgumentException, ApiException
accessToken
- the bearer token to use to authenticate for this call.ApiException
- if the HTTP call status is different than 2xx.IllegalArgumentException
OAuth.UserInfo
public void registerAccessTokenListener(AccessTokenListener accessTokenListener)
accessTokenListener
- public String getJWTUri(String clientId, String redirectURI, String oAuthBasePath)
clientId
- OAuth2 client IDredirectURI
- OAuth2 redirect uri@Deprecated public void configureJWTAuthorizationFlow(String publicKeyFilename, String privateKeyFilename, String oAuthBasePath, String clientId, String userId, long expiresIn) throws ApiException, IOException
requestJWTUserToken(String, String, List, byte[], long)
()} and requestJWTApplicationToken(String, List, byte[], long)
publicKeyFilename
- the filename of the RSA public keyprivateKeyFilename
- the filename of the RSA private keyoAuthBasePath
- DocuSign OAuth base path (account-d.docusign.com for the developer sandbox
and account.docusign.com for the production platform)clientId
- DocuSign OAuth Client Id (AKA Integrator Key)userId
- DocuSign user Id to be impersonated (This is a UUID)expiresIn
- number of seconds remaining before the JWT assertion is considered as invalidApiException
- if there is an error while exchanging the JWT with an access tokenIOException
- if there is an issue with either the public or private filepublic OAuth.OAuthToken requestJWTUserToken(String clientId, String userId, List<String> scopes, byte[] rsaPrivateKey, long expiresIn) throws IllegalArgumentException, ApiException, IOException
clientId
- DocuSign OAuth Client Id (AKA Integrator Key)userId
- DocuSign user Id to be impersonated (This is a UUID)scopes
- the list of requested scopes. Values include OAuth.Scope_SIGNATURE
, OAuth.Scope_EXTENDED
, OAuth.Scope_IMPERSONATION
. You can also pass any advanced scope.rsaPrivateKey
- the byte contents of the RSA private keyexpiresIn
- number of seconds remaining before the JWT assertion is considered as invalidIllegalArgumentException
- if one of the arguments is invalidApiException
- if there is an error while exchanging the JWT with an access tokenIOException
- if there is an issue with either the public or private filepublic OAuth.OAuthToken requestJWTApplicationToken(String clientId, List<String> scopes, byte[] rsaPrivateKey, long expiresIn) throws IllegalArgumentException, IOException, ApiException
clientId
- DocuSign OAuth Client Id (AKA Integrator Key)scopes
- the list of requested scopes. Values include OAuth.Scope_SIGNATURE
, OAuth.Scope_EXTENDED
, OAuth.Scope_IMPERSONATION
. You can also pass any advanced scope.rsaPrivateKey
- the byte contents of the RSA private keyexpiresIn
- number of seconds remaining before the JWT assertion is considered as invalidIllegalArgumentException
- if one of the arguments is invalidIOException
- if there is an issue with either the public or private fileApiException
- if there is an error while exchanging the JWT with an access tokenpublic Date parseDate(String str)
str
- Stringpublic String formatDate(Date date)
date
- Datepublic String parameterToString(Object param)
param
- Objectpublic 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 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 Object serialize(Object obj, String contentType, Map<String,Object> formParams) throws ApiException
obj
- ObjectcontentType
- Content typeformParams
- Form parametersApiException
- API exceptionpublic javax.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(javax.ws.rs.core.Response response, javax.ws.rs.core.GenericType<T> returnType) throws ApiException
T
- Typeresponse
- ResponsereturnType
- Return typeApiException
- API exceptionpublic File downloadFileFromResponse(javax.ws.rs.core.Response response) throws ApiException
response
- ResponseApiException
- If fail to read file content from response and write to diskpublic File prepareDownloadFile(javax.ws.rs.core.Response response) throws IOException
IOException
public <T> T invokeAPI(String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, Object body, Map<String,String> headerParams, Map<String,Object> formParams, String accept, String contentType, String[] authNames, javax.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", "HEAD" and "DELETE"queryParams
- The query parameterscollectionQueryParams
- The collection 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 exceptionprotected javax.ws.rs.client.Client buildHttpClient(boolean debugging)
debugging
- Debug settingprotected void performAdditionalClientConfiguration(org.glassfish.jersey.client.ClientConfig clientConfig)
protected Map<String,List<String>> buildResponseHeaders(javax.ws.rs.core.Response response)
Copyright © 2021. All rights reserved.