Package com.avoka.tm.svc
Class RestCallSvc
java.lang.Object
com.avoka.tm.svc.RestCallSvc
Provides a wrapper class for HttpRequest
class to create a HttpRequest by getting request details in Json format or an object of RestCFG.
All the default values are the same as HttpRequest.
Examples
The example below create a request by getting request details in Json format and send the request.
import com.avoka.tm.svc.RestCallSvc; import com.avoka.tm.http.* import com.avoka.tm.vo.* import com.avoka.tm.query.* String jSONFile = "{\n" + "\"methodType\": \"POST\",\n" + "\"restURL\": \"http://localhost:9080/manager/secure/rest/fluentapi/txnquery/listValues\",\n" + "\"authorisation\": { \n" + " \"type\": \"BASIC\",\n" + " \"userName\": \"test\",\n" + " \"password\": \"test\" } ,\n" + "\"headers\": {\"Content-Type\": \"application/json\"} ,\n" + "\"message\": \"{ \\\"setId\\\" : \\\"\$Txn.id\\\"}\"\n" + "}"; Txn txn = new TxnQuery().firstValue(); if (txn != null) { HttpResponse response = new RestCallSvc().buildRequestBasedJson(jSONFile, Map.of("Txn",(Object) txn)).execute(); print response.getTextContent().toString(); }
The example below create a request by getting request details as an object of RestCFG and send the request.
import com.avoka.tm.svc.RestCallSvc; import com.avoka.tm.http.* import com.avoka.tm.vo.* import com.avoka.tm.query.* Txn txn = new TxnQuery().firstValue(); RestCFG restCFG= new RestCFG(); restCFG.setRestURL("http://localhost:9080/manager/secure/rest/fluentapi/txnquery/listValues"); restCFG.setMethodType(RestCFG.MethodType.POST); RestCFG.Authorisation authorisation = new RestCFG.Authorisation(); authorisation.setType(RestCFG.Authorisation.AuthorisationType.BASIC); authorisation.setUserName("test"); authorisation.setPassword("test"); restCFG.setAuthorisation(authorisation); restCFG.setHeaders(Map.of("Content-Type", "application/json")); restCFG.setMessage("{ \"setId\" : \"\$Txn.id\"}"); if (txn != null) { HttpResponse response = new RestCallSvc().buildRequest(restCFG, Map.of("Txn",(Object) txn)).execute(); print response.getTextContent().toString(); }
- Since:
- 22.4.0
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuildRequest
(RestCFG restCFG) Return a new HttpRequest object based the RestCFG object config.buildRequest
(RestCFG restCFG, Map<String, Object> modelMap) Return a new HttpRequest object based the RestCFG object config.buildRequestBasedJson
(String jsonCFG) Return a new HttpRequest object based the Json config.buildRequestBasedJson
(String jsonCFG, Map<String, Object> modelMap) Return a new HttpRequest object based the Json config.
-
Constructor Details
-
RestCallSvc
public RestCallSvc()
-
-
Method Details
-
buildRequest
Return a new HttpRequest object based the RestCFG object config.- Parameters:
restCFG
- the RestCFG object which includes all the details of HttpRequest.- Returns:
- a new HttpRequest object
-
buildRequest
Return a new HttpRequest object based the RestCFG object config.- Parameters:
restCFG
- the RestCFG object which includes all the details of HttpRequest.modelMap
- the model key name and value which will merge with message and parameters using Velocity engine.- Returns:
- a new HttpRequest object
-
buildRequestBasedJson
Return a new HttpRequest object based the Json config. -
buildRequestBasedJson
Return a new HttpRequest object based the Json config. It will merge the given model key name and value with the template using Velocity engine.
-