Program: GETURI3
//?*******************************************************************************************
//?@Author - Aaron Bartell
//?@Created: 2005-08-03
//?@Desc: Compose a simple xml stream for a non-SOAP web service transaction. It will
//? call web service http://192.168.0.11:8181/myrxs/rxs3 which is included in
//? the base install of the RPG-XML Suite. Note the IP address will need to be
//? changed to that of the machine where RPG-XML Suite was installed.
//?@Notes:
//?*******************************************************************************************
H dftactgrp(*no) bnddir('RXSBND')
/copy rxs,RXSCp ?RPG-XML Suite
D compose pr
D transmit pr
D parse pr
D allHandler pr
D pType value like(RXS_Type)
D pXPath value like(RXS_XPath)
D pData value like(RXS_XmlData)
D pDataLen value like(RXS_Length)
D errHandler pr
D pCurLine 10i 0 value
D pCurCol 10i 0 value
D pErrStr 1024a value varying
D gError ds likeds(RXS_Error) inz
//?Result of parse
D gPrsData ds qualified inz
D status 10a varying
D msg 256a varying
//?Used for RXS_getUri API
D gInCfg ds likeds(RXS_GetUriIn) inz
D gReqData s like(RXS_XmlData)
D gRspData s like(RXS_XmlData)
D gRspHttpHdr s like(RXS_XmlData)
/free
reset gError;
reset gPrsData;
compose();
if gError.code <> *blanks;
return;
endif;
transmit();
if gError.code <> *blanks;
return;
endif;
parse();
RXS_log(RXS_DIAG: 'gPrsData.status=' + gPrsData.status);
RXS_log(RXS_DIAG: 'gPrsData.msg=' + gPrsData.msg);
*inlr = *on;
/end-free
//?-------------------------------------------------------------------------------------------
//?@Author: Aaron Bartell
//?@Created: 2005-08-03
//?@Desc:
//?-------------------------------------------------------------------------------------------
P compose b
D compose pi
/free
monitor;
RXS_initTplEng(RXS_VAR: *omit: *omit: *omit: *omit: *on);
RXS_loadTpl('geturi3.tpl');
RXS_updVar('residential': 'true');
RXS_updVar('title': 'Mr.');
RXS_updVar('first': 'Aaron');
RXS_updVar('last': 'Bartell');
RXS_updVar('street': '123 Center Rd');
RXS_updVar('cty': 'Mankato');
RXS_updVar('state': 'MN');
RXS_updVar('zip': '56001');
RXS_wrtSection('PostAdr_begin');
RXS_updVar('phone': '123-123-1234');
RXS_wrtSection('phone');
RXS_updVar('phone': '321-321-4321');
RXS_wrtSection('phone');
RXS_wrtSection('PostAdr_end');
gReqData = RXS_getBuffData(*on); //?*on=clear buffer after retrieving.
on-error;
gError = RXS_catchError();
endmon;
/end-free
P e
//?-------------------------------------------------------------------------------------------
//?@Author: Aaron Bartell
//?@Created: 2005-08-03
//?@Desc:
//?-------------------------------------------------------------------------------------------
P transmit b
D transmit pi
/free
monitor;
//?Note the below IP address needs to be changed to that of the iSeries where
//?the RPG-XML Suite was installed. Also note that if a different value was used
//?for the name of the RXS instance than 'myrxs' that should be specified in the
//?below URL.
gInCfg.URI = 'http://192.168.0.11/myrxs/rxs3';
gInCfg.Port = 8181;
gInCfg.Debug = RXS_YES;
RXS_getUri(gInCfg: gReqData: gRspData: gRspHttpHdr);
on-error;
gError = RXS_catchError();
endmon;
/end-free
P e
//?-------------------------------------------------------------------------------------------
//?@Author: Aaron Bartell
//?@Created: 2005-08-03
//?@Desc:
//?-------------------------------------------------------------------------------------------
P parse b
D parse pi
/free
monitor;
RXS_allElemContentHandler(%paddr(allHandler));
RXS_allAttrHandler(%paddr(allHandler));
RXS_parse(gRspData: RXS_VAR: %paddr(errHandler));
on-error;
gError = RXS_catchError();
endmon;
/end-free
P e
//?-------------------------------------------------------------------------------------------
//?@Author: Aaron Bartell
//?@Created: 2005-08-03
//?@Desc:
//?@Notes: There are four events that your program can be notified of through the allHandler
//? sub procedure and they are passed in the pEvntType parm. An event is triggered
//? as the parser reads the document top down, left to right (same way you read the
//? newspaper). Note that you will only be notified of events you specified before the
//? call to RXS_parse by using API's RXS_allElemBegHandler, RXS_allElemContentHandler,
//? RXS_allElemEndHandler, and RXS_allAttrHandler.
//?
//? The four events and their values (note that these can all be overidden by
//? changing the RXSCFG file or by doing a temporary override on the RXS_parse command)
//?
//? Element Begin = '>' -- Placed at end of string (i.e. '/elem>')
//? Element Content = '/' -- Placed at end of string (i.e. '/elem/')
//? Element End = '/>' -- Placed at end of string (i.e. '/elem/>')
//? Attribute = '@' -- Placed between the elem and attr (i.e. '/elem@attr')
//?
//? The most common events you will use are Element Content and Attribute simply
//? because these are the two that provide business data via the pData parm on the
//? allHandler procedure interface. Events Element Begin and Element End are very
//? helpful when you have repeating XML data. You can then use the Begin and End
//? events to do a CLEAR and WRITE to a PF record respectively. Remember that
//? in-between the Element Begin and Element End events you will be notified of all the
//? element content, which means that after the CLEAR (i.e. Element Begin event) you
//? can place data into the PF record until you reach the Element End event at which
//? time you can do a WRITE of that record because it has now been populated with data.
//?-------------------------------------------------------------------------------------------
P allHandler b
D allHandler pi
D pEvntType value like(RXS_Type)
D pXPath value like(RXS_XPath)
D pData value like(RXS_XmlData)
D pDataLen value like(RXS_Length)
/free
select;
when pXPath = '/response@status';
gPrsData.status = pData;
when pXPath = '/response/';
gPrsData.msg = pData;
endsl;
/end-free
P e
//?-------------------------------------------------------------------------------------------
//?@Author: Aaron Bartell
//?@Created: 2005-08-03
//?@Desc:
//?-------------------------------------------------------------------------------------------
P errHandler B
D errHandler PI
D pCurLine 10i 0 value
D pCurCol 10i 0 value
D pErrStr 1024a value varying
/free
gError.code = 'GETURI3001';
gError.severity = 100;
gError.pgm = 'GETURI3.errHandler';
gError.text =
'Line:' + %char(pCurLine) +
' Column:' + %char(pCurCol) +
' ' + pErrStr;
/end-free
P E
IFS Template: /www/myrxs/templates/geturi3.tpl
::PostAdr_begin
<PostAdr residential=".:residential:.">
<name title=".:title:.">
<first>.:first:.</first>
<last>.:last:.</last>
</name>
<street>.:street:.</street>
<cty>.:cty:.</cty>
<state>.:state:.</state>
<zip>.:zip:.</zip>
::phone
<phone>.:phone:.</phone>
::PostAdr_end
</PostAdr>