public abstract class BaseService
extends java.lang.Object
Modifier and Type | Field and 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 and Description |
---|
BaseService(java.lang.String name,
Authenticator authenticator)
Instantiates a new IBM Cloud service.
|
Modifier and Type | Method and Description |
---|---|
void |
configureClient(HttpConfigOptions options)
Configures the currently-configured
OkHttpClient 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-configured
OkHttpClient 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 new
OkHttpClient 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() |
public static final java.lang.String PROPNAME_URL
public static final java.lang.String PROPNAME_DISABLE_SSL
public static final java.lang.String PROPNAME_ENABLE_GZIP
public static final java.lang.String PROPNAME_ENABLE_RETRIES
public static final java.lang.String PROPNAME_MAX_RETRIES
public static final java.lang.String PROPNAME_RETRY_INTERVAL
public BaseService(java.lang.String name, Authenticator authenticator)
name
- the service nameauthenticator
- an Authenticator instance that will perform authentication on outgoing requestspublic void configureService(java.lang.String serviceName)
public void enableGzipCompression(boolean shouldEnableCompression)
shouldEnableCompression
- the value used to set the enableGzipCompression HttpConfigOptionpublic void enableRetries(int maxRetries, int maxRetryInterval)
maxRetries
- the value of the maximum number of retriesmaxRetryInterval
- the maximum time to wait between retries in secondspublic void disableRetries()
public okhttp3.OkHttpClient getClient()
OkHttpClient
instance.OkHttpClient
instancepublic void setClient(okhttp3.OkHttpClient client)
OkHttpClient
instance to be used for API invocations by this BaseService instance.client
- the new OkHttpClient
instancepublic static boolean isJsonMimeType(java.lang.String mimeType)
mimeType
- the mimetype to considerpublic static boolean isJsonPatchMimeType(java.lang.String mimeType)
mimeType
- the mimetype to considerpublic 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)
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.@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)
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.public void configureClient(HttpConfigOptions options)
OkHttpClient
instance based on the passed-in options.options
- the HttpConfigOptions
object for modifying the clientpublic java.lang.String getName()
@Deprecated public java.lang.String getEndPoint()
@Deprecated public void setEndPoint(java.lang.String endPoint)
endPoint
- the new end point. Will be ignored if empty or nullpublic okhttp3.Headers getDefaultHeaders()
public void setDefaultHeaders(java.util.Map<java.lang.String,java.lang.String> headers)
headers
- name value pairs of headerspublic Authenticator getAuthenticator()
public void setServiceUrl(java.lang.String serviceUrl)
serviceUrl
- the new service URL valuepublic java.lang.String getServiceUrl()
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2022 IBM Cloud Developer Experience. All rights reserved.