java.lang.Object
com.sap.cloud.sdk.services.openapi.apiclient.ApiClient

public final class ApiClient extends Object
Used by the OpenAPI VDM to access HTTP-related information, such as the target URL of the headers.
  • Constructor Details

    • ApiClient

      public ApiClient()
      Creates an instance of this class. The rest template will ignore getters and setters names for Jackson properties.
    • ApiClient

      public ApiClient(@Nonnull org.springframework.web.client.RestTemplate restTemplate)
      Creates an instance of this class given an instance of RestTemplate.
      Parameters:
      restTemplate - An instance of RestTemplate
    • ApiClient

      public ApiClient(@Nonnull Destination destination)
      Creates an instance of this class given an instance of Destination. The rest template will ignore getters and setters names for Jackson properties.
      Parameters:
      destination - An instance of Destination
  • Method Details

    • getBasePath

      @Nonnull public String getBasePath()
      Get the current base path
      Returns:
      String the base path
    • setBasePath

      @Nonnull public ApiClient setBasePath(@Nonnull String basePath)
      Set the base path, which should include the host
      Parameters:
      basePath - the base path
      Returns:
      ApiClient this client
    • getStatusCode

      public int getStatusCode()
      Gets the status code of the previous request
      Returns:
      HttpStatus the status code
    • getResponseHeaders

      @Nonnull public org.springframework.util.MultiValueMap<String,String> getResponseHeaders()
      Gets the response headers of the previous request
      Returns:
      MultiValueMap a map of response headers
    • getAuthentications

      @Nonnull public Map<String,Authentication> getAuthentications()
      Get authentications (key: authentication name, value: authentication).
      Returns:
      Map the currently configured authentication types
    • getAuthentication

      @Nonnull public Authentication getAuthentication(@Nonnull String authName)
      Get authentication for the given name.
      Parameters:
      authName - The authentication name
      Returns:
      The authentication, null if not found
    • setUsername

      public void setUsername(@Nonnull String username)
      Helper method to set username for the first HTTP basic authentication.
      Parameters:
      username - the username
    • setPassword

      public void setPassword(@Nonnull String password)
      Helper method to set password for the first HTTP basic authentication.
      Parameters:
      password - the password
    • setApiKey

      public void setApiKey(@Nonnull String apiKey)
      Helper method to set API key value for the first API key authentication.
      Parameters:
      apiKey - the API key
    • setApiKeyPrefix

      public void setApiKeyPrefix(@Nonnull String apiKeyPrefix)
      Helper method to set API key prefix for the first API key authentication.
      Parameters:
      apiKeyPrefix - the API key prefix
    • setUserAgent

      @Nonnull public ApiClient setUserAgent(@Nonnull String userAgent)
      Set the User-Agent header's value (by adding to the default header map).
      Parameters:
      userAgent - the user agent string
      Returns:
      ApiClient this client
    • addDefaultHeader

      @Nonnull public ApiClient addDefaultHeader(@Nonnull String name, @Nonnull String value)
      Add a default header.
      Parameters:
      name - The header's name
      value - The header's value
      Returns:
      ApiClient this client
    • isDebugging

      public boolean isDebugging()
      Check that whether debugging is enabled for this API client.
      Returns:
      boolean true if this client is enabled for debugging, false otherwise
    • getDateFormat

      @Nonnull public DateFormat getDateFormat()
      Get the date format used to parse/format date parameters.
      Returns:
      DateFormat format
    • setDateFormat

      @Nonnull public ApiClient setDateFormat(@Nonnull DateFormat dateFormat)
      Set the date format used to parse/format date parameters.
      Parameters:
      dateFormat - Date format
      Returns:
      API client
    • parseDate

      @Nonnull public Date parseDate(@Nonnull String str)
      Parse the given string into Date object.
      Parameters:
      str - the string to parse
      Returns:
      the Date parsed from the string
    • formatDate

      @Nonnull public String formatDate(@Nonnull Date date)
      Format the given Date object into string.
      Parameters:
      date - the date to format
      Returns:
      the formatted date as string
    • parameterToString

      @Nonnull public String parameterToString(@Nonnull Object param)
      Format the given parameter object into string.
      Parameters:
      param - the object to convert
      Returns:
      String the parameter represented as a String
    • collectionPathParameterToString

      @Nonnull public String collectionPathParameterToString(@Nullable ApiClient.CollectionFormat collectionFormat, @Nonnull Collection<? extends CharSequence> values)
      Formats the specified collection path parameter to a string value.
      Parameters:
      collectionFormat - The collection format of the parameter.
      values - The values of the parameter.
      Returns:
      String representation of the parameter
    • parameterToMultiValueMap

      @Nonnull public org.springframework.util.MultiValueMap<String,String> parameterToMultiValueMap(@Nullable ApiClient.CollectionFormat collectionFormat, @Nullable String name, @Nullable Object value)
      Converts a parameter to a MultiValueMap for use in REST requests
      Parameters:
      collectionFormat - The format to convert to
      name - The name of the parameter
      value - The parameter's value Can be Map,Collection or also be a generic Object
      Returns:
      a Map containing the String value(s) of the input parameter
    • isJsonMime

      public boolean isJsonMime(@Nonnull String mediaType)
      Check if the given String is a JSON MIME.
      Parameters:
      mediaType - the input MediaType
      Returns:
      boolean true if the MediaType represents JSON, false otherwise
    • isJsonMime

      public boolean isJsonMime(@Nonnull org.springframework.http.MediaType mediaType)
      Check if the given MIME is a JSON MIME. JSON MIME examples: application/json application/json; charset=UTF8 APPLICATION/JSON
      Parameters:
      mediaType - the input MediaType
      Returns:
      boolean true if the MediaType represents JSON, false otherwise
    • isProblemJsonMime

      public boolean isProblemJsonMime(@Nonnull String mediaType)
      Check if the given String is a Problem JSON MIME (RFC-7807).
      Parameters:
      mediaType - the input MediaType
      Returns:
      boolean true if the MediaType represents Problem JSON, false otherwise
    • selectHeaderAccept

      @Nullable public List<org.springframework.http.MediaType> selectHeaderAccept(@Nonnull String[] accepts)
      Select the Accept header's value from the given accepts array: if JSON exists in the given array, use it; otherwise use all of them (joining into a string)
      Parameters:
      accepts - The accepts array to select from
      Returns:
      List The list of MediaTypes to use for the Accept header
    • selectHeaderContentType

      @Nonnull public org.springframework.http.MediaType selectHeaderContentType(@Nonnull String[] contentTypes)
      Select the Content-Type header's value from the given array: if JSON exists in the given array, use it; otherwise use the first one of the array.
      Parameters:
      contentTypes - The Content-Type array to select from
      Returns:
      MediaType The Content-Type header to use. If the given array is empty, JSON will be used.
    • invokeAPI

      @Nullable public <T> T invokeAPI(@Nonnull String path, @Nonnull org.springframework.http.HttpMethod method, @Nullable org.springframework.util.MultiValueMap<String,String> queryParams, @Nullable Object body, @Nullable org.springframework.http.HttpHeaders headerParams, @Nullable org.springframework.util.MultiValueMap<String,Object> formParams, @Nullable List<org.springframework.http.MediaType> accept, @Nullable org.springframework.http.MediaType contentType, @Nullable String[] authNames, @Nonnull org.springframework.core.ParameterizedTypeReference<T> returnType) throws OpenApiRequestException
      Invoke API by sending HTTP request with the given options.
      Type Parameters:
      T - the return type to use
      Parameters:
      path - The sub-path of the HTTP URL
      method - The request method
      queryParams - The query parameters
      body - The request body object
      headerParams - The header parameters
      formParams - The form parameters
      accept - The request's Accept header
      contentType - The request's Content-Type header
      authNames - The authentications to apply
      returnType - The return type into which to deserialize the response
      Returns:
      The response body in chosen type
      Throws:
      OpenApiRequestException - Thrown in case an exception occurs during invocation of the REST API