public class ApiInvoker
extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
ApiInvoker.CollectionFormat |
| Constructor and Description |
|---|
ApiInvoker()
Constructs a new empty ApiInvoker instance
|
| Modifier and Type | Method and Description |
|---|---|
ApiInvoker |
addDefaultHeader(String name,
String value)
Add a default header.
|
protected void |
addHeadersToRequest(HttpHeaders headers,
RequestEntity.BodyBuilder requestBuilder)
Add headers to the request that is being built
|
String |
formatDate(Date date)
Format the given Date object into string.
|
DateFormat |
getDateFormat()
Get the date format used to parse/format date parameters.
|
MultiValueMap<String,String> |
getResponseHeaders()
Gets the response headers of the previous request
|
HttpStatus |
getStatusCode()
Gets the status code of the previous request
|
<T> T |
invokeAPI(InvokerConfig config,
String path,
HttpMethod method,
MultiValueMap<String,String> queryParams,
Object body,
HttpHeaders headerParams,
MultiValueMap<String,Object> formParams,
List<MediaType> accept,
MediaType contentType,
ParameterizedTypeReference<T> returnType)
Invokes API service end point with supplied parameters.
|
boolean |
isJsonMime(MediaType mediaType)
Check if the given MIME is a JSON MIME.
|
boolean |
isJsonMime(String mediaType)
Check if the given
String is a JSON MIME. |
MultiValueMap<String,String> |
parameterToMultiValueMap(ApiInvoker.CollectionFormat collectionFormat,
String name,
Object value)
Converts a parameter to a
MultiValueMap for use in REST requests |
String |
parameterToString(Object param)
Converts different types of parameters to string
|
Date |
parseDate(String dateString)
Converts date string to date objects
|
protected Object |
selectBody(Object obj,
MultiValueMap<String,Object> formParams,
MediaType contentType)
Select the body to use for the request
|
List<MediaType> |
selectHeaderAccept(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)
|
MediaType |
selectHeaderContentType(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.
|
ApiInvoker |
setDateFormat(DateFormat dateFormat)
Set the date format used to parse/format date parameters.
|
public HttpStatus getStatusCode()
public MultiValueMap<String,String> getResponseHeaders()
public ApiInvoker addDefaultHeader(String name, String value)
name - The header's namevalue - The header's valuepublic DateFormat getDateFormat()
public ApiInvoker setDateFormat(DateFormat dateFormat)
dateFormat - Date formatpublic Date parseDate(String dateString)
throws MindsphereException
dateString - String representation of dateMindsphereException - thrown if an exception is encountered during conversionpublic String formatDate(Date date)
date - The date object to be converted to stringpublic String parameterToString(Object param)
param - Parameter as an object instancepublic MultiValueMap<String,String> parameterToMultiValueMap(ApiInvoker.CollectionFormat collectionFormat, String name, Object value)
MultiValueMap for use in REST requestscollectionFormat - The format to convert toname - The name of the parametervalue - The parameter's valuepublic boolean isJsonMime(String mediaType)
String is a JSON MIME.mediaType - the input MediaTypepublic boolean isJsonMime(MediaType mediaType)
mediaType - the input MediaTypepublic List<MediaType> selectHeaderAccept(String[] accepts)
accepts - The accepts array to select frompublic MediaType selectHeaderContentType(String[] contentTypes)
contentTypes - The Content-Type array to select fromprotected Object selectBody(Object obj,
MultiValueMap<String,Object> formParams,
MediaType contentType)
obj - the body objectformParams - the form parameterscontentType - the content type of the requestpublic <T> T invokeAPI(InvokerConfig config, String path, HttpMethod method, MultiValueMap<String,String> queryParams, Object body, HttpHeaders headerParams, MultiValueMap<String,Object> formParams, List<MediaType> accept, MediaType contentType, ParameterizedTypeReference<T> returnType) throws MindsphereException
config - InvokerConfig instancepath - Base path of service end pointmethod - Http method to be usedqueryParams - Query parameters supplied for the service end point callbody - Request body contentsheaderParams - Header parameters supplied for the service end point callformParams - Form parameters supplied for the service end point callaccept - Media Types acceptedcontentType - Content type of the requestreturnType - Response Type expectedMindsphereException - thrown if an error occurs while attempting to invoke the APIprotected void addHeadersToRequest(HttpHeaders headers,
RequestEntity.BodyBuilder requestBuilder)
headers - The headers to addrequestBuilder - The current request