Package com.avoka.tm.svc
Class RestCallSvc
- java.lang.Object
-
- com.avoka.tm.svc.RestCallSvc
-
public class RestCallSvc extends Object
Provides a wrapper class for
HttpRequestclass 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:
HttpRequest
-
-
Constructor Summary
Constructors Constructor Description RestCallSvc()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpRequestbuildRequest(RestCFG restCFG)Return a new HttpRequest object based the RestCFG object config.HttpRequestbuildRequest(RestCFG restCFG, Map<String,Object> modelMap)Return a new HttpRequest object based the RestCFG object config.HttpRequestbuildRequestBasedJson(String jsonCFG)Return a new HttpRequest object based the Json config.HttpRequestbuildRequestBasedJson(String jsonCFG, Map<String,Object> modelMap)Return a new HttpRequest object based the Json config.
-
-
-
Method Detail
-
buildRequest
public HttpRequest buildRequest(RestCFG restCFG)
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
public HttpRequest buildRequest(RestCFG restCFG, Map<String,Object> modelMap)
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
public HttpRequest buildRequestBasedJson(String jsonCFG)
Return a new HttpRequest object based the Json config.
-
buildRequestBasedJson
public HttpRequest buildRequestBasedJson(String jsonCFG, Map<String,Object> modelMap)
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.
-
-