Seeking advice on AXIS transport API

Discussions relating to the ScottKlement.com port of the open source YAJL JSON Reader/Generator. This includes the YAJL tool as well as the YAJLR4, YAJLGEN, YAJLINTO and YAJLDTAGEN add-ons from ScottKlement.com. http://www.scottklement.com/yajl/
Post Reply
Dharshani
Posts: 5
Joined: Wed Nov 29, 2023 6:08 am

Seeking advice on AXIS transport API

Post by Dharshani »

Hi All,

I have used AXIS routines to get third party API response. I will provide some part of the code below,

Code: Select all

       Ctl-Opt OPTION(*SRCSTMT) FORMSALIGN(*NO) INDENT('| ') DECEDIT(*JOBRUN);                      
       Ctl-Opt PGMINFO(*PCML:*MODULE:*DCLCASE) DFTNAME(PGM_NAME);                                  
       Ctl-Opt DFTACTGRP(*NO) ACTGRP(*CALLER) BNDDIR('AXIS' : 'YAJL');                              
                                                                       
      /Copy /QIBM/ProdData/OS/WebServices/V1/client/include/Axis.rpgleinc                           
      /Include YAJL/QRPGLESRC,yajl_h                                    
                                                                       

       //Logs
       axiscAxisStartTrace(logPath : *NULL); 
	

	//(set the url value with parameter)

       //AXIS rotines
       // Create HTTP transport handle.                                                             
       tHandle = axiscTransportCreate(url : AXISC_PROTOCOL_HTTP11);                                 
       If (tHandle = *NULL);                                                                        
         errMsg = 'TransportCreate() failed';                                                       
         Return;                                                                                    
       EndIf;                                                                                       
                                                                                                    
       // Set HTTP method                                                                           
       propBuf1 = 'GET' + X'00';                                                                    
       rc = axiscTransportSetProperty(tHandle: AXISC_PROPERTY_HTTP_METHOD:                          
                                      %Addr(propBuf1));                                             
                                                                                                    
       propBuf1  = 'application/json' + X'00';                                                      
       rc = axiscTransportSetProperty(tHandle :                                                     
                                      AXISC_PROPERTY_HTTP_HEADER :                                  
                                      %Addr(tHandle));                                              
                                                                                                    
       // Set connect timeout value                                                                 
       propInt = 30;                                                                                
       rc = axiscTransportSetProperty(tHandle:                                                      
                                      AXISC_PROPERTY_CONNECT_TIMEOUT:                               
                                      %Addr(propInt));                                              
                                                                                                    
       // Set SSL information - turn off SSLv2 and sslv3.                                           
       CertStorePointer = %Alloc(%Len(%Trim(C_CERTSTORE)) + 1);                                     
       %Str(CertStorePointer: %Len(%Trim(C_CERTSTORE)) + 1) = C_CERTSTORE;                          
                                                                                                    
       NonePointer = %Alloc(%Len(%Trim(C_NONE)) + 1);                                               
       %Str(NonePointer: %Len(%Trim(C_NONE)) + 1) = C_NONE;                                         
                                                                                                    
       BlankPointer = %Alloc(%Len(%Trim(C_BLANK)) + 1);                                             
       %Str(BlankPointer: %Len(%Trim(C_BLANK)) + 1) = C_BLANK;                                      
                                                                                                    
       TruePointer = %Alloc(%Len(%Trim(C_TRUE)) + 1);                                               
       %Str(TruePointer: %Len(%Trim(C_TRUE)) + 1) = C_TRUE;                                         
                                                                                                    
       rc = axiscTransportSetProperty(tHandle:                                                      
                                      AXISC_PROPERTY_HTTP_SSL:                                      
                                      CertStorePointer:            // cert store                    
                                      BlankPointer :               // store pwd                     
                                      BlankPointer :               // cert label                    
                                      NonePointer :                // SSL V2                        
                                      NonePointer :                // SSL V3                        
                                      NonePointer :                // TLS V1                        
                                      NonePointer :                // TLS V1.1                      
                                      BlankPointer :               // TLS V1.2                      
                                      TruePointer :                // Tolerate soft warnings        
                                      BlankPointer :               // App ID                        
                                      BlankPointer :               // SNI                           
                                       *NULL);                                                      
       If (rc = -1);                                                                                
         checkError('TransportSetProperty:  HTTP_SSL');                                             
       EndIf;                                                                                       
                                                                                                    
       // Flush transport so request is sent and receive response.                                  
       rc = axiscTransportFlush(tHandle);                                                           
       If (rc = -1);                                                                                
         checkError ('TransportFlush()');                                                                                                                                   
       Else;                                                                                        
         flushAndReceiveData();                                                                     
       EndIf;                                                                                       
                                                                                                    
       // Cleanup handle.                                                                           
       axiscTransportDestroy(tHandle);     

//Procedure flushAndReceiveData
Dcl-Proc flushAndReceiveData;              
                                                                                                          Dcl-PI *n;                                                                                 
   End-PI;                                                                                    
                                                                                                    
         Dcl-S header Pointer;              
           Clear response;                                                                          
           Clear header;                                                                            
           scoreAvailable = *Off;                                                                   
           MOSQNO = *Zeros;                                                                         
                                                                                                    
           // Flush data so request is sent                                                         
           rc = axiscTransportFlush(tHandle);                                                       
           If (rc = -1);                                                                            
             checkError ('TransportFlush()');                                                       
             Return;                                                                                
           EndIf;                                                                                   
                                                                                                    
           Dou rc < 1;                                                                              
             // Receive data and print out data and response to stdout                              
             rc = axiscTransportReceive(tHandle: %Addr(response):                                   
                                      %Size(response) : 0);                                         
           EndDo;                                                                                  

//............. REST part of code.
These code works successfully for past few years. From the last week we have recieved errors.
Every fresh session's 1st request called successfully and return valid json response. from the second request the response receive an error like "400 Bad request" .
When I sign out from as400 and relogging, the first request respond successfully.
When I compare the trace logs I found following details, for the unsuccessfull request the trace executed 'ChannelFactory::preloadChannel(): ' but this is not executed for successfull request.

Please give me an advice on this regard? Why this kind of errors occured?
Dharshani
Posts: 5
Joined: Wed Nov 29, 2023 6:08 am

Re: Seeking advice on AXIS transport API

Post by Dharshani »

Hi All,

Kindy seeking a response on this. Could you please help me?
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: Seeking advice on AXIS transport API

Post by Scott Klement »

I have only used the AXISC Transport API twice, both for demo programs that have never been used in production. I have never run into the problem you're having, and I don't have any idea what "ChannelFactory::preloadChannel()" means. It doesn't appear to be an error message, but rather the name of a routine inside of AXIS -- so isn't particularly useful information.

This makes it very hard to help you.

My advice: Don't use the AXISC routines. If you need HTTP routines that are shipped as part of the operating system, use the ones in SQL (such as HTTP_GET) They MUCH MUCH easier to use than AXISC, and the newer ones also perform well. If you don't need to use something that comes with the OS, use HTTPAPI, it's far more powerful and easier to understand and fix problems. (There is no circumstance under which I recommend the AXISC routines anymore.)

Unfortunately, I just don't know the answer to the problem.
Dharshani
Posts: 5
Joined: Wed Nov 29, 2023 6:08 am

Re: Seeking advice on AXIS transport API

Post by Dharshani »

Hi Scott,

Thanks a lot for your response.
Post Reply