Class RestClient
java.lang.Object
org.jdrupes.keycloak.moodleauth.moodle.RestClient
- All Implemented Interfaces:
AutoCloseable
A class for invoking REST services.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final com.fasterxml.jackson.databind.ObjectMapper -
Constructor Summary
ConstructorsConstructorDescriptionRestClient(URI uri) Instantiates a new rest client.RestClient(URI uri, Map<String, Object> defaultParams) Instantiates a new rest client. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static StringencodeData(Map<String, Object> data) Encodes the map following the non-standard conventions of PHP’shttp_build_querystatic StringUsed byencodeData(Map)and recursively invoked as required.<T> TInvoke a request with the parameters specified.setDefaultParams(Map<String, Object> params) Sets the default params.uri()
-
Field Details
-
mapper
-
-
Constructor Details
-
RestClient
Instantiates a new rest client.- Parameters:
uri- the uridefaultParams- the default params
-
RestClient
Instantiates a new rest client.- Parameters:
uri- the uri
-
-
Method Details
-
setUri
- Parameters:
uri- the uri to set
-
uri
- Returns:
- the uri
-
setDefaultParams
Sets the default params.- Parameters:
params- the params- Returns:
- the rest client
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
invoke
public <T> T invoke(Class<T> resultType, Map<String, Object> queryParams, Map<String, throws IOExceptionObject> data) Invoke a request with the parameters specified.- Type Parameters:
T- the generic type- Parameters:
resultType- the result typequeryParams- parameters to be added to the querydata- to be send in the body- Returns:
- the result
- Throws:
IOException- Signals that an I/O exception has occurred.
-
encodeData
Encodes the map following the non-standard conventions of PHP’shttp_build_query- Parameters:
data- the data- Returns:
- the query string
-
encodeStream
Used byencodeData(Map)and recursively invoked as required.- Parameters:
data- a stream of entrieskeyBase- the key base ofnullfor the top-lebel invocation- Returns:
- the query string
-