Author Info
Chris Malek

Chris Malek is a PeopleTools® Technical Consultant with two decades of experience working on PeopleSoft enterprise software projects. He is available for consulting engagements.

About Chris Work with Chris
Looking for pain-free PeopleSoft web services? 😀
PeopleSoft Simple Web Services (SWS)

Introducing a small but powerful PeopleSoft bolt-on that makes web services very easy. If you have a SQL statement, you can turn that into a web service in PeopleSoft in a few minutes.

Contents

JSON Decoding Examples

Simple REST JSON Post - Example 1

First we will look at a simple REST JSON Post. The screenshot below has the service operation setup. This is the most simple web service. You will notice that:

  • There is no Template other than /
  • There is no Document Template because we are not passing any parameters
  • The Request and Response Message objects are both CHG_GENERIC.V1 which is a “Nonrowset-based” based messages. This is is not shown.
Service Operation Setup

We plan on posting some simple JSON to this. The HTTP Signature will look like this:

POST http://localhost:8000/PSIGW/RESTListeningConnector/PSFT_CS/CHG_JSON_TEST.v1/
Authorization: Basic UFM6dHJ5aW5nLXNlZS1pZi1JLXBvc3RlZC1teS1wYXNzd29yZC1JLXNlZQ==
Content-Type: application/json

{
   "firstName": "Chris",
   "lastName": "Malek",
   "Region": "Southern California",
   "FavoriteDesert": "Pie, any kind"
}

The response that comes out of this web services the following.

HTTP/1.1 200 OK
Connection: close
Date: Wed, 02 Dec 2020 04:33:21 GMT
Content-Length: 234
Content-Type: application/json; encoding="UTF-8"
Content-Encoding: gzip
Set-Cookie: JSESSIONID=6zshuetDLvmVT5G55VCUt0su3nVWAn469hsagTQOqg0zHVExziNa!-1985259815; path=/; HttpOnly,psmap=; domain=.c.peoplesoftdemo-1470578694381.internal; path=/

{

  "firstName": "Chris",
  "lastName": "Malek",
  "Region": "Southern California",
  "FavoriteDesert": "Pie, any kind",
  "META": {

    "OPRID": "PS",
    "CURRENT_TIME": "2020-12-02 04:33:21.000000",
    "TRANSACTION_ID": "81fa5f4b-3457-11eb-9b6b-e783fa52141b",
    "DBNAME": "CS92U009"
  }
}

The handler parses the inbound root JSON object strings and echos any value back out. We also add a “META” object with some information about the run-time environment.

The entire PeopleCode handler for this web service is:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import PS_PT:Integration:IRequestHandler;

class simpleJSONPost implements PS_PT:Integration:IRequestHandler
   method onRequest(&msRequest As Message) Returns Message;
   
end-class;

method onRequest
   /+ &msRequest as Message +/
   /+ Returns Message +/
   /+ Extends/implements PS_PT:Integration:IRequestHandler.OnRequest +/
   
   
   Local Message &response = CreateMessage(@("Operation." | &msRequest.OperationName), %IntBroker_Response);
   
   Local JsonObject &responseRootJSON = CreateJsonObject();
   
   Local string &requestPayload = &msRequest.GetContentString();
   
   Local JsonParser &parser = CreateJsonParser();
   
   Local boolean &bParseResult = &parser.Parse(&requestPayload);
   
   If &bParseResult = True Then
      Local integer &i;
      
      Local JsonObject &jObj = &parser.GetRootObject();
      For &i = 1 To &jObj.ChildCount
         
         Local string &propName;
         
         &propName = &jObj.GetPropertyNameAt(&i);
         &responseRootJSON.AddProperty(&propName, &jObj.GetAsString(&propName));
         
      End-For;
   End-If;
   
   
   Local JsonObject &JsonObjMETA = CreateJsonObject();
   
   &JsonObjMETA.AddProperty("OPRID", %OperatorId);
   &JsonObjMETA.AddProperty("CURRENT_TIME", %Datetime);
   &JsonObjMETA.AddProperty("TRANSACTION_ID", &msRequest.TransactionId);
   &JsonObjMETA.AddProperty("DBNAME", %DbName);
   
   &responseRootJSON.AddJsonObject("META", &JsonObjMETA);
   
   
   /* Push the generated XML to the response document */
   If &response.SetContentString(&responseRootJSON.ToString()) Then
      
   End-If;
   Return &response;
   
end-method;

With this simple example you can see:

  • How to get the raw unparsed JSON string from the request message
  • Parse a simple JSON object
  • Return back JSON data

This web service has no:

  • Error Handling
  • JSON detection of different data types
  • Any real practical use

More Detailed JSON Parsing Examples

For now see JSON Parsing Using PeopleTools JsonParser