Creating a SOAP Service with PeopleTools using Document Objects

There are different approaches when exposing a web service. We can use a CI-based integration but it sometimes does not fill my needs. We can expose a web service using Document object which is a simple way to create XML/JSON documents.

Create a Document

Peopletools -> Document Builder

Add a new value. Choose Package+Document+Version. This will be used to create a message. Here you should create a structure with child objects and branches.

There will be two Documents: one for request message and other one for response.

Request message could have these fields (they don't need to match with dbfields!):

  • EMPLID
  • EMPL_RCD
  • SAL_ADMIN_PLAN
  • GRADE
  • STEP

Response message:

  • EMPLID
  • EMPL_RCD
  • COMPRATE
  • STATUS

A document should look like this...No alt text provided for this image

Create a Message

Peopletools -> Integration Broker -> Integration Setup

Once you have created the documents, you must create the messages based on those documents (remember Package+Document+Version ?)

No alt text provided for this image

Create a Service + Service Operation

The next steps are very well-known. Go to Peopletools -> Integration Broker -> Integration Setup -> Services

Add a new service (not REST), save it and after that, add a Service Operation from the same Page. This action will take you to the Service Operation page where you can add the Request Message and the Response Message previously created.

In "Routing Actions Upon Save", check Generate Any-to-Local. Once you do save, a routing will be created. e.g.: ~GENERATED~78620867

At this moment you don't have a handler yet. You'll have to code it and then return to this page to activate it.

Reimplementing standard methods

This is a code example, some parts are pseudocode.

Create an Application Package with your code.

import PS_PT:Integration:IRequestHandler;


class calcComprate implements PS_PT:Integration:IRequestHandler
   method OnRequest(&Msg As Message) Returns Message;
end-class;


method OnRequest
   /+ &Msg as Message +//+ Returns Message +//+ Extends/implements PS_PT:Integration:IRequestHandler.OnRequest +/
   
   /* Documento/Mensaje */
   Local Document &docRequest, &docResponse;
   Local Compound &elemRequest, &elemResponse;
   
   /* Campos de mensaje */
   Local string &anEmplid, &aSalAdminPlan, &aGrade;
   Local number &anEmplRcd, &aStep;
   
   Local Message &msgResponse = CreateMessage(Operation.<YOUR_CUSTOM_SERVICE_OPERATION>, %IntBroker_Response);
   
   &Msg = %IntBroker.GetMessage();


   /* Parsing inbound message */
   &docRequest = &Msg.GetDocument();
   &elemRequest = &docRequest.DocumentElement;
   &anEmplid = &elemRequest.GetPropertyByName("EMPLID").Value;
   &anEmplRcd = &elemRequest.GetPropertyByName("EMPL_RCD").Value;
   &aSalAdminPlan = &elemRequest.GetPropertyByName("SAL_ADMIN_PLAN").Value;
   &aGrade = &elemRequest.GetPropertyByName("GRADE").Value;
   &aStep = &elemRequest.GetPropertyByName("STEP").Value;
   
   /* Obtain comprate using the values obtained in the request messsage */
   &nbrComprate = <function that returns comprate value from CMP_RULE_RATECD>
   
   /* Create a Response message */
   &docResponse = &msgResponse.GetDocument();
   &elemResponse = &docResponse.DocumentElement;
   &elemResponse.GetPropertyByName("EMPLID").value = &anEmplid;
   &elemResponse.GetPropertyByName("EMPL_RCD").value = &anEmplid;
   
   If &nbrComprate exists Then
      &elemResponse.GetPropertyByName("COMPRATE").value = &nbrComprate;
      &elemResponse.GetPropertyByName("STATUS").value = "OK";
   Else
      &elemResponse.GetPropertyByName("COMPRATE").value = -999999;
      &elemResponse.GetPropertyByName("STATUS").value = "ERROR";
   End-If;
   
   Return &msgResponse;
end-method;

After you finished coding, go to Service Operation definition and add the handler of your new Application Package.

Create the web service
Peopletools -> Integration Broker -> Web Services -> Provide Web Services
This is a wizard where you search for your service. Next, next, next...
Copy the url of you wsdl and test it with an integration tool like SoapUI. Your request message shoul look like this.
Request Message:
<soapenv:Body>
    <YOUR_REQUEST_MESSAGE>
        <EMPLID>ABCD</EMPLID>
        <EMPL_RCD>0</EMPL_RCD>
        <SAL_ADMIN_PLAN>A</SAL_ADMIN_PLAN>
        <GRADE>B</GRADE>
        <STEP>1</STEP>
    </YOUR_REQUEST_MESSAGE>
</soapenv:Body>
Response message: the compensation rate is $ 3,500 and status is OK.
OK MESSAGE 
<soapenv:Body>
    <YOUR_REPONSE_MESSAGE>
        <EMPLID>ABCD</EMPLID>
        <EMPL_RCD>0</EMPL_RCD>
        <COMPRATE>3500</COMPRATE>
        <STATUS>OK</STATUS>
    </YOUR_REPONSE_MESSAGE>
</soapenv:Body>
If there were no compensation rate, it will return -999999 and STATUS= ERROR.
<soapenv:Body>
    <YOUR_REPONSE_MESSAGE>
        <EMPLID>ABCD</EMPLID>
        <EMPL_RCD>0</EMPL_RCD>
        <COMPRATE>-999999</COMPRATE>
        <STATUS>ERROR</STATUS>
    </YOUR_REPONSE_MESSAGE>
</soapenv:Body>

PS: you can use this technique to create JSON message. Peoplecode changes a little and you have to change some bits of your integration setup.

No comments:

Post a Comment

PeopleCode to retrieve Google map between two addresses

  PeopleCode Example: /* Define constants for the API request */ Local string &origin = "123 Main St, Anytown, USA";   /* ...