HTTPサービスの例(XMLアウトバウンド)

LANSA Integrator

HTTPサービスの例(XMLアウトバウンド)


HTTPServiceサービスをロードします。アウトバウンドxmlコンテンツ・ハンドラーとスタイル・シート(XML変換ウィザードで作成)を使用してxmlの注文を作成します。

この例では、詳細をすべて返すホストにxmlを介して注文の一部を送信します。

以下のファンクションはIBM i で実行されます。

FUNCTION   OPTIONS(*DIRECT)                                    

**********                                                     

DEFINE     FIELD(#JSMSTS) TYPE(*CHAR) LENGTH(020)              

DEFINE     FIELD(#JSMMSG) TYPE(*CHAR) LENGTH(255)              

DEFINE     FIELD(#JSMCMD) TYPE(*CHAR) LENGTH(255)

**********                                                     

DEFINE     FIELD(#ORDER) TYPE(*CHAR) LENGTH(010)               

DEFINE     FIELD(#NAME) TYPE(*CHAR) LENGTH(050)                

DEFINE     FIELD(#STREET) TYPE(*CHAR) LENGTH(050)              

DEFINE     FIELD(#CITY) TYPE(*CHAR) LENGTH(050)                

DEFINE     FIELD(#STATE) TYPE(*CHAR) LENGTH(005)               

DEFINE     FIELD(#ZIP) TYPE(*CHAR) LENGTH(005)                 

**********                                                        

DEFINE     FIELD(#LINENUM) TYPE(*DEC) LENGTH(003) DECIMALS(0)     

DEFINE     FIELD(#PARTNUM) TYPE(*DEC) LENGTH(003) DECIMALS(0)     

DEFINE     FIELD(#PARTDSC) TYPE(*CHAR) LENGTH(050)                

DEFINE     FIELD(#PARTAMT) TYPE(*DEC) LENGTH(010) DECIMALS(2) EDIT

           _CODE(3)                                               

DEFINE     FIELD(#PARTQTY) TYPE(*DEC) LENGTH(003) DECIMALS(0) EDIT

           _CODE(Z)                                               

**********                                                        

DEF_LIST   NAME(#WRKLST) FIELDS(#LINENUM #PARTNUM #PARTDSC #PARTAM

           T #PARTQTY) TYPE(*WORKING)                             

DEF_LIST   NAME(#DSPLST) FIELDS(#LINENUM #PARTNUM #PARTAMT #PARTQT

           Y)                                                     

********** build partial order details                            

EXECUTE    SUBROUTINE(BUILDORD)                                   

BEGIN_LOOP                                                        

********** Get completed order details                            

CLR_LIST   NAMED(#DSPLST)                                         

SELECTLIST NAMED(#WRKLST)                                         

ADD_ENTRY  TO_LIST(#DSPLST)                                       

ENDSELECT                                                         

**********                                                        

DISPLAY    FIELDS(#ORDER #NAME #STREET #CITY #STATE #ZIP) BROWSELI

           ST(#DSPLST)                                            

********** 'Open service'                                         

USE        BUILTIN(JSM_OPEN) TO_GET(#JSMSTS #JSMMSG)              

EXECUTE    SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)          

**********                                                        

********** 'Load service'                                         

USE        BUILTIN(JSM_COMMAND) WITH_ARGS('''SERVICE_LOAD SERVICE(

           HTTPSERVICE)''') TO_GET(#JSMSTS #JSMMSG)               

EXECUTE    SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)          

********** 'Send REquest                                          

**********                                                        

CHANGE     FIELD(#JSMCMD) TO('SEND HANDLER(OXML) XSL(SENDORDER) HO

           ST(L04TST:85) URI(/CGI-BIN/JSMDIRECT?ORDERXML) SERVICE_ 

           LIST(LINENUM,PARTNUM,PARTDSC,PARTAMT,PARTQTY)')         

**********                                                         

USE        BUILTIN(JSM_COMMAND) WITH_ARGS(#JSMCMD) TO_GET(#JSMSTS  

           #JSMMSG #WRKLST)                                        

EXECUTE    SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)           

**********                                                         

********** 'Receive response'                                      

********** HANDLER(IXML) XSL(RECEIVEORDER) or                      

********** HANDLER(ISVL)                                           

**********                                                         

CHANGE     FIELD(#JSMCMD) TO('RECEIVE HANDLER(IXML) XSL(RECEIVEORD 

           ER) SERVICE_LIST(LINENUM,PARTNUM,PARTDSC,PARTAMT,PARTQT

           Y)')                                                   

CLR_LIST   NAMED(#WRKLST)                                         

USE        BUILTIN(JSM_COMMAND) WITH_ARGS(#JSMCMD) TO_GET(#JSMSTS 

           #JSMMSG #WRKLST)                                       

EXECUTE    SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)          

**********                                                        

********** 'Unload service'                                       

**********                                                        

USE        BUILTIN(JSM_COMMAND) WITH_ARGS('''SERVICE_UNLOAD''') TO

           _GET(#JSMSTS #JSMMSG)                                  

EXECUTE    SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)          

**********                                                        

********** 'Close service'                                        

USE        BUILTIN(JSM_CLOSE) TO_GET(#JSMSTS #JSMMSG)             

EXECUTE    SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)          

END_LOOP                                                          

********** SUB ROUTINES                                           

**********                                                        

SUBROUTINE NAME(CHECK) PARMS((#JSMSTS *RECEIVED) (#JSMMSG *RECEIVE

           D))                                         

IF         COND('#JSMSTS *NE OK')                      

DISPLAY    FIELDS(#JSMSTS #JSMMSG)                     

**********                                             

USE        BUILTIN(JSM_CLOSE) TO_GET(#JSMSTS #JSMMSG)  

**********                                             

MENU       MSGTXT('Java service error has occurred')   

**********                                             

ENDIF                                                  

ENDROUTINE                                             

**********                                             

SUBROUTINE NAME(BUILDORD)                                    

********** customer details                                  

CHANGE     FIELD(#ORDER) TO('''A123456789''')                

CHANGE     FIELD(#NAME) TO('''Uluru Vacations''')            

CHANGE     FIELD(#STREET) TO('''1 Main Street''')            

CHANGE     FIELD(#CITY) TO('''Alice Springs''')              

CHANGE     FIELD(#STATE) TO(NT)                              

CHANGE     FIELD(#ZIP) TO('''5000''')                        

********** create 2 order lines                              

CHANGE     FIELD(#PARTDSC #PARTAMT #PARTQTY) TO(*DEFAULT)    

CHANGE     FIELD(#LINENUM) TO(001)                           

CHANGE     FIELD(#PARTNUM) TO(123)                           

ADD_ENTRY  TO_LIST(#WRKLST)                                  

CHANGE     FIELD(#LINENUM) TO(002)            

CHANGE     FIELD(#PARTNUM) TO(456)            

ADD_ENTRY  TO_LIST(#WRKLST)                   

ENDROUTINE             

このファンクションは要求を処理して、更新された注文リストを返します。dc@w29のエントリーではこのファンクションを指定する必要があります。例えば、以下のようになります。

名前

ローカル・ホスト

プロセス名

ファンクション名

ORDERXML

*DEFAULT

JSM

EX06

FUNCTION   OPTIONS(*DIRECT)                                     

**********                                                      

DEFINE     FIELD(#JSMSTS) TYPE(*CHAR) LENGTH(020)               

DEFINE     FIELD(#JSMMSG) TYPE(*CHAR) LENGTH(255)               

DEFINE     FIELD(#JSMCMD) TYPE(*CHAR) LENGTH(255) 

**********                                                      

DEFINE     FIELD(#ORDER) TYPE(*CHAR) LENGTH(010)                

DEFINE     FIELD(#NAME) TYPE(*CHAR) LENGTH(050)                 

DEFINE     FIELD(#STREET) TYPE(*CHAR) LENGTH(050)               

DEFINE     FIELD(#CITY) TYPE(*CHAR) LENGTH(050)                 

DEFINE     FIELD(#STATE) TYPE(*CHAR) LENGTH(005)                

DEFINE     FIELD(#ZIP) TYPE(*CHAR) LENGTH(005)   

**********                                                        

DEFINE     FIELD(#LINENUM) TYPE(*DEC) LENGTH(003) DECIMALS(0)     

DEFINE     FIELD(#PARTNUM) TYPE(*DEC) LENGTH(003) DECIMALS(0)     

DEFINE     FIELD(#PARTDSC) TYPE(*CHAR) LENGTH(050)                

DEFINE     FIELD(#PARTAMT) TYPE(*DEC) LENGTH(010) DECIMALS(2)     

DEFINE     FIELD(#PARTQTY) TYPE(*DEC) LENGTH(003) DECIMALS(0)     

DEF_LIST   NAME(#WRKLST) FIELDS(#LINENUM #PARTNUM #PARTDSC #PARTAM

           T #PARTQTY) TYPE(*WORKING)                             

********** 'Open service'                                         

**********                                                        

USE        BUILTIN(JSM_OPEN) TO_GET(#JSMSTS #JSMMSG)              

EXECUTE    SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)          

**********                                                        

********** 'Load service'                                         

USE        BUILTIN(JSM_COMMAND) WITH_ARGS('''SERVICE_LOAD SERVICE(

           HTTPSERVICE)''') TO_GET(#JSMSTS #JSMMSG)               

EXECUTE    SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)          

**********                                                        

********** Receive XML order, SV order, POST order                

CHANGE     FIELD(#JSMCMD) TO('RECEIVE HANDLER(IXML) XSL(RECEIVEORD

           ER) SERVICE_LIST(LINENUM,PARTNUM,PARTDSC,PARTAMT,PARTQT

           Y)')                                                   

USE        BUILTIN(JSM_COMMAND) WITH_ARGS(#JSMCMD) TO_GET(#JSMSTS 

           #JSMMSG #WRKLST)                                       

EXECUTE    SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)          

**********                                                        

********** Process and validate                                

CHANGE     FIELD(#PARTAMT) TO(*DEFAULT)                           

SELECTLIST NAMED(#WRKLST)                                         

CHANGE     FIELD(#PARTQTY) TO('#PARTQTY + 10')                    

CHANGE     FIELD(#PARTAMT) TO('#PARTQTY * 125.25')                

UPD_ENTRY  IN_LIST(#WRKLST)                                       

ENDSELECT                                                         

********** Send response                                          

**********                                                        

CHANGE     FIELD(#JSMCMD) TO('SEND HANDLER(IXML) XSL(SENDORDER) SE

           RVICE_LIST(LINENUM,PARTNUM,PARTDSC,PARTAMT,PARTQTY)')  

********** ******                                                 

USE        BUILTIN(JSM_COMMAND) WITH_ARGS(#JSMCMD) TO_GET(#JSMSTS 

           #JSMMSG #WRKLST)                                       

EXECUTE    SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)          

**********                                                        

********** 'Close service'                                        

**********                                                        

USE        BUILTIN(JSM_CLOSE) TO_GET(#JSMSTS #JSMMSG)             

EXECUTE    SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)          

**********                                                        

********** SUB ROUTINES                                           

**********                                                        

SUBROUTINE NAME(CHECK) PARMS((#JSMSTS *RECEIVED) (#JSMMSG *RECEIVE

           D))                                         

IF         COND('#JSMSTS *NE OK')                      

**********                                             

********** Close service and send the HTTP response    

**********                                             

USE        BUILTIN(JSM_CLOSE) TO_GET(#JSMSTS #JSMMSG)  

ENDIF                                                  

ENDROUTINE