Package com.softlayer.api
Class RestApiClient
java.lang.Object
com.softlayer.api.RestApiClient
- All Implemented Interfaces:
ApiClient
public class RestApiClient extends Object implements ApiClient
Implementation of API client for http://sldn.softlayer.com/article/REST
-
Field Summary
Fields Modifier and Type Field Description static String
BASE_SERVICE_URL
The API URL that should be used when connecting via the softlayer/classic infrastructure private network.static String
BASE_URL
The publically available API URL. -
Constructor Summary
Constructors Constructor Description RestApiClient()
Create a Rest client that uses the publically available API.RestApiClient(String baseUrl)
Create a Rest client with a custom URL. -
Method Summary
Modifier and Type Method Description <S extends Service>
ScreateService(Class<S> serviceClass, String id)
Get a service for the given sets of classes and optional ID.String
getBaseUrl()
HttpCredentials
getCredentials()
Returns the HTTP Authorization headerprotected String
getFullUrl(String serviceName, String methodName, String id, ResultLimit resultLimit, String maskString)
Get the full REST URL required to make a request.HttpClientFactory
getHttpClientFactory()
protected String
getHttpMethodFromMethodName(String methodName)
JsonMarshallerFactory
getJsonMarshallerFactory()
boolean
isLoggingEnabled()
protected void
logRequest(String httpMethod, String url, Object[] params)
protected void
logResponse(String url, int statusCode, String body)
void
setHttpClientFactory(HttpClientFactory httpClientFactory)
void
setJsonMarshallerFactory(JsonMarshallerFactory jsonMarshallerFactory)
void
setLoggingEnabled(boolean loggingEnabled)
RestApiClient
withBearerToken(String token)
Uses a HTTP Bearer token for authentication instead of API key.RestApiClient
withCredentials(String username, String apiKey)
Set the username and API key credentials.RestApiClient
withHttpClientFactory(HttpClientFactory httpClientFactory)
RestApiClient
withJsonMarshallerFactory(JsonMarshallerFactory jsonMarshallerFactory)
RestApiClient
withLoggingEnabled()
Enables logging for client API callsprotected void
writeParameterHttpBody(Object[] params, OutputStream out)
-
Field Details
-
BASE_URL
The publically available API URL.- See Also:
- Constant Field Values
-
BASE_SERVICE_URL
The API URL that should be used when connecting via the softlayer/classic infrastructure private network.- See Also:
- Constant Field Values
-
-
Constructor Details
-
RestApiClient
public RestApiClient()Create a Rest client that uses the publically available API. -
RestApiClient
Create a Rest client with a custom URL.- Parameters:
baseUrl
- The custom URL the REST client will use.
-
-
Method Details
-
getBaseUrl
-
getHttpClientFactory
-
setHttpClientFactory
-
withHttpClientFactory
-
isLoggingEnabled
public boolean isLoggingEnabled() -
setLoggingEnabled
public void setLoggingEnabled(boolean loggingEnabled) -
withLoggingEnabled
Description copied from interface:ApiClient
Enables logging for client API calls- Specified by:
withLoggingEnabled
in interfaceApiClient
- Returns:
- This instance
-
getJsonMarshallerFactory
-
setJsonMarshallerFactory
-
withJsonMarshallerFactory
-
withCredentials
Description copied from interface:ApiClient
Set the username and API key credentials. This is required for most service methods.- Specified by:
withCredentials
in interfaceApiClient
- Returns:
- This instance
-
withBearerToken
Description copied from interface:ApiClient
Uses a HTTP Bearer token for authentication instead of API key.- Specified by:
withBearerToken
in interfaceApiClient
- Returns:
- This instance
-
getCredentials
Description copied from interface:ApiClient
Returns the HTTP Authorization header- Specified by:
getCredentials
in interfaceApiClient
- Returns:
- This instance
-
writeParameterHttpBody
-
getHttpMethodFromMethodName
-
getFullUrl
protected String getFullUrl(String serviceName, String methodName, String id, ResultLimit resultLimit, String maskString)Get the full REST URL required to make a request.- Parameters:
serviceName
- The name of the API service.methodName
- The name of the method on the service to call.id
- The identifier of the object to make a call to, otherwise null if not making a request to a specific object.resultLimit
- The number of results to limit the request to.maskString
- The mask, in string form, to use on the request.- Returns:
- String
-
logRequest
-
logResponse
-
createService
Description copied from interface:ApiClient
Get a service for the given sets of classes and optional ID. It is not recommended to call this directly, but rather invoke the service method on the type class. E.g.Account.service(ApiClient)
.- Specified by:
createService
in interfaceApiClient
-