Package com.ibm.cloud.sdk.core.service
Class BaseService
- java.lang.Object
-
- com.ibm.cloud.sdk.core.service.BaseService
-
public abstract class BaseService extends java.lang.Object
Abstracts common functionality of various IBM Cloud services.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
PROPNAME_DISABLE_SSL
static java.lang.String
PROPNAME_ENABLE_GZIP
static java.lang.String
PROPNAME_ENABLE_RETRIES
static java.lang.String
PROPNAME_MAX_RETRIES
static java.lang.String
PROPNAME_RETRY_INTERVAL
static java.lang.String
PROPNAME_URL
-
Constructor Summary
Constructors Constructor Description BaseService(java.lang.String name, Authenticator authenticator)
Instantiates a new IBM Cloud service.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
configureClient(HttpConfigOptions options)
Configures the currently-configuredOkHttpClient
instance based on the passed-in options.void
configureService(java.lang.String serviceName)
static java.lang.String
constructServiceUrl(java.lang.String parameterizedUrl, java.util.Map<java.lang.String,java.lang.String> defaultUrlVariables, java.util.Map<java.lang.String,java.lang.String> providedUrlVariables)
Constructs a service URL by formatting a parameterized URL.static java.lang.String
constructServiceURL(java.lang.String parameterizedUrl, java.util.Map<java.lang.String,java.lang.String> defaultUrlVariables, java.util.Map<java.lang.String,java.lang.String> providedUrlVariables)
Deprecated.use constructServiceUrl() instead.void
disableRetries()
Disables the retries for the HTTP requests.void
enableGzipCompression(boolean shouldEnableCompression)
Enables gzip compression of requests bodies for the current client.void
enableRetries(int maxRetries, int maxRetryInterval)
Enables the retries for the HTTP requests.Authenticator
getAuthenticator()
Returns the Authenticator instance currently set on this BaseService instance.okhttp3.OkHttpClient
getClient()
Returns the currently-configuredOkHttpClient
instance.okhttp3.Headers
getDefaultHeaders()
Returns the set of default headers current set on this BaseService instance.java.lang.String
getEndPoint()
Deprecated.Use getServiceURL() instead.java.lang.String
getName()
Gets the name.java.lang.String
getServiceUrl()
Returns the service URL value associated with this service instance.static boolean
isJsonMimeType(java.lang.String mimeType)
Returns true iff the specified mimeType indicates a JSON-related content type.static boolean
isJsonPatchMimeType(java.lang.String mimeType)
Returns true iff the specified mimeType indicates a "Json Patch"-related content type.void
setClient(okhttp3.OkHttpClient client)
Sets a newOkHttpClient
instance to be used for API invocations by this BaseService instance.void
setDefaultHeaders(java.util.Map<java.lang.String,java.lang.String> headers)
Set the default headers to be used on every HTTP request.void
setEndPoint(java.lang.String endPoint)
Deprecated.Use setServiceURL() instead.void
setServiceUrl(java.lang.String serviceUrl)
Set the service URL (the base URL for the service instance).java.lang.String
toString()
-
-
-
Field Detail
-
PROPNAME_URL
public static final java.lang.String PROPNAME_URL
- See Also:
- Constant Field Values
-
PROPNAME_DISABLE_SSL
public static final java.lang.String PROPNAME_DISABLE_SSL
- See Also:
- Constant Field Values
-
PROPNAME_ENABLE_GZIP
public static final java.lang.String PROPNAME_ENABLE_GZIP
- See Also:
- Constant Field Values
-
PROPNAME_ENABLE_RETRIES
public static final java.lang.String PROPNAME_ENABLE_RETRIES
- See Also:
- Constant Field Values
-
PROPNAME_MAX_RETRIES
public static final java.lang.String PROPNAME_MAX_RETRIES
- See Also:
- Constant Field Values
-
PROPNAME_RETRY_INTERVAL
public static final java.lang.String PROPNAME_RETRY_INTERVAL
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BaseService
public BaseService(java.lang.String name, Authenticator authenticator)
Instantiates a new IBM Cloud service.- Parameters:
name
- the service nameauthenticator
- an Authenticator instance that will perform authentication on outgoing requests
-
-
Method Detail
-
configureService
public void configureService(java.lang.String serviceName)
-
enableGzipCompression
public void enableGzipCompression(boolean shouldEnableCompression)
Enables gzip compression of requests bodies for the current client. If shouldEnableCompression is true, then a new client is configured with the GzipRequestInterceptor.- Parameters:
shouldEnableCompression
- the value used to set the enableGzipCompression HttpConfigOption
-
enableRetries
public void enableRetries(int maxRetries, int maxRetryInterval)
Enables the retries for the HTTP requests.- Parameters:
maxRetries
- the value of the maximum number of retriesmaxRetryInterval
- the maximum time to wait between retries in seconds
-
disableRetries
public void disableRetries()
Disables the retries for the HTTP requests.
-
getClient
public okhttp3.OkHttpClient getClient()
Returns the currently-configuredOkHttpClient
instance.- Returns:
- the
OkHttpClient
instance
-
setClient
public void setClient(okhttp3.OkHttpClient client)
Sets a newOkHttpClient
instance to be used for API invocations by this BaseService instance.- Parameters:
client
- the newOkHttpClient
instance
-
isJsonMimeType
public static boolean isJsonMimeType(java.lang.String mimeType)
Returns true iff the specified mimeType indicates a JSON-related content type. (e.g. application/json, application/json-patch+json, application/merge-patch+json, etc.).- Parameters:
mimeType
- the mimetype to consider- Returns:
- true if the mimeType indicates a JSON-related content type
-
isJsonPatchMimeType
public static boolean isJsonPatchMimeType(java.lang.String mimeType)
Returns true iff the specified mimeType indicates a "Json Patch"-related content type. (e.g. application/json-patch+json)).- Parameters:
mimeType
- the mimetype to consider- Returns:
- true if the mimeType indicates a JSON-related content type
-
constructServiceUrl
public static java.lang.String constructServiceUrl(java.lang.String parameterizedUrl, java.util.Map<java.lang.String,java.lang.String> defaultUrlVariables, java.util.Map<java.lang.String,java.lang.String> providedUrlVariables)
Constructs a service URL by formatting a parameterized URL.- Parameters:
parameterizedUrl
- URL that contains variable placeholders, e.g. "{scheme}://ibm.com".defaultUrlVariables
- map from variable names to default values. Each variable in the parameterized URL must have a default value specified in this map.providedUrlVariables
- map from variable names to desired values. If a variable is not provided in this map, the default variable value will be used instead.- Returns:
- the formatted URL with all variable placeholders replaced by values.
-
constructServiceURL
@Deprecated public static java.lang.String constructServiceURL(java.lang.String parameterizedUrl, java.util.Map<java.lang.String,java.lang.String> defaultUrlVariables, java.util.Map<java.lang.String,java.lang.String> providedUrlVariables)
Deprecated.use constructServiceUrl() instead.Constructs a service URL by formatting a parameterized URL.- Parameters:
parameterizedUrl
- URL that contains variable placeholders, e.g. "{scheme}://ibm.com".defaultUrlVariables
- map from variable names to default values. Each variable in the parameterized URL must have a default value specified in this map.providedUrlVariables
- map from variable names to desired values. If a variable is not provided in this map, the default variable value will be used instead.- Returns:
- the formatted URL with all variable placeholders replaced by values.
-
configureClient
public void configureClient(HttpConfigOptions options)
Configures the currently-configuredOkHttpClient
instance based on the passed-in options.- Parameters:
options
- theHttpConfigOptions
object for modifying the client
-
getName
public java.lang.String getName()
Gets the name.- Returns:
- the name
-
getEndPoint
@Deprecated public java.lang.String getEndPoint()
Deprecated.Use getServiceURL() instead.Gets the API end point.- Returns:
- the API end point
-
setEndPoint
@Deprecated public void setEndPoint(java.lang.String endPoint)
Deprecated.Use setServiceURL() instead.Sets the end point.- Parameters:
endPoint
- the new end point. Will be ignored if empty or null
-
getDefaultHeaders
public okhttp3.Headers getDefaultHeaders()
Returns the set of default headers current set on this BaseService instance.- Returns:
- the Headers object containing the default headers.
-
setDefaultHeaders
public void setDefaultHeaders(java.util.Map<java.lang.String,java.lang.String> headers)
Set the default headers to be used on every HTTP request.- Parameters:
headers
- name value pairs of headers
-
getAuthenticator
public Authenticator getAuthenticator()
Returns the Authenticator instance currently set on this BaseService instance.- Returns:
- the Authenticator set on this BaseService
-
setServiceUrl
public void setServiceUrl(java.lang.String serviceUrl)
Set the service URL (the base URL for the service instance).- Parameters:
serviceUrl
- the new service URL value
-
getServiceUrl
public java.lang.String getServiceUrl()
Returns the service URL value associated with this service instance.- Returns:
- the service URL
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-