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.
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?