HTTP Service Example XML Outbound

LANSA Integrator

HTTP Service Example (XML Outbound)

Load HTTPService service. Creates xml order using Outbound xml content handler and stylesheet (created using the XML Transformation Wizard).

This example sends a partial order via xml to a host which returns the completed details.

The following function should be executed on the 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             

 

This function processes the request and returns an updated order list.  An entry in dc@w29 should specify this function e.g.

Service Name

Local Host

Process Name

Function Name

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