In this example we are leveraging the HTTP post using the JAVA program Apache commons API and then calling the Java program method directly from RPGLE program.
Click here for HttpXMLDataPost Java Source code
h DftActGrp(*no) ActGrp(*Caller)
*
d ExcCmd PR ExtPgm('QCMDEXC')
d Cmd_Str 512a Options(*VARSIZE)
d Const
d Cmd_Len 15p 5 Const
d $xml_filePath s 250a
d $prop_fileName s 50a
d $success s 1N
d $CmdStr s 512a inz
* Prototype for Java String Object
d crtString PR o EXTPROC(*JAVA:
d 'java.lang.String':
d *CONSTRUCTOR)
d RPGBytes 250A Const Varying
* Prototype for Java String's getBytes method
d cvtToBytes PR 30A EXTPROC(*JAVA:
d 'java.lang.String':
d 'getBytes')
d Varying
* Prototype for HttpXMLDataPost Object
d HttpXMLData PR o EXTPROC(*JAVA:
d 'com.as400samplecode.HttpXMLDataPost'
d :*CONSTRUCTOR)
* HttpXMLDataPosT Object
d httpXMLData_ s o Class(*JAVA:
d 'com.as400samplecode.HttpXMLDataPost'
d )
* Prototype for HttpXMLDataPost's XMLDataPost method
d XMLDataPost PR 1N EXTPROC(*JAVA:
d 'com.as400samplecode.HttpXMLDataPost'
d :'XMLDataPost')
d String o Class (*JAVA:'java.lang.String')
d Const
d String o Class (*JAVA:'java.lang.String')
d Const
d @file_path s o Class(*JAVA:'java.lang.String')
d @properties s o Class(*JAVA:'java.lang.String')
*
*----- Main Routine
*
/free
@file_path = crtString($xml_filePath);
@properties = crtString($prop_fileName);
httpXMLData_ = HttpXMLData();
$success = XMLDataPost(httpXMLData_:@file_path:@properties);
*inlr = *on;
return;
/end-free
*
*----- Initial Routine
*
c *inzsr begsr
c *entry plist
c parm $xml_filePath
c parm $prop_fileName
c parm $success
c eval $success = *off
c eval $CmdStr = 'CALL XMLHTTPCL'
c callp ExcCmd(%Trim($CmdStr) :
c %Len(%Trim($CmdStr)))
c endsr
Source for XMLHTTPCL to setup Java environment variables and Classpath
PGM
RMVENVVAR ENVVAR(QIBM_RPG_JAVA_PROPERTIES)
MONMSG MSGID(CPF0000)
RMVENVVAR ENVVAR(QIBM_USE_DESCRIPTOR_STDIO)
MONMSG MSGID(CPF0000)
RMVENVVAR ENVVAR(JAVA_HOME)
MONMSG MSGID(CPF0000)
RMVENVVAR ENVVAR(CLASSPATH)
MONMSG MSGID(CPF0000)
CD DIR('/directory1/directory2')
ADDENVVAR ENVVAR(QIBM_RPG_JAVA_PROPERTIES) +
VALUE('-Dos400.stderr=file:STDERR.TXT;-Dos4+
00.stdout=file:STDOUT.TXT;')
ADDENVVAR ENVVAR(QIBM_USE_DESCRIPTOR_STDIO) VALUE('Y')
ADDENVVAR ENVVAR(JAVA_HOME) +
VALUE('/qibm/ProdData/Java400/jdk15')
ADDENVVAR ENVVAR(CLASSPATH) +
VALUE('.:/QIBM/ProdData/HTTP/Public/jt400/l+
ib/jt400.zip:/QIBM/ProdData/HTTP/Public/jt4+
00/utilities:/directory1/directory2:/directory1/DR+
Track/bin:/directory1/directory2/lib/commons-log+
ging-1.1.1.jar:/directory1/directory2/lib/httpcl+
ient-4.1.1.jar:/directory1/directory2/lib/httpco+
re-4.1.jar:')
ENDPGM
Recommended Reading
No comments:
Post a Comment
NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.