1. litmis
  2. Untitled project
  3. xmlservice_examples

Overview

HTTPS SSH

Summary

Here you will find xmlservice Gem examples. IBM also has some documented on the YiPs website.

The XMLSERVICE gem can use http or db2 to communicate from Ruby to your IBM i. See the Considerations section below for things you should be aware of.

Install

git clone git@bitbucket.org:litmis/xmlservice_examples.git

Setup

NOTE: You will need *SECADM authority to create an Apache config.

Apache config

Run the following from a shell (i.e. ssh or CALL QP2TERM)

mkdir -p /www/xmlservice_examples/conf
mkdir -p /www/xmlservice_examples/logs
cat >> /www/xmlservice_examples/conf/httpd.conf << EOF
Listen *:8000
ScriptAlias /cgi-bin/ /QSYS.LIB/POWER_RUBY.LIB/
<Directory /QSYS.LIB/POWER_RUBY.LIB/>
  order allow,deny
  allow from all
  SetHandler cgi-script
  Options +ExecCGI
</Directory>
EOF

5250 commands to run

ADDPFM FILE(QUSRSYS/QATMHINSTC) MBR(XMLEXP) TEXT('XMLSERVICE examples')

Modify member XML using command UPDDTA:

UPDDTA FILE(QUSRSYS/QATMHINSTC) MBR(XMLEXP)

Paste the following into member XMLEXP:

-apache -d /www/xmlservice_examples -f conf/httpd.conf -AutoStartN

Start/stop Apache server instance:

STRTCPSVR SERVER(*HTTP) INSTANCE(XMLEXP)

ENDTCPSVR SERVER(*HTTP) INSTANCE(XMLEXP)

Source for RPG example

The following is necessary if you desire to invoke the sample RPG *SRVPGM.

CRTLIB XMLEXP

CRTRPGMOD MODULE(XMLEXP/SRVPGM1) SRCSTMF('/path/to/xmlservice_examples/source_members/srvpgm1.rpgle')

CRTSRVPGM SRVPGM(XMLEXP/SRVPGM1) MODULE(XMLEXP/SRVPGM1) EXPORT(*ALL)

Config files

Modify config/database.yml to have valid values for username and password

Try it out

cd xmlservice_examples

ruby dtaq.rb

HTTP or DB2?

XMLSERVICE is very flexible in that its transport from Ruby to IBM i can use either http or a generic DB2-for-i stored procedure. Take a look at the http_or_db2.rb example to see the differences in configuration.

Considerations

  • The http approach is noticeably slower than DB2 approach when multiple calls are required, though if only one call is necessary then http is faster because it requires less start-up time. See the commented code at the bottom of http_or_db2.rb for a simple test.

  • The DB2 approach can only be used in 1-tier situations (i.e. when the Ruby script is on the same machine as the database) unless you want to install the commercial DB2Connect product from IBM.

  • The http approach is good when your Ruby code isn't on the same IBM i machine you are calling.