From YiPs Wiki (i powered)

XMLSERVICE: XMLSERVICE 123 PHPGET

(click to open)

Quick Page Table of Contents

Scanning…

XMLSERVICE PHP HTTP GET

Goto Main Page
Goto Documents

PHP REST GET 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.

Step 1) Install XMLSERVICE

Download:
1) XMLSERVICE main page has download "latest" and install instructions.

Step 2) Configure

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 ...

Step 3 - Example - PGM complex data with DS

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_get.php - HTTP GET call XMLSERVICE

<?php
require_once('connection.inc');

// http GET parms
$clobIn = getxml();
$clobOut = "";
$parm  = "?db2=$i5restdatabase";
$parm .= "&uid=$user";
$parm .= "&pwd=$password";
$parm .= "&ipc=$ipc";
$parm .= "&ctl=$ctl";
$parm .= "&xmlin=".urlencode($clobIn);
$parm .= "&xmlout=32768";  // size expected XML output
// execute
$linkall = "$i5rest".htmlentities($parm);
$getOut = simplexml_load_file($linkall);
// result
if ($getOut) $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);
}

Step 4 - Example - Use PHP HTTP GET to Kill XMLSERVICE job

The keywords used to route the kill order are ctl=“*immed” and ipc=“/tmp/rangerusr” (same ipc used above example).

test_get_kill.php - kill XMLSERVICE job

<?php
require_once('connection.inc');

// http GET parms
$ctlKill= '*immed';
$clobIn = '<?xml version="1.0"?>';
$clobOut = "";
$parm  = "?db2=$i5restdatabase";
$parm .= "&uid=$user";
$parm .= "&pwd=$password";
$parm .= "&ipc=$ipc";
$parm .= "&ctl=$ctlKill";
$parm .= "&xmlin=".urlencode($clobIn);
$parm .= "&xmlout=32768";  // size expected XML output
// execute
$linkall = "$i5rest".htmlentities($parm);
$getOut = simplexml_load_file($linkall);
?>

Author(s)

Tony “Ranger” Cairns - IBM i PHP / PASE

Retrieved from http://www.youngiprofessionals.com/wiki/index.php/XMLSERVICE/XMLSERVICE123PHPGET
Page last modified on October 21, 2013, at 01:59 PM EST