From YiPs Wiki (i powered)

XMLService: XMLSERVICE 123 PERL

(click to open)

Quick Page Table of Contents

Scanning…

XMLSERVICE perl

Goto Main Page
Goto Documents

This page is for IBM i developers that want to try XMLSERVICE from perl.

Perl DBI (DBD::DB2) was used for this perl CGI to XMLSERVICE test.

Step 1) Install XMLSERVICE

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

Step 2) Configure Apache

Perl is configured as a CGI program (perl-cgi).

1) Apache rest configuration (CGI interface)
Example: Add the following to /www/zendsvr/conf/httpd.conf
# perl cgi wrapper program
ScriptAlias /perl-bin/ /QOpenSys/perl-bin/
AddType application/x-httpd-perl .pl
Action application/x-httpd-perl /perl-bin/perl-cgi
<Directory /QOpenSys/perl-bin>
Options +ExecCGI
order allow,deny
allow from all
</Directory>
# perl applications (.pl)
Alias /perl-htdocs /QOpenSys/perl-bin/perl-htdocs
<Location /perl-htdocs>
Order deny,allow
Allow from all
</Location>

2) Create File: /QOpenSys/perl-bin/perl-cgi
#!/QOpenSys/usr/bin/perl
exec $ENV{PATH_TRANSLATED};
print "Content-Type: text/html;\r\n\r\n";
print "<html>\n";
print " <head>\n";
print " <title>View CGI Environment Variables</title>\n";
print " </head>\n";
print " <body bgcolor=white>\n";
print " <h1>$ENV{PATH_TRANSLATED}</h1>";
print " <h2><font face=helv color=cc9900>CGI Environment 
Variables</font></h2>\n";
print " <table cellpadding=3 cellspacing=0 border=1>\n";
foreach $key (sort(keys %ENV))
{
print " <tr><td align=right>$key:</td><td>&nbsp;$ENV{$key}</td></tr>\n";
}
print " </table>\n";
print " </body>\n";
print "</html>\n";
exit(0);

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 - Use perl to make the call

This will call test program ZZCALL in XMLSERVICE library.

To run just point your browser at the page.

To call PGM:
http://myibmi/perl-htdocs/dbxmlcall.pl

Note: Some browsers do not display the returned XML formatted, so you may have to use the browser pull downs to see “page source” to see the returned XML.

RPG PGM called (can also be SRVPGM procedure):
     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


3) Create File: /QOpenSys/perl-bin/perl-htdocs/dbxmlcall.pl:
#!/usr/bin/perl
print "Content-Type: text/xml;\r\n\r\n";

# Program:
#   This program calls an exmple RPG PGM,
#   also call system APIs. (see dbxmlkill.pl)
# Comment:
#   first call starts XMLSERVICE,
# XMLSERVICE:
#   DBI supports stored procedures in/out,
#   therefore can use new XMLSERVICE support,
# DB2 connection via DBI interface:
#   runs in this process, no user/password
# XML to/from XMLSERVICE:
#   no XML parser is included with IBM i perl
use DBI;
use DBD::DB2::Constants;
use DBD::DB2;

$dbh = DBI->connect("dbi:DB2:*LOCAL")
            or die $DBI::errstr;

$stmt = 'call XMLSERVICE.iPLUG65K(?,?,?,?)';
$sth = $dbh->prepare($stmt)
  or die "prepare got error " . $dbh->err;
$ipc = "/tmp/perlme";
$sth->bind_param(1, $ipc)
  or die "bind 1 got error " . $dbh->err;
$ctl = "*sbmjob";
$sth->bind_param(2, $ctl)
  or die "bind 2 got error " . $dbh->err;
$xmlin = '<?xml version="1.0"?>
<script>
<pgm name="ZZCALL" lib="XMLSERVICE">
 <parm  io="both">
   <data type="1A">a</data>
 </parm>
 <parm  io="both">
   <data type="1A">b</data>
 </parm>
 <parm  io="both">
   <data type="7p4">11.1111</data>
 </parm>
 <parm  io="both">
   <data type="12p2">222.22</data>
 </parm>
 <parm  io="both">
  <ds>
   <data type="1A">x</data>
   <data type="1A">y</data>
   <data type="7p4">66.6666</data>
   <data type="12p2">77777.77</data>
  </ds>
 </parm>
 <return>
  <data type="10i0">0</data>
 </return>
</pgm>
</script>
';
$sth->bind_param(3, $xmlin)
  or die "bind 3 got error " . $dbh->err;
$xmlout = "";
$xmloutlen = 4096;
$sth->bind_param_inout(4, \$xmlout, $xmloutlen)
  or die "bind 4 got error " . $dbh->err;
$sth->execute()
  or die "execute got error" . $dbh->err;

# why more junk at the end xml?
$xmlout =~ m/script/g;
$first = pos($xmlout);
pos($xmlout) = $first + 10;
$xmlout =~ m/script/g;
$last = pos($xmlout);
pos($xmlout) = 0;
$xml =substr($xmlout,0,$last+1);
# print "(Use view page source button browser to see XML)\n";
print $xml;
# use XML::Parser;
# use XML::Xerces;
# no xml parser available???


Output:
<?xml version="1.0"?>
<script>
<pgm name="ZZCALL" lib="XMLSERVICE">
<parm  io="both">
<data type="1A">C</data>
</parm>
<parm  io="both">
<data type="1A">D</data>
</parm>
<parm  io="both">
<data type="7p4">321.1234</data>
</parm>
<parm  io="both">
<data type="12p2">1234567890.12</data>

</parm>
<parm  io="both">
<ds>
<data type="1A">E</data>
<data type="1A">F</data>
<data type="7p4">333.3330</data>
<data type="12p2">4444444444.44</data>
</ds>
</parm>
<return>
<data type="10i0">0</data>
</return>

</pgm>
</script>

Step 4) Example - Use perl to Kill XMLSERVICE job

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

To run just point your browser at the page.

To kill XMLSERVICE:
http://myibmi/perl-htdocs/dbxmlkill.pl
4) Create File: /QOpenSys/perl-bin/perl-htdocs/dbxmlkill.pl:
#!/usr/bin/perl
print "Content-Type: text/html;\r\n\r\n";

# Program:
#   This program kills running XMLSERVICE
#   started by dbxmlcall.pl.
use DBI;
use DBD::DB2::Constants;
use DBD::DB2;

$dbh = DBI->connect("dbi:DB2:*LOCAL")
  or die $DBI::errstr;
$stmt = 'call XMLSERVICE.iPLUG4K(?,?,?,?)';
$sth = $dbh->prepare($stmt) 
  or die "prepare got error " . $dbh->err;
$ipc = "/tmp/perlme";
$sth->bind_param(1, $ipc) 
  or die "bind 1 got error " . $dbh->err;
$ctl = "*immed";
$sth->bind_param(2, $ctl) 
  or die "bind 2 got error " . $dbh->err;
$xmlin = '<?xml version="1.0"?>';
$sth->bind_param(3, $xmlin) 
  or die "bind 3 got error " . $dbh->err;
$xmlout = "";
$xmloutlen = 4096;
$sth->bind_param_inout(4, \$xmlout, $xmloutlen)
  or die "bind 4 got error " . $dbh->err;
$sth->execute()
  or die "execute got error" . $dbh->err;

print "dead";


Author(s)

Tony “Ranger” Cairns - IBM i PHP / PASE

Retrieved from http://youngiprofessionals.com/wiki/index.php/XMLService/XMLSERVICE123PERL
Page last modified on October 21, 2013, at 02:30 PM EST