Class ApiClient
java.lang.Object
com.sap.cloud.sdk.services.openapi.apache.ApiClient
API client for executing HTTP requests using Apache HttpClient 5.
-
Method Summary
Modifier and TypeMethodDescriptionprotected booleanstatic ApiClientcreate()Creates an ApiClient instance with default configuration.static ApiClientcreate(Destination destination) Creates an ApiClient instance configured for the given destination.booleanstatic StringescapeString(String str) Escape the given string to be used as URL query value.static ApiClientfromHttpClient(org.apache.hc.client5.http.impl.classic.CloseableHttpClient httpClient) Creates an ApiClient instance from an existing HttpClient.inthashCode()<T> TinvokeAPI(String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, String urlQueryDeepObject, Object body, Map<String, String> headerParams, Map<String, Object> formParams, String accept, String contentType, com.fasterxml.jackson.core.type.TypeReference<T> returnType) Invoke API by sending HTTP request with the given options.parameterToPair(String name, Object value) Formats the specified query parameter to a list containing a singlePairobject.parameterToPairs(String collectionFormat, String name, Collection<?> value) Formats the specified collection query parameters to a list ofPairobjects.static StringparameterToString(Object param) Format the given parameter object into string.static StringselectHeaderAccept(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)static StringselectHeaderContentType(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.toString()withBasePath(String basePath) withObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) withOpenApiResponseListener(OpenApiResponseListener openApiResponseListener) withTempFolderPath(String tempFolderPath)
-
Method Details
-
fromHttpClient
@Nonnull public static ApiClient fromHttpClient(@Nonnull org.apache.hc.client5.http.impl.classic.CloseableHttpClient httpClient) Creates an ApiClient instance from an existing HttpClient.- Parameters:
httpClient- The HttpClient to use for requests- Returns:
- A new ApiClient instance
-
create
Creates an ApiClient instance configured for the given destination.- Parameters:
destination- The destination to use for requests- Returns:
- A new ApiClient instance configured with the destination
-
create
Creates an ApiClient instance with default configuration.- Returns:
- A new ApiClient instance
-
parameterToString
Format the given parameter object into string.- Parameters:
param- Object- Returns:
- Object in string format
-
parameterToPair
Formats the specified query parameter to a list containing a singlePairobject.Note that
valuemust not be a collection.- Parameters:
name- The name of the parameter.value- The value of the parameter.- Returns:
- A list containing a single
Pairobject.
-
parameterToPairs
@Nonnull public static List<Pair> parameterToPairs(@Nonnull String collectionFormat, @Nullable String name, @Nullable Collection<?> value) Formats the specified collection query parameters to a list ofPairobjects.Note that the values of each of the returned Pair objects are percent-encoded.
- Parameters:
collectionFormat- The collection format of the parameter.name- The name of the parameter.value- The value of the parameter.- Returns:
- A list of
Pairobjects.
-
selectHeaderAccept
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:
- The Accept header to use. If the given array is empty, null will be returned (not to set the Accept header explicitly).
-
selectHeaderContentType
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:
- The Content-Type header to use. If the given array is empty, or matches "any", JSON will be used.
-
escapeString
Escape the given string to be used as URL query value.- Parameters:
str- String- Returns:
- Escaped string
-
invokeAPI
@Beta @Nullable public <T> T invokeAPI(@Nonnull String path, @Nonnull String method, @Nullable List<Pair> queryParams, @Nullable List<Pair> collectionQueryParams, @Nullable String urlQueryDeepObject, @Nullable Object body, @Nonnull Map<String, String> headerParams, @Nonnull Map<String, throws OpenApiRequestExceptionObject> formParams, @Nullable String accept, @Nonnull String contentType, @Nonnull com.fasterxml.jackson.core.type.TypeReference<T> returnType) Invoke API by sending HTTP request with the given options.- Type Parameters:
T- Type- Parameters:
path- The sub-path of the HTTP URLmethod- The request method, one of "GET", "POST", "PUT", and "DELETE"queryParams- The query parameterscollectionQueryParams- The collection query parametersurlQueryDeepObject- A URL query string for deep object parametersbody- The request body object - if it is not binary, otherwise nullheaderParams- The header parametersformParams- The form parametersaccept- The request's Accept headercontentType- The request's Content-Type headerreturnType- Return type- Returns:
- The response body in type of string
- Throws:
OpenApiRequestException- API exception
-
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-
withBasePath
- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
getBasePath
-
withObjectMapper
@Nonnull @Beta public ApiClient withObjectMapper(@Nonnull com.fasterxml.jackson.databind.ObjectMapper objectMapper) - Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withTempFolderPath
- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withOpenApiResponseListener
@Nonnull @Beta public ApiClient withOpenApiResponseListener(@Nullable OpenApiResponseListener openApiResponseListener) - Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-