3.4.8 Sample ILE RPGX Client Programs
The following RPG program example shows how use the HTTPService and the InboundFIle handler to return a PDF document to a HTTP client program.
The program example also includes a binding fields and binding list example, which is not needed for its task of sending a HTTP response. Also the SERVICE_UNLOAD command is commented out so that the HTTP response return by the SEND command is returned to the HTTP client on the JSMX_CLOSE API call.
For further examples of ILE RPGX client applications, refer to Client Application Examples.
Example
CRTRPGMOD MODULE(JSMBLD/DEMORPGSRV) SRCFILE(*LIBL/QCSRC)
CRTPGM PGM(JSMBLD/DEMORPGSRV) MODULE(*LIBL/DEMORPGSRV) +
BNDSRVPGM(*LIBL/JSMRPGSRV) ACTGRP(*CALLER)
D FieldDef1 S 60 DIM(6) CTDATA
D FieldDef2 S 60 DIM(3) CTDATA
D ListDef1 S 60 DIM(3) CTDATA
D ListDefSize S 10I 0 INZ(0)
D ListEntSize S 10I 0 INZ(0)
D ListCount S 10I 0 INZ(0)
D ListMaxCount S 10I 0 INZ(0)
D FieldDefSize S 10I 0 INZ(0)
D FieldEntSize S 10I 0 INZ(0)
*
D JSMHDL S 4 INZ(*BLANKS)
D JSMSRV S 100 INZ(*BLANKS)
D JSMSTS S 40 INZ(*BLANKS)
D JSMMSG S 4096 INZ(*BLANKS)
D JSMCMD S 2048 INZ(*BLANKS)
D ZEROLENGTH S 10I 0 INZ(0)
*
D FLD1 DS
D EMPLOYEE 50A INZ('John Smith')
D SURNAME 30A INZ('Smith')
D SALARY 7P 2 INZ(30000.50)
D AGE 3S 0 INZ(25)
D DATE D DATFMT(*ISO)
D DATETIME Z
*
D LST1 DS OCCURS(10)
D EMPNME 50 INZ('Acme Corp')
D SURNME 35 INZ('Jones')
D GIVENME 20 INZ('Bill')
*
* Initialize
*
C CALLB(D) 'JSMX_BEGIN'
C PARM *OMIT
C PARM ZEROLENGTH
*
* Open connection
*
C CLEAR JSMSRV
C EVAL JSMSRV = 'LOCALHOST:4560'
C CALLB(D) 'JSMX_OPEN'
C PARM JSMHDL
C PARM JSMSRV
C PARM JSMSTS
C PARM JSMMSG
*
* Bind Fields
*
C EVAL DATE = %DATE()
C EVAL DATETIME = %TIMESTAMP()
*
C EVAL FieldDefSize = %SIZE(FieldDef1:*ALL)
C EVAL FieldEntSize = %SIZE(FLD1)
C CALLB(D) 'JSMX_BINDFLD'
C PARM JSMHDL
C PARM FieldDef1
C PARM FieldDefSize
C PARM FLD1
C PARM FieldEntSize
C PARM JSMSTS
C PARM JSMMSG
*
* Bind List - set list count
*
C EVAL ListDefSize = %SIZE(ListDef1:*ALL)
C EVAL ListEntSize = %SIZE(LST1)
C EVAL ListCount = 1
C EVAL ListMaxCount = %ELEM(LST1)
C CALLB(D) 'JSMX_BINDLST'
C PARM JSMHDL
C PARM ListDef1
C PARM ListDefSize
C PARM LST1
C PARM ListEntSize
C PARM ListCount
C PARM ListMaxCount
C PARM JSMSTS
C PARM JSMMSG
*
* Send command
*
C CLEAR JSMCMD
C EVAL JSMCMD = 'SERVICE_LOAD' +
C ' SERVICE(HTTPSERVICE)' +
C ' SERVICE_CONTENT(*HTTP)' +
C ' TRACE(*YES)'
C CALLB(D) 'JSMX_COMMAND'
C PARM JSMHDL
C PARM JSMCMD
C PARM JSMSTS
C PARM JSMMSG
*
* Bind List - use current value of list count
*
C EVAL ListDefSize = %SIZE(ListDef1:*ALL)
C EVAL ListEntSize = %SIZE(LST1)
C EVAL ListMaxCount = %ELEM(LST1)
C CALLB(D) 'JSMX_BINDLST'
C PARM JSMHDL
C PARM ListDef1
C PARM ListDefSize
C PARM LST1
C PARM ListEntSize
C PARM ListCount
C PARM ListMaxCount
C PARM JSMSTS
C PARM JSMMSG
*
* Send command
*
C CLEAR JSMCMD
C EVAL JSMCMD = 'SEND' +
C ' HANDLER(InboundFile)' +
C ' FILE(test-input/ValidatingXML.pdf)' +
C ' CONTENT(*PDF)' +
C ' UACACHE(5)'
C
C CALLB(D) 'JSMX_COMMAND'
C PARM JSMHDL
C PARM JSMCMD
C PARM JSMSTS
C PARM JSMMSG
*
* Send command
*
* CLEAR JSMCMD
* EVAL JSMCMD = 'SERVICE_UNLOAD'
* CALLB(D) 'JSMX_COMMAND'
* PARM JSMHDL
* PARM JSMCMD
* PARM JSMSTS
* PARM JSMMSG
*
* Close service
*
C CALLB(D) 'JSMX_CLOSE'
C PARM JSMHDL
C PARM JSMSTS
C PARM JSMMSG
*
* Finalize
*
C CALLB(D) 'JSMX_END'
*
C SETON LR
**CTDATA FieldDef1
EMPLOYEE A000005000
SURNAME A000003000
SALARY P000000702
AGE S000000300
DATE A000001000
DATETIME A000002600
**CTDATA FieldDef2
EMPLOYEE A000005000
SURNAME A000003500
GIVENAME A000002000
**CTDATA ListDef1
EMPLOYEE A000005000
SURNAME A000003500
GIVENAME A000002000