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:
Template other than /Document Template because we are not passing any parametersCHG_GENERIC.V1 which is a “Nonrowset-based” based messages. This is is not shown.
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:
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:
This web service has no:
For now see JSON Parsing Using PeopleTools JsonParser
Chris Malek s a PeopleTools® Technical Consultant with over two decades of experience working on PeopleSoft enterprise software projects. He is available for consulting engagements.
Work with Chris