Class RestCallSvc

java.lang.Object
com.avoka.tm.svc.RestCallSvc

public class RestCallSvc extends Object

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 Details

    • RestCallSvc

      public RestCallSvc()
  • Method Details

    • 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.
      Parameters:
      jsonCFG - the Json config which includes all the details of HttpRequest. This object maps to an object of class RestCFG
      Returns:
      a new HttpRequest object
      See Also:
    • 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.
      Parameters:
      jsonCFG - the Json config which includes all the details of HttpRequest. This object maps to an object of class RestCFG
      modelMap - the model key name and value which will merge with the template using Velocity engine.
      Returns:
      a new HttpRequest object
      See Also: