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.ObjectAbstracts common functionality of various IBM Cloud services.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringPROPNAME_DISABLE_SSLstatic java.lang.StringPROPNAME_ENABLE_GZIPstatic java.lang.StringPROPNAME_ENABLE_RETRIESstatic java.lang.StringPROPNAME_MAX_RETRIESstatic java.lang.StringPROPNAME_RETRY_INTERVALstatic java.lang.StringPROPNAME_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 voidconfigureClient(HttpConfigOptions options)Configures the currently-configuredOkHttpClientinstance based on the passed-in options.voidconfigureService(java.lang.String serviceName)static java.lang.StringconstructServiceUrl(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.StringconstructServiceURL(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.voiddisableRetries()Disables the retries for the HTTP requests.voidenableGzipCompression(boolean shouldEnableCompression)Enables gzip compression of requests bodies for the current client.voidenableRetries(int maxRetries, int maxRetryInterval)Enables the retries for the HTTP requests.AuthenticatorgetAuthenticator()Returns the Authenticator instance currently set on this BaseService instance.okhttp3.OkHttpClientgetClient()Returns the currently-configuredOkHttpClientinstance.okhttp3.HeadersgetDefaultHeaders()Returns the set of default headers current set on this BaseService instance.java.lang.StringgetEndPoint()Deprecated.Use getServiceURL() instead.java.lang.StringgetName()Gets the name.java.lang.StringgetServiceUrl()Returns the service URL value associated with this service instance.static booleanisJsonMimeType(java.lang.String mimeType)Returns true iff the specified mimeType indicates a JSON-related content type.static booleanisJsonPatchMimeType(java.lang.String mimeType)Returns true iff the specified mimeType indicates a "Json Patch"-related content type.voidsetClient(okhttp3.OkHttpClient client)Sets a newOkHttpClientinstance to be used for API invocations by this BaseService instance.voidsetDefaultHeaders(java.util.Map<java.lang.String,java.lang.String> headers)Set the default headers to be used on every HTTP request.voidsetEndPoint(java.lang.String endPoint)Deprecated.Use setServiceURL() instead.voidsetServiceUrl(java.lang.String serviceUrl)Set the service URL (the base URL for the service instance).java.lang.StringtoString()
-
-
-
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-configuredOkHttpClientinstance.- Returns:
- the
OkHttpClientinstance
-
setClient
public void setClient(okhttp3.OkHttpClient client)
Sets a newOkHttpClientinstance to be used for API invocations by this BaseService instance.- Parameters:
client- the newOkHttpClientinstance
-
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-configuredOkHttpClientinstance based on the passed-in options.- Parameters:
options- theHttpConfigOptionsobject 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:
toStringin classjava.lang.Object
-
-