These examples show how to use Python to post to the PeopleSoft Integration Broker HttpListeningConnector. They cover both asynchronous and synchronous service operations.
This example posts to an asynchronous Service Operation. In PeopleTools, when you post asynchronously, the PeopleSoft code that triggers is NOT run instantaneously. It will run at some point in the future.
You need:
PTEST with Password authentication)CHG_TEST.V1, Nonrowset-based)CHG_TEST)OnNotify handler that processes the inbound message:import PS_PT:Integration:INotificationHandler;
class TESTER implements PS_PT:Integration:INotificationHandler
method OnNotify(&_MSG As Message);
end-class;
method OnNotify
/+ &_MSG as Message +/
/+ Extends/implements PS_PT:Integration:INotificationHandler.OnNotify +/
Local XmlDoc &doc;
&doc = &_MSG.GetXmlDoc();
/* Process the XML here */
end-method;
The Python script submits an XML document to the HttpListeningConnector. The XML structure does not matter as long as the handler PeopleCode knows how to parse it.
TransactionID response header contains a value, the integration broker accepted the XML.Since this is an asynchronous service operation, there is no way for the handler code to pass information back to the Python script. For that you need a synchronous operation (see below).
If your integration requires PeopleSoft to process the message and your client needs the response immediately, you need a synchronous service operation.
A synchronous request must implement the OnRequest method instead of OnNotify:
import PS_PT:Integration:IRequestHandler;
class syncTester 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 +/
Local XmlDoc &xmlDocFromPython;
Local XmlNode &requestRootNode;
&xmlDocFromPython = &MSG.GetXmlDoc();
&requestRootNode = &xmlDocFromPython.DocumentElement;
/* Setup response xml body */
Local Message &response;
&response = CreateMessage(Operation.CHG_SYNC_TEST, %IntBroker_Response);
Local XmlDoc &xmlout;
Local XmlNode &childNode;
&xmlout = CreateXmlDoc("<?xml version='1.0'?><response/>");
Evaluate Lower(&requestRootNode.NodeName)
When = "helloworld"
&childNode = &xmlout.DocumentElement.AddElement("helloworld").AddText("Hello Python");
Break;
When = "activeusercount"
Local integer &ucount;
SQLExec("SELECT COUNT(*) FROM PSOPRDEFN WHERE ACCTLOCK = 0 ", &ucount);
&childNode = &xmlout.DocumentElement.AddElement("activeusercount").AddText(String(&ucount));
Break;
When-Other
&childNode = &xmlout.DocumentElement.AddElement("error").AddText("I do not understand. Please try again. You submitted: " | &requestRootNode.NodeName);
Break;
End-Evaluate;
&response.SetXmlDoc(&xmlout);
Return &response;
end-method;
This handler examines the root node of the XML and runs different branches:
helloworld - Returns a greetingactiveusercount - Counts unlocked users in the systemOnRequest instead of OnNotifyYou can submit any XML to PeopleSoft service operations and have the handler code process it and (for synchronous) respond. The two systems just need to agree upon an XML format to exchange. The handler PeopleCode can parse the data and update PeopleSoft via SQL, Component Interface, or any other PeopleCode method.
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