Question Receive XML notification on webpage

Potish

Member
I working with a vendor to process client requests and after I submit each request the vendor has a process to return a notification to a URL I specify. I have worked before to implement solutions to send and receive xml requests using CURL, but I am yet to have a situation where the vendor posted an xml response to a URL. My primary question

1. What progress functions or methods could I use to identify and receive the notification and parse the xml response to a temp-table in webspeed?

2. After I process the xml response I need to send back an 'ok' response to the vendor. Would this just be a post request from my webspeed page?
 

Cecil

19+ years progress programming and still learning.
It's sounds like you need to use the SAX-Parser to process the inbound XML and then use cURL to post back an XML response.

Just for clarification, the Vendor is doing a HTTP POST of an XML to at URL that you provide and that you want WebSpeed to handle the inbound POST request?

Is there any authentication happening as part of the HTTP POSTs?

The ABL is lacking in a native HTTP client to handle this kind of thing unless you "roll your own".
 

Cecil

19+ years progress programming and still learning.
Is it possible to see some developers documentation from the vendor? It might be easier to get a better understanding of what exactly is needed.

Here is a personal case study which might be similar to what you are trying to do. I was using an SMS gateway (Clickatell) to send an SMS message to mobile phones. I would create a simple XML file and using cURL POST the XML to Clickatell's API portal. In response I would receive a unique token code.

Clickatell also had the optional feature to 'call-back' an XML message back to my web server/WebSpeed. The call-back message was a response message contain the previous token code and a status indicated whether the SMS message was successful or not and some other extra information. I would simple use WebSpeed to handle the POST request just like a regular html form and I would then use the SAX-parser to parse the inbound XML document which is stored a longchar variable.

Is this something similar to what you are trying to achieve?
 

Potish

Member
I found and tried the code below but it does not look to be working. I have an installation of OE 11.1 on Windows 2008 Server. Also the vendor will only sent response to a secure HTTPS URL.

{src/web/method/cgidefs.i}

define variable XMLDocHandle as handle no-undo.
define variable XMLSaveDirectory as character initial "\bh\logs\".

if web-context:is-xml then
do:
create x-document XMLDocHandle.
XMLDocHandle = web-context:x-document.

/* Save the document to file */
output-content-type("text/xml").
XMLDocHandle:save("file",XMLSaveDirectory + "pygtnotification.xml ).

delete object XMLDocHandle.
end.


The Vendor provided a PHP sample of what the page should look like as follows

// Read the raw POST data containing the XML response
$rawXML = file_get_contents("php://input");

// Arrays to hold the data returned
$dataError = "";
$dataAuth = "";

// Functions required to parse the XML data returned
function startElement($parser, $name, $attrs)
{
global $dataError, $dataAuth;
if ($name == "AUTHRX") $dataAuth = $attrs;
if ($name == "ERRORRX") $dataError = $attrs;
}

function endElement($parser, $name)
{
}

// Calculate the name of the file that will store the values.
$FileName = "Notify_".date("Ymd").".txt";

// Open the file that will store the values
$handle = fopen(dirname($_SERVER['PATH_TRANSLATED']).$FileName,"a+");

// Create XML parser and set element handlers
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");

// Read the XML response and stop if an unexpected error occurred.
if (xml_parse($xml_parser, $rawXML)) {
$data = "Raw XML\r\n".
"-------\r\n".
$rawXML."\r\n";
fwrite($handle, $data);
if ($dataError) {
// XML returned an error; write the error to the file
$data = "ecode: ".$dataError['ECODE'].
"\r\nedesc: ".$dataError['EDESC'];
fwrite($handle, $data);
} elseif ($dataAuth) {
// XML returned a response message; write the values to the file
$data = "tid: ".$dataAuth['TID'].
"\r\nstat: ".$dataAuth['STAT'].
"\r\nres: ".$dataAuth['RES'].
"\r\nrisk: ".$dataAuth['RISK'];
fwrite($handle, $data);
}
} else {
// The XML received is not valid
$data = sprintf("The XML notification is not well formed; reason: %d \r\n", xml_error_string(xml_get_error_code($xml_parser)));
fwrite($handle, $data);
}

// Destroy XML parser
xml_parser_free($xml_parser);

// Close the file
fwrite($handle, "\r\n\r\n");
fclose($handle);

// Return the value OK to acknowledge that the notification has been received.
die("OK");
 
Last edited:

Cecil

19+ years progress programming and still learning.
I've quickly mocked something up. I can't truly test it as I don't have the real XML file to test. Looking at the PHP code (which I'm not expert at) I sort of worked out what it's doing and I think I've managed to emulate the code into WebSpeed. (See the attached ZIP File)

I've never used the web-context:is-xml method before and I'm not sure what the conditions are for it to return true, apart from having to be an XML. In my testing I was not able to get web-context:is-xml to return true, I just don't know why????

My solution was just to copy the raw WEB-CONTEXT into memptr and using the SAX-Reader parse the memptr and pull out the required values depending whether it was successful or not.

Try it out and and see how you got on. You will have to adapt the code to fit your desired result.

Note:
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 

Attachments

  • XMLPost.zip
    2.6 KB · Views: 9

Cecil

19+ years progress programming and still learning.
Just out of curiosity did you manage to get this sorted out?
 

Potish

Member
Not yet. I got pulled into something else but it's still on my list of items to get done. Hoping to work on it later this week.
 
Top