Creating Application Class

For Provider Application Services, create an application class extending the PTCBAPPLSVCDEFN:ApplicationServiceBase application class and then implement the invokeService() method to define your application logic.

Use the %This.ServiceAPI property to read and write parameters and other Application Services metadata.

The following methods are used in the example code. This list does not include all the Application Services methods. See ServiceAPI Methods for information on all methods available and additional information on the methods listed below.

Method

Use this method to

getInputParameter

retrieve input value based on parameter defined on the application service.

getOutputParameter

retrieve output value based on parameter.

getOutputRow

retrieve the specified output message row based on the index.

getTemplateParameter

retrieve template value based on parameter defined on the application service.

InsertOutputRow

insert an empty message row.

setInputParameter

set input value based on parameter defined on the application service.

setOutputParameter

set output value based on parameter defined on the application service.

setResponseHeader

set the response header value based on header defined on the application service.

The following properties are used in the example code. This list does not include all the Application Services properties. See ServiceAPI Properties for information on all methods available and additional information on the properties listed below.

Property

Use this property to

HttpMethod

return the HTTP method that was invoked for the transaction.

InputRows

get values on the specified row.

OutputRows

set values on the specified row.

ResultState

set the result state to be returned for the request.

URIIndex

return the URI index that is invoked as defined on the application service.

Example Application Class for GET Method

The Application Service for this example has the following:

  • URI Template is band{instrument}/{timein}

  • Method is GET with Multi Row Output

    Note: The code for single row output is shown commented out.

  • Output Parameters are:

    • instrument

    • numPlayers

    • playdate

    • timeout

import PTCBAPPLSVCDEFN:ApplicationServiceBase;

class EXAMPLE1 extends PTCBAPPLSVCDEFN:ApplicationServiceBase
   method invokeService();
end-class;

method invokeService
   /+ Extends/implements PTCBAPPLSVCDEFN:ApplicationServiceBase.invokeService +/
   Local string &Inst, &httpMethod, &name;
   Local integer &UriIndex, &age;
   Local time &timein;
   Local date &datein;
   
   &httpMethod = %This.ServiceAPI.HttpMethod;
   &UriIndex = %This.ServiceAPI.URIIndex;
   
   If &httpMethod = "GET" Then
      If &UriIndex = 1 Then
         /****Fetching value of template parameters*/
         &Inst = %This.ServiceAPI.getTemplateParameter("instrument");
         &timein = %This.ServiceAPI.getTemplateParameter("timein");
         
         <* Setting values for output parameters single row 
         %This.ServiceAPI.setOutputParameter("numPlayers", 10);
         %This.ServiceAPI.setOutputParameter("instrument", &Inst);
         %This.ServiceAPI.setOutputParameter("playdate", %Date);
         %This.ServiceAPI.setOutputParameter("timeout", &timein); *>
         
         
         /****setting values for output parameters (multi-row) */
         %This.ServiceAPI.insertOutputRow();
         %This.ServiceAPI.OutputRows [1].setParameter("numPlayers", 10);
         %This.ServiceAPI.OutputRows [1].setParameter("instrument", &Inst);
         %This.ServiceAPI.OutputRows [1].setParameter("playdate", %Date);
         %This.ServiceAPI.OutputRows [1].setParameter("timeout", &timein);
         
         %This.ServiceAPI.insertOutputRow();
         %This.ServiceAPI.OutputRows [2].setParameter("numPlayers", 6);
         %This.ServiceAPI.OutputRows [2].setParameter("instrument", &Inst);
         %This.ServiceAPI.OutputRows [2].setParameter("playdate", %Date);
         %This.ServiceAPI.OutputRows [2].setParameter("timeout", &timein);
         
         /****Setting Value of Result States to denote logical conclusion for
the service execution */
         %This.ServiceAPI.ResultState = "SUCCESS - PLAY MUSIC";
         
      End-If;
   End-If;
end-method;

Example Application Classes that includes GET and POST

The Application Service for this example has the following:

  • URI Template is band{instrument}/{musicCode}

  • GET method has Multi Row Output with following output parameters:

    • instrument

    • numPlayers

  • Post method Input parameters

    • instrument

    • player

  • POST method output parameters

    • results

    • tool

import PTCBAPPLSVCDEFN:ApplicationServiceBase;

class example2 extends PTCBAPPLSVCDEFN:ApplicationServiceBase
   method invokeService();
end-class;

method invokeService
   /+ Extends/implements PTCBAPPLSVCDEFN:ApplicationServiceBase.invokeService +/
   Local string &Inst, &Inst1, &httpMethod, &name, &headervalue, &results, &tool, &player;
   Local integer &UriIndex, &age;
   Local time &timein;
   Local date &datein;
   Local array of any &code;
   
   &httpMethod = %This.ServiceAPI.HttpMethod;
   &UriIndex = %This.ServiceAPI.URIIndex;
   
   If &httpMethod = "GET" Then
      If &UriIndex = 1 Then
         /****Fetching value of template parameters*/
         &Inst = %This.ServiceAPI.getTemplateParameter("instrument");
         rem &timein = %This.ServiceAPI.getTemplateParameter("timein");
         &code = %This.ServiceAPI.getTemplateParameter("musicCode");
         
         /****setting values for output parameters (multi-row) */
         %This.ServiceAPI.insertOutputRow();
         %This.ServiceAPI.OutputRows [1].setParameter("numPlayers", 10);
         %This.ServiceAPI.OutputRows [1].setParameter("instrument", &Inst);
         
         %This.ServiceAPI.insertOutputRow();
         %This.ServiceAPI.OutputRows [2].setParameter("numPlayers", 6);
         %This.ServiceAPI.OutputRows [2].setParameter("instrument", &Inst);
         
         
         /****Setting Value of Result States to denote logical conclusion for
the service execution */
         %This.ServiceAPI.ResultState = "SUCCESS - PLAY MUSIC";
         
      End-If;
   End-If;
   
   If &httpMethod = "POST" Then
      If &UriIndex = 1 Then
         
         /* read request header  */
         &headervalue = %This.ServiceAPI.getRequestHeaderValue("Accept-Language");
         
         
         /* set response header for location */
         %This.ServiceAPI.setResponseHeader("Type", "Woodwind");
         
         /****Fetching value of template parameters*/
         &Inst = %This.ServiceAPI.getTemplateParameter("instrument");
         &code = %This.ServiceAPI.getTemplateParameter("musicCode");
         
         /****Fetching values for multi-row input parameters*/
         &player = %This.ServiceAPI.InputRows [1].getParameter("player");
         &Inst = %This.ServiceAPI.InputRows [1].getParameter("instrument");
         
         &player = %This.ServiceAPI.InputRows [2].getParameter("player");
         &Inst1 = %This.ServiceAPI.InputRows [2].getParameter("instrument");
         
         /****setting values for output parameters (single row) */
         %This.ServiceAPI.setOutputParameter("results", "OK");
         %This.ServiceAPI.setOutputParameter("tool", "860");
         
         /****Setting Value of Result States to denote logical conclusion for
the service execution */
         %This.ServiceAPI.ResultState = "Success";
      End-If;
   End-If;
   
end-method;