Package com.softlayer.api
Class RestApiClient
- java.lang.Object
-
- com.softlayer.api.RestApiClient
-
-
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
All Methods Instance Methods Concrete Methods 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 Detail
-
BASE_URL
public static final String BASE_URL
The publically available API URL.- See Also:
- Constant Field Values
-
BASE_SERVICE_URL
public static final String 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 Detail
-
RestApiClient
public RestApiClient()
Create a Rest client that uses the publically available API.
-
RestApiClient
public RestApiClient(String baseUrl)
Create a Rest client with a custom URL.- Parameters:
baseUrl- The custom URL the REST client will use.
-
-
Method Detail
-
getBaseUrl
public String getBaseUrl()
-
getHttpClientFactory
public HttpClientFactory getHttpClientFactory()
-
setHttpClientFactory
public void setHttpClientFactory(HttpClientFactory httpClientFactory)
-
withHttpClientFactory
public RestApiClient withHttpClientFactory(HttpClientFactory httpClientFactory)
-
isLoggingEnabled
public boolean isLoggingEnabled()
-
setLoggingEnabled
public void setLoggingEnabled(boolean loggingEnabled)
-
withLoggingEnabled
public RestApiClient withLoggingEnabled()
Description copied from interface:ApiClientEnables logging for client API calls- Specified by:
withLoggingEnabledin interfaceApiClient- Returns:
- This instance
-
getJsonMarshallerFactory
public JsonMarshallerFactory getJsonMarshallerFactory()
-
setJsonMarshallerFactory
public void setJsonMarshallerFactory(JsonMarshallerFactory jsonMarshallerFactory)
-
withJsonMarshallerFactory
public RestApiClient withJsonMarshallerFactory(JsonMarshallerFactory jsonMarshallerFactory)
-
withCredentials
public RestApiClient withCredentials(String username, String apiKey)
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
public RestApiClient withBearerToken(String token)
Description copied from interface:ApiClientUses a HTTP Bearer token for authentication instead of API key.- Specified by:
withBearerTokenin interfaceApiClient- Returns:
- This instance
-
getCredentials
public HttpCredentials getCredentials()
Description copied from interface:ApiClientReturns the HTTP Authorization header- Specified by:
getCredentialsin interfaceApiClient- Returns:
- This instance
-
writeParameterHttpBody
protected void writeParameterHttpBody(Object[] params, OutputStream out)
-
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
-
createService
public <S extends Service> S createService(Class<S> serviceClass, String id)
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
-
-