Submitted by milan.zdimal on Thu, 11/08/2007 - 00:00
Forums

I have gone though just about every function in tutorial 14, 15, 23 & 24. But I am unable to figure out how to output the raw XML data stored in an ILOB. I am processing a soap response and I would like to be able to ResponseWrite the entire soap enevelope, not just a single xpath value.

The most logical function that I thought would do it was ResponseWriteILOB; however, it outputs some kind of encoded string.

Does anyone know the solution to this? Please let me know.

My Code is below:

 
<%@ language="RPGLE" %>
<%
     d*' Include the ILOB and xml parser prototypes
      /include qasphdr,ilob
      /include qasphdr,xmlparser

     d file            s           1014    varying      
     d CRLF            c                   x'0D25'      
     d q               c                   ''''      
     d path            s            256    varying      
     d url             s           1014    varying      
     d Error           s               N      
     d reqILOB         s               *      
     d respILOB        s               *      
     d xmlPtr          s               *      
     d i               s             10i 0

     /free
         SetContentType('text/html; charset=windows-1252');

         file = './wsauth/auth.html';
         ResponseWriteTag(file : '*FIRST');

         if (form('username') > '' AND
             form('password') > '');

            exsr RunWebService;    
         endif;
         ResponseWriteTag(file : 'html-footer');

         return;


     Begsr RunWebService;
      //' create and reset my work ILOB's for my Web-Service            
         reqILOB  = SesGetILOB
('request');   // get a pointer to a session ILOB used as my request
         respILOB = SesGetILOB
('response');  // get a pointer to a session ILOB used for the response 
from the server
          ILOB_Clear(reqILOB);
          ILOB_Clear(respILOB);

      //' Build the SOAP request
          Exsr BuildReq;

      //' Build the URL string
          Url =  'http://192.168.1.226/response.xml';      

      //' My request is now ready to go to the server, so i call the 
httpRequest for ILOB's
          Error = ILOB_httpRequest(
             Url :                         // The URL in form:"http:/
/server:port/resource"
              30:                          // Number of seconds befor
e timing out  
              'POST':                      // The "POST" or "GET" met
hod               
              reqILOB:                     // pointer to my Request I
LOB               
              RespILOB                     // pointer to my Response ILOB

          );

      //' Check for errors
          if error;
             ResponseWrite(GetlastError('*MSGTXT'));
             leaveSr;
          endif;

      //' My data has arrived - I'll fire up the XML parser
          xmlPtr = XML_ParseILOB ( //' Returns XML-
object tree from an ILOB
              RespILOB:             //' Pointer to an ILOB object
              'syntax=loose':       //' Parsing options
              1208:                 //' The ccsid of the input ilob  (0
=current job)
              0                     //' The ccsid of the XML tree (0=cu
rrent job)            
          );
      //' Check for errors
          if XML_Error(xmlPtr);
             ResponseWrite(XML_Message(xmlPtr));
             XML_Close(xmlPtr);
             leaveSr;
          endif;
      //' Use X-path to get data from the XML tree
      //' The number of elements is given by the [UBOUND] now we just 
index through it
           path = '/soap:Envelope/soap:Body/m0:AuthenticateResponse'
                + '/m0:AuthenticateResult';

          ResponseWrite('<hr/><b>Login Value: </b>');
          ResponseWrite(XML_GetValue
(xmlPtr:path:'Invalid Soap Packet'));

          ResponseWrite('<hr/><b>Soap Packet:</b>');
          ILOB_SaveToStream(RespILOB:'/www2/debug.txt':'w,ccsid=277'); 


          XML_Close(xmlPtr);
      EndSr;


      Begsr BuildReq;
      //' Now i want to populate a simple XML request. - 
my ILOB header need a content type XML
      //' All httpRequest are routet to the same default job hench the
 cookie
        ILOB_SetHeaderBuf(
          reqILOB :
          'Content-Type: application/xml; charset=windows-
1252' + CRLF +
          'SOAPAction: "http://icebreak.org/"'
        );

      //' I reroute my response object to the request ILOB, so I can u
se the ASP sysnax for creating the XML
      //' Here we build the SOAP envelope and body -
 this was copied from running the webservice interactive.
          SetResponseObject(reqILOB);

      %><?xml version="1.0" encoding="UTF-8"?>
         <soap:Envelope xmlns:xsi=http://www.w3.org/2001/XMLSchema-
instance xmlns:xsd=http://www.w3.org/2001/XMLSchema xmlns:soap="http
://schemas.xmlsoap.org/soap/envelope/">
            <soap:Body>
              <m0:Authenticate xmlns:m0=http://<edit>/ldapauthenticati
on>
                <m0:username><%= form('username') %></m0:username>
                <m0:password><%= form('password') %></m0:password>
              </m0:Authenticate>
            </soap:Body>
          </soap:Envelope><%

      //' Now i redirect my response back to the default responce obje
t ( thats what my browser receives )
           SetResponseObject(*NULL);
       //  SetEncodingType('*html');
       EndSr; 
%> 

Re: Converting an ILOB to a Raw Text String
Hi Milan;

You are so close - what you are missing is just setting the transfere between the ILOB and the responseobject to binary. it will look like: 

 
  %><xmp><% 
 ILOB_SetWriteBinary(MyresultIlob : *ON); // This is already in ASCII
  ResponseWriteIlob(MyresultIlob);
  %></xmp><% 

Note the XMP tag. If you omit that it it will just be a part of the response but you cant see it