HTTPAPI and http_parse_xml_stmf error

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
rishabkshk
Posts: 2
Joined: Tue Nov 25, 2025 11:22 am

HTTPAPI and http_parse_xml_stmf error

Post by rishabkshk »

Hi Scott,

First of all thanks for making the life easier for us. It is truly beyond words, the work you have put in for the IBM i world.

I am having some programs erroring out for some reason when using http_parse_xml_stmf to parse xml documents on the IFS(stmf with ccsid 1208). The error is happening in the callback procedure. Below is the error occurring when moving `value` to the target field.

Code: Select all

Message . . . . :   Length of varying length variable is out of range.        
Cause . . . . . :   The length of a varying length character or DBCS variable 
  is less than 0 or greater than its declared maximum length in RPG procedure 
  RESPONSE in program xxxxx. 


Response procedure:

Code: Select all

P Response        B                                               
d Response        PI                                              
d   userdata                      *   value                       
d   depth                       10I 0 value                       
d   name                      1024A   varying const               
d   path                     24576A   varying const               
d   value                    32767A   varying const               
d   attrs                         *   dim(32767)                  
d                                     const options(*varsize)       
  
if (path = '/soap-env:Envelope/soap-env:Body/nm:WELSING/INPUT/POSDRER')   ;                               
     Select;                                               
     When (name = 'PO');                                                                    
        PurchaseOrder = %trim(value);  
    ENDSL;
endif;

Below is how it is being called:

Code: Select all

If (http_parse_xml_stmf( %trim(xmldocpath)                
                       : HTTP_XML_CALC                    
                       : *null                            
                       : %paddr(Response)                 
                       : *null ) < 0 );                                                               
EndIf;
Also the dump for the `value` variable :

Code: Select all

VALUE                 CHAR(32767)          VARYING(2)                                                                        
                                           '      ÿ· o4hpØ                                                Ø       H¸   ;º   '
                        81                 '                                     è                      ENDELEMENT          '
                        161                '              Ø       H¸   ;º           *N                                      '
                        241                '                                                                                '
                        321                '                                                                                '
                        401                '                                                                                '
                        481                '                                                                                '
                        561                '                                                                                '
                        641                '                                                                                '
                        721                '                                                                                '
                        801                '                                                                                '
                        881                '                                                                                '
                        961                '                                                                                '


I have also created another pgm to try and debug but it works well there. The issue is intermittent and does not occur on every file process. If there was any issue with the xml, then the program wouldn't work the second time for the same file. Only the `value` variable has junk data.

I also tried changing ccsid on the http_parse_xml_stmf and HTTP_XML_CALC has reduced the errors substantially but not all.

What could be the probable cause? memory corruption? activation groups? I am out of ideas at this moment.
Scott Klement
Site Admin
Posts: 952
Joined: Sun Jul 04, 2021 5:12 am

Re: HTTPAPI and http_parse_xml_stmf error

Post by Scott Klement »

What is the hex value of the first 4 bytes of the 'value' parameter?

How can this problem be reproduced?
rishabkshk
Posts: 2
Joined: Tue Nov 25, 2025 11:22 am

Re: HTTPAPI and http_parse_xml_stmf error

Post by rishabkshk »

Below is the dump output

Code: Select all

VALUE IN HEX         '8000000000000000D5F200B07C9EB740000000090000000000000000000000000000000000000000'X
  41                 '0000000000000000000000000000000000000000000000008000000000000000EF5FBFD6134F1EB0'X
  81                 '00000000000000000000000000000000000000000000000000000000000000000000000A00000054'X
  121                '00000000000000000000000000000000000000000000C5D5C4C5D3C5D4C5D5E30000000000000000'X
  161                '000000000000000000000000000000008000000000000000EF5FBFD6134F1EB04040404040404040'X
  201                '40405CD5404040404040404000000000000000000000000000000000000000000000000000000000'X
  241                '00000000000000000000000000000000000000000000000000000000000000000000000000000000'X
  281                '00000000000000000000000000000000000000000000000000000000000000000000000000000000'X
There is no way to consistently reproduce it. It keeps working until it does not.
Scott Klement
Site Admin
Posts: 952
Joined: Sun Jul 04, 2021 5:12 am

Re: HTTPAPI and http_parse_xml_stmf error

Post by Scott Klement »

The first 2 bytes of the value are x'8000', which means the length is 32768, since the parameter is defined as 32767, you are getting the error.

You talk like the error is sporadic, but... doesn't it happen consistently with certain XML documents? If you do the same document again, you don't get the error? That surprises me very much.

On the other hand, if a particular document does it consistently, I could probably solve the problem. But if its sporadic, I don't know what I can do.
Post Reply