Scanning…
PHP REST POST was used for this XMLSERVICE test (included with Zend Server downloads 1/2 tier). This is not the Zend PHP Toolkit interface, instead this is what happens below that “nice” PHP interface wrapper.
Download: 1) XMLSERVICE main page has download "latest" and install instructions.
The RPG CGI sample module is included in the XMLSERVICE download.
Apache rest configuration (CGI interface) Example: Add the following to /www/zendsvr/conf/httpd.conf ScriptAlias /cgi-bin/ /QSYS.LIB/XMLSERVICE.LIB/ <Directory /QSYS.LIB/XMLSERVICE.LIB/> AllowOverride None order allow,deny allow from all SetHandler cgi-script Options +ExecCGI </Directory>
IMPORTANT: If you are running a machine with CCSID 65535 (and nothing works), please read and follow the documentation (main XMLSERVICE page), setting valid CCSID like 37 for Apache (web) and/or command line PHP (pear tests).
/www/zendsvr/conf/httpd.conf (web admin GUI port 2001 - ZENDSVR): DefaultFsCCSID 37 ... or 280 (Italian) ... or so on ... CGIJobCCSID 37 ... or 280 (Italian) ... or so on ...
Example calling a typical RPG PGM with a few parameters, one of which is a data structure. In this case all the parameters are io=‘both’ (input/output), so the XML going in looks exactly like the XML coming out of XMLSERVICE, except the return XML data values will change to whatever the called function writes into the parameter variables.
connection.inc - connection information
<?php // database $database = "LP0164D"; $user = "ADCU"; $password = "NICEXXXX"; $internalKey = "/tmp/rangerusr"; // misc test settings $i5persistentconnect = false; $libxmlservice = 'XMLSERVICE'; // ZENDSVR $toolkitdir = "."; // zend ship also $i5rest = "http://lp0164d.rchland.ibm.com/cgi-bin/xmlcgi.pgm"; $i5restdatabase = "*LOCAL"; // only *LOCAL tested // call parms $ipc = $internalKey; $ctl = "*sbmjob"; $clobIn = ""; $clobOut = ""; function test_lib_replace($xml) { global $libxmlservice; $was = array("xyzlibxmlservicexyz"); $now = array("$libxmlservice"); $out = str_replace($was,$now,$xml); return $out; } ?>
test_post.php - HTTP POST call XMLSERVICE
<?php require_once('connection.inc'); // http POST parms $clobIn = getxml(); $clobOut = ""; $postdata = http_build_query( array( 'db2' => $i5restdatabase, 'uid' => $user, 'pwd' => $password, 'ipc' => $ipc, 'ctl' => $ctl, 'xmlin' => $clobIn, 'xmlout' => 4096 // size expected XML output ) ); $opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata ) ); $context = stream_context_create($opts); // execute $linkall = $i5rest; $result = file_get_contents($linkall, false, $context); // result if ($result) { $getOut = simplexml_load_string($result); $clobOut = $getOut->asXML(); } else $clobOut = ""; // ----------------- // output processing // ----------------- // dump raw XML (easy test debug) var_dump($clobOut); // D INCHARA S 1a // D INCHARB S 1a // D INDEC1 S 7p 4 // D INDEC2 S 12p 2 // D INDS1 DS // D DSCHARA 1a // D DSCHARB 1a // D DSDEC1 7p 4 // D DSDEC2 12p 2 // *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // * main(): Control flow // *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // C *Entry PLIST // C PARM INCHARA // C PARM INCHARB // C PARM INDEC1 // C PARM INDEC2 // C PARM INDS1 function getxml() { $clob = <<<ENDPROC <?xml version='1.0'?> <script> <pgm name='ZZCALL' lib='xyzlibxmlservicexyz'> <parm io='both'> <data type='1A' var='INCHARA'>a</data> </parm> <parm io='both'> <data type='1A' var='INCHARB'>b</data> </parm> <parm io='both'> <data type='7p4' var='INDEC1'>11.1111</data> </parm> <parm io='both'> <data type='12p2' var='INDEC2'>222.22</data> </parm> <parm io='both'> <ds> <data type='1A' var='INDS1.DSCHARA'>x</data> <data type='1A' var='INDS1.DSCHARB'>y</data> <data type='7p4' var='INDS1.DSDEC1'>66.6666</data> <data type='12p2' var='INDS1.DSDEC2'>77777.77</data> </ds> </parm> <return> <data type='10i0'>0</data> </return> </pgm> </script> ENDPROC; return test_lib_replace($clob); }
The keywords used to route the kill order are ctl=“*immed” and ipc=“/tmp/rangerusr” (same ipc used above example).
test_post_kill.php - kill XMLSERVICE job
<?php require_once('connection.inc'); // http POST parms $ctlKill= '*immed'; $clobIn = '<?xml version="1.0"?>'; $clobOut = ""; $postdata = http_build_query( array( 'db2' => $i5restdatabase, 'uid' => $user, 'pwd' => $password, 'ipc' => $ipc, 'ctl' => $ctlKill, 'xmlin' => $clobIn, 'xmlout' => 4096 // size expected XML output ) ); $opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata ) ); $context = stream_context_create($opts); // execute $linkall = $i5rest; $result = file_get_contents($linkall, false, $context); ?>
Tony “Ranger” Cairns - IBM i PHP / PASE