Class RestApiClient

  • All Implemented Interfaces:
    ApiClient

    public class RestApiClient
    extends Object
    implements ApiClient
    Implementation of API client for http://sldn.softlayer.com/article/REST
    • Field Detail

      • 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()
      • setHttpClientFactory

        public void setHttpClientFactory​(HttpClientFactory httpClientFactory)
      • isLoggingEnabled

        public boolean isLoggingEnabled()
      • setLoggingEnabled

        public void setLoggingEnabled​(boolean loggingEnabled)
      • setJsonMarshallerFactory

        public void setJsonMarshallerFactory​(JsonMarshallerFactory jsonMarshallerFactory)
      • withCredentials

        public RestApiClient withCredentials​(String username,
                                             String apiKey)
        Description copied from interface: ApiClient
        Set the username and API key credentials. This is required for most service methods.
        Specified by:
        withCredentials in interface ApiClient
        Returns:
        This instance
      • withBearerToken

        public RestApiClient withBearerToken​(String token)
        Description copied from interface: ApiClient
        Uses a HTTP Bearer token for authentication instead of API key.
        Specified by:
        withBearerToken in interface ApiClient
        Returns:
        This instance
      • writeParameterHttpBody

        protected void writeParameterHttpBody​(Object[] params,
                                              OutputStream out)
      • getHttpMethodFromMethodName

        protected String getHttpMethodFromMethodName​(String methodName)
      • 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

        protected void logRequest​(String httpMethod,
                                  String url,
                                  Object[] params)
      • logResponse

        protected void logResponse​(String url,
                                   int statusCode,
                                   String body)
      • createService

        public <S extends Service> S createService​(Class<S> serviceClass,
                                                   String id)
        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 interface ApiClient