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 StringBASE_SERVICE_URLThe API URL that should be used when connecting via the softlayer/classic infrastructure private network.static StringBASE_URLThe 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.StringgetBaseUrl()HttpCredentialsgetCredentials()Returns the HTTP Authorization headerprotected StringgetFullUrl(String serviceName, String methodName, String id, ResultLimit resultLimit, String maskString)Get the full REST URL required to make a request.HttpClientFactorygetHttpClientFactory()protected StringgetHttpMethodFromMethodName(String methodName)JsonMarshallerFactorygetJsonMarshallerFactory()booleanisLoggingEnabled()protected voidlogRequest(String httpMethod, String url, Object[] params)protected voidlogResponse(String url, int statusCode, String body)voidsetHttpClientFactory(HttpClientFactory httpClientFactory)voidsetJsonMarshallerFactory(JsonMarshallerFactory jsonMarshallerFactory)voidsetLoggingEnabled(boolean loggingEnabled)RestApiClientwithBearerToken(String token)Uses a HTTP Bearer token for authentication instead of API key.RestApiClientwithCredentials(String username, String apiKey)Set the username and API key credentials.RestApiClientwithHttpClientFactory(HttpClientFactory httpClientFactory)RestApiClientwithJsonMarshallerFactory(JsonMarshallerFactory jsonMarshallerFactory)RestApiClientwithLoggingEnabled()Enables logging for client API callsprotected voidwriteParameterHttpBody(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:ApiClientEnables logging for client API calls- Specified by:
withLoggingEnabledin interfaceApiClient- Returns:
- This instance
-
getJsonMarshallerFactory
-
setJsonMarshallerFactory
-
withJsonMarshallerFactory
-
withCredentials
Description copied from interface:ApiClientSet the username and API key credentials. This is required for most service methods.- Specified by:
withCredentialsin interfaceApiClient- Returns:
- This instance
-
withBearerToken
Description copied from interface:ApiClientUses a HTTP Bearer token for authentication instead of API key.- Specified by:
withBearerTokenin interfaceApiClient- Returns:
- This instance
-
getCredentials
Description copied from interface:ApiClientReturns the HTTP Authorization header- Specified by:
getCredentialsin 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:ApiClientGet 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:
createServicein interfaceApiClient
-