Example: Invoking a Consumer Application Service
The following example demonstrates how the consumer application service with IB Service Name CONSUME_EXAMPLE is invoked:
Note:
See ServiceAPI Methods and properties for information on all methods available and additional information on the methods using in the example People Code below.
The PeopleCode Reference Guide for Application Services are defined under ServiceAPI methods and Properties for both Provider and Consumer Application Services. Since the variable name assigned (ServiceAPI) is used for Provider Application Class implementation, for Consume PeopleCode the MessageAPI is referred to the ServiceAPI for documentation purposes.
import PTCBAPPLSVCDEFN:ApplicationServiceBase; /* Import the Application Service Base class */
import PTCBAPPLSVCDEFN:MessageAPI; /* used to get the ServiceAPI object */
Local PTCBAPPLSVCDEFN:ApplicationServiceBase &base;
Local PTCBAPPLSVCDEFN:MessageAPI &ServiceAPI;
&base = create PTCBAPPLSVCDEFN:ApplicationServiceBase(); /* instantiate and return the base object */
/* Returns the ServiceAPI based on the Application Service keys (Application Service name,
Root Resource, URI Index, and REST Method) */
&ServiceAPI = &base.createService("CONSUME_EXAMPLE", "conroot", 1, %AppService_HTTP_GET);
/* Populate any Template Parameters based on the URI Index */
&ServiceAPI.setTemplateParameter("flightNumber", "12X20", False);
&ServiceAPI.setTemplateParameter("pilots", "DogDish", True);
&ServiceAPI.setTemplateParameter("pilots", "Hammer", True);
/* use the &ServiceAPI to populate any Input Parameters */
/* User Exception Option which when set if an error occurred will not terminate
the actual Synchronous Transaction but will allow the developer to read the error and continue processing. */
&ServiceAPI.UserException = True;
/* allows the developer to override the entire URL used to invoke the Application Service */
rem &ServiceAPI.SetOverrideURL(http://xxxxxxx:5000/PSIGW/RESTListeningConnector/T60KAC11/flightdata.v1/flight);
/* Invokes the Application Service via an Integration Broker SyncRequest */
&base.invokeService();
Local integer &RespCode;
Local string &RawData;
/* check for exception if User Exception set */
If &ServiceAPI.ResponseFailed Then
&RespCode = &ServiceAPI.HttpResponseCode; /* read the HTTP Response Code returned by the Provider */
Local string &RespException = &ServiceAPI.ResponseException; /* Read the Response Exception returned as a result of the invocation */
&RawData = &ServiceAPI.getOutputContentData(); /* read any actual data returned by the Provider */
Else
/* use the &ServiceAPI to read the data returned by the Provider (Output Parameters) */
Local string &Program = &ServiceAPI.getOutputParameter("flightProgram");
Local string &ACType = &ServiceAPI.getOutputParameter("aircraftType");
&RespCode = &ServiceAPI.HttpResponseCode; /* read the HTTP Response Code returned by the Provider */
&RawData = &ServiceAPI.getOutputContentData(); /* optionally read actual raw data returned by the Provider */
End-If;