[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: First Attempt At Decoding Base64 XML Element



Donnie,

I fixed the namespace problem with v1.15.3 and I successfully generated a stub, which successfully received the response message of your web service.

Please find the sample attached as plain text.

The v1.13 Base64 UnMarshaller always returns the binary data as it has been encoded on the server. For example, when the server encodes a PDF to Base64, the Base64 UnMarshaller returns the binary data of that PDF. After having saved the binary data to a stream file, the stream file can be opened with Acrobat Reader.

Starting with v1.15 you can control that behavior with parameter BASE64TYPE of the WSDL2RPG command. The default value is *BINARY which makes the Base64 UnMarshaller to return binary data. With *CHAR the UnMarshaller decodes the Base64 data to binary and then translates it to the job CCSID:

  when (depth = 2
         and
         name = 'transactions');
     p_assert(namespace = ''
        : 'Namespace should be empty');
     if (not Value_isNil(attrs));
        UnMarshaller_setFieldIdentifier(name: path);
        currentItem.transactions =
           UnMarshaller_toBase64Binary(value); // = BASE64TYPE(*BINARY)
           // : getPostCcsid());                  = BASE64TYPE(*CHAR)
     endif;

Here is what I did in my test program to parse the Base64 encoded XML document of element <transactions>:

  // If the Web service finished successfully ...
  if (not OTSWebSvcs_Port_isError());
     // ... get response data from response data structure
     rc = http_parse_xml_string(
             %addr(dequeue2Response.dequeue2Return.transactions) + 2
             : %len(dequeue2Response.dequeue2Return.transactions)
             : OTSWebSvcs_Port_getPostCcsid() // = 1208
             : *null
             : %paddr(incoming)
             : %addr(result));

     if (rc <> 0);
        text = http_error();
        sndMsg(text);
     else;
        if (result <> 'Hello World');
           sndMsg('Result does not match ''Hello World''');
        else;
           sndMsg('*** Success ***');
        endif;
     endif;

Parser callback procedure:

 P Incoming        B
 D Incoming        PI
 D   userdata                      *   value
 D   depth                       10I 0 value
 D   name                      1024A   varying const
 D   path                     24576A   varying const
 D   value                    65535A   varying const
 D   attrs                         *   dim(32767)
 D                                     const options(*varsize)
 D result          S                   like(userData_t ) based(userdata)
  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  /free
     if ( path = '');
        select;
        when name = 'Test';
           result = value;
        endsl;
     endif;
  /end-free
 P                 E

The server side of this test case is an Axis2 web service that has been generated from your WSDL file.

Thomas.


Am 27.10.2012 00:04, schrieb Donnie:
    Thomas,

    I would like to run your attached program here but I get the following
    message when I try to download your attachment:



    "Forbidden.  You don't have permission to access
    /pipermail/ftpapi/attachments/20121026/2c431c5a/attachment.zip on this
    server."



    I'll debug impl_dequeue2ResponseStart() like you suggested and let you
    know what I find.



    A few facts on my end:



    1.  soapUI returns the correct response for me, too.

    2.  I'm currently using WSDL2RPG v1.15.2 and HTTPAPI v1.24

    3.  The generated test stub returns an empty response from the
    webservice call.

    4.  Add OTSWebSvcs_RedirectResponse_toStmf(stmf);  to the test stub and
    I get the attached file.





    I still have WSDL2RPG v1.13 on our box and the test stub generated from
    that version did return a response.  If I go back to v1.13 let me ask
    this.  The <transactions> element will be returned as EBCDIC or ASCII?
    If ASCII, then what is the recommended way to convert it to EBCDIC?  As
    for parsing the <transactions> element, would you agree that HTTPAPI
    procedure: http_parse_xml_string() would be the best choice?



    Thanks,

    Donnie





      ------------------------------
      Message: 4
      Date: Fri, 26 Oct 2012 20:58:04 +0200
      From: Thomas Raddatz <[1]thomas.raddatz@xxxxxxxxxxx>
      To: HTTPAPI and FTPAPI Projects <[2]ftpapi@xxxxxxxxxxxxxxxxxxxxxx>
      Subject: Re: First Attempt At Decoding Base64 XML Element
      Message-ID: <[3]508ADD3C.1050500@xxxxxxxxxxx>
      Content-Type: text/plain; charset=ISO-8859-1; format=flowed
      Another option is to start the debugger for ESSSRV02 and adding a
      breakpoint to the "select;" statement of procedure
      impl_dequeue2ResponseStart().
      When the debugger stops with "depth = 1" check the "namespace"
      variable. If
      it is empty, remove the following statement, compile your program
      and try
      it again:
          select;
          when (depth = 1
                 and
                 name = 'dequeue2Response'
      Add:      );
      Rmv:      and
      Rmv:      namespace = '[4]http://websvcs.otswebws');
             if (MultiRef_isReference(attrs));
      If that does not work, you should send the debug log to me.
      Thomas.
      ------------------------------
      Message: 5
      Date: Fri, 26 Oct 2012 22:30:09 +0200
      From: Thomas Raddatz <[5]thomas.raddatz@xxxxxxxxxxx>
      To: HTTPAPI and FTPAPI Projects <[6]ftpapi@xxxxxxxxxxxxxxxxxxxxxx>
      Subject: Re: First Attempt At Decoding Base64 XML Element
      Message-ID: <[7]508AF2D1.8050205@xxxxxxxxxxx>
      Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"
      Donnie,
      After are more extensive test I am no longer sure what is going
      wrong on
      your side. Attached you find your programs, slightly changed to make
      them
      run on our system.
      I used soapUI and the response that you posted on 23.10.2012. Guess
      what? I
      got back everything:
       > EVAL dequeue2Response
         DEQUEUE2RESPONSE.DEQUEUE2RETURN.COUNT = 3
         DEQUEUE2RESPONSE.DEQUEUE2RETURN.TRANSACTIONS =

      ....5...10...15...20...25...30...35...40...45...50...55...60
              1   '<?xml version="1.0" encoding="UTF-8"?><tranBlock><tran
      ID="7'
             61   '939" companyID="TMTSW" auxID="0093368348"><T.7.01.0>
      <key>26'
            121   '75704</k'
         DEQUEUE2RESPONSE.DEQUEUE2RETURN.TRANSACTIONIDOUT = 7941
      Please compare the changed modules with the one you use.
      You do not need to try 1.15.2 because that version seems to have a
      problem
      with the namespaces (actually no namespaces) of your wsdl. These
      namespaces
      are driving me crazy. I wished someone could explain that to me in
      detail.
      I understand that an element has to be qualified with a namespace
      prefix
      when it is a complex type that is a child of another complex type
      and if
      both namespaces are different. It has to be qualified even if the
      schema
      specifies "elementFormDefault" as "unqualified". I am going to check
      that
      again.
      Thomas.
      -------------- next part --------------
      A non-text attachment was scrubbed...
      Name: Donnie.zip
      Type: application/zip
      Size: 18636 bytes
      Desc: not available
      URL:
      <[8]http://scottklement.com/pipermail/ftpapi/attachments/20121026/2c
      431c5a/attachment.zip>
      ------------------------------

References

    1. mailto:thomas.raddatz@xxxxxxxxxxx
    2. mailto:ftpapi@xxxxxxxxxxxxxxxxxxxxxx
    3. mailto:508ADD3C.1050500@xxxxxxxxxxx
    4. http://websvcs.otswebws/
    5. mailto:thomas.raddatz@xxxxxxxxxxx
    6. mailto:ftpapi@xxxxxxxxxxxxxxxxxxxxxx
    7. mailto:508AF2D1.8050205@xxxxxxxxxxx
    8. http://scottklement.com/pipermail/ftpapi/attachments/20121026/2c431c5a/attachment.zip



-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------


      /IF NOT DEFINED(PROTOTYPE_PMR049A)
      *======================================================================
      *  Generated by WSDL2RPG 1.15.2 / 17.10.2012
      *  Built on Oct 27, 2012 (13:43:22)
      *  Built for V6R1M0
      *  Based on WS_SRV v1.15.2
      *======================================================================
      *
      *   This source member contains the common procedures
      *   of web service port:
      *
      *      OTSWebSvcs
      *
      *======================================================================
      *   Pre-Compiler tags used by STRPREPRC to retrieve creation
      *   commands from the source member.
      * ---------------------------------------------------------------------
      * >>PRE-COMPILER<<
      *   >>CRTCMD<< CRTRPGMOD    MODULE(&LI/&OB) +
      *                           SRCFILE(&SL/&SF) +
      *                           SRCMBR(&SM);
      *   >>COMPILE<<
      *     >>PARM<< TRUNCNBR(*NO);
      *     >>PARM<< DBGVIEW(*LIST);
      *   >>END-COMPILE<<
      *   >>EXECUTE<<
      *   >>CMD<<    CRTSRVPGM +
      *              SRVPGM(&LI/&OB ) +
      *              MODULE(&LI/&OB   +
      *                     &LI/PMR049A01        +
      *                             ) +
      *              EXPORT(*ALL) +
      *              BNDSRVPGM(*LIBL/WSDL2RPGRT  +
      *                        *LIBL/MIME        +
      *                        *LIBL/HTTPMIME    +
      *                        *LIBL/BASICS1   ) +
      *              TEXT('+
      *              Web Service: OTSWebSvcs+
      *              ') +
      *              DETAIL(*BASIC);
      * >>END-PRE-COMPILER<<
      *======================================================================
     H NOMAIN
     H DEBUG
     H BNDDIR('HTTPAPI': 'QC2LE')
     H OPTION(*SRCSTMT : *NODEBUGIO)
     H EXTBININT(*YES)
      /ENDIF
      /IF NOT DEFINED(PROTOTYPE_DEFINED_PMR049A)
      /DEFINE PROTOTYPE_DEFINED_PMR049A
      *
      *   Type definitions
      /COPY QWSDL2RPG,TYPES_H
      /COPY QWSDL2RPG,PWSDL2R88                    WSDL2RPG: Public Helper Procedures
      /COPY QWSDL2RPG,PWSDL2R90                    WSDL2RPG: AppMsg
      *
      *   Array dimensions:
      *
      *   Web Service specific types:
      *
     D tns2_TransactionBlock2_t...
     D                 DS                  template
     D                                     qualified
     D  count                        10I 0
     D  transactions                128A   varying
     D  transactionIdOut...
     D                               20I 0
      *
      *
     D impl_dequeue2_t...
     D                 DS                  template
     D                                     qualified
     D  subscriberId                 10I 0
     D  transactionIdIn...
     D                               20I 0
      *
      *
     D impl_dequeue2Response_t...
     D                 DS                  template
     D                                     qualified
     D  dequeue2Return...
     D                                     likeds(tns2_TransactionBlock2_t)
      *
      *
      *   Public prototypes
      *
      *   Web service: Returns the endpoint of the Web service
     D OTSWebSvcs_Endpoint_get...
     D                 PR         32767A          varying
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Endpoint_get+
     D                                     ')
      *
      *   Web service: Sets the endpoint of the Web service
     D OTSWebSvcs_Endpoint_set...
     D                 PR
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Endpoint_set+
     D                                     ')
     D  i_url                     32767A   const varying  options(*varsize)
      *
      *   Web service: Returns the host name of the Web Service endpoint
     D OTSWebSvcs_Endpoint_getHost...
     D                 PR         32767A          varying
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Endpoint_getHost+
     D                                     ')
      *
      *   Web service: Sets the host name of the Web service endpoint
     D OTSWebSvcs_Endpoint_setHost...
     D                 PR
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Endpoint_setHost+
     D                                     ')
     D  i_url                     32767A   const varying  options(*varsize)
      *
      *   Web service: Returns the port of the Web Service endpoint
     D OTSWebSvcs_Endpoint_getPort...
     D                 PR            10I 0
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Endpoint_getPort+
     D                                     ')
      *
      *   Web service: Sets the port of the Web service endpoint
     D OTSWebSvcs_Endpoint_setPort...
     D                 PR
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Endpoint_setPort+
     D                                     ')
     D  i_port                       10I 0 const
      *
      *   Web service: Initializes the web services port
     D OTSWebSvcs_Port_initialize...
     D                 PR
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Port_initialize+
     D                                     ')
     D  i_operName                         const  like(wsdl_operName_t )
      *
      *   Web service: Sets the proxy server to use for the connection
     D OTSWebSvcs_Port_setHttpProxy...
     D                 PR
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Port_setHttpProxy+
     D                                     ')
     D  i_server                    256A   const
     D  i_port                       10I 0 const
      *
      *   Web service: Returns the proxy server to use for the connection
     D OTSWebSvcs_Port_getHttpProxy...
     D                 PR                         likeds(wsdl_proxy_t )
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Port_getHttpProxy+
     D                                     ')
      *
      *   Web service: Enables/disables the debug log of HTTP API
     D OTSWebSvcs_Port_setHttpDebug...
     D                 PR
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Port_setHttpDebug+
     D                                     ')
     D   i_status                      N   const
     D   i_fileName                 500A   const  varying  options(*nopass)
     D   i_verbose                     N   const  options(*nopass)
      *
      *   Web service: Returns the HTTP API debug settings
     D OTSWebSvcs_Port_getHttpDebug...
     D                 PR                         likeds(wsdl_httpDebug_t )
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Port_getHttpDebug+
     D                                     ')
      *
      *   Web service: Sets the CCSID used for POST data.
     D OTSWebSvcs_Port_setPostCcsid...
     D                 PR
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Port_setPostCcsid+
     D                                     ')
     D  i_post_ccsid                 10I 0 const
      *
      *   Web service: Returns the CCSID used for POST data.
     D OTSWebSvcs_Port_getPostCcsid...
     D                 PR            10I 0
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Port_getPostCcsid+
     D                                     ')
      *
      *   Web service: Sets the timeout that HTTPAPI uses
      *   when connecting to the server or waiting for response.
     D OTSWebSvcs_Port_setTimeout...
     D                 PR
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Port_setTimeout+
     D                                     ')
     D  i_timeout                    10I 0 const
      *
      *   Web service: Returns the timeout that HTTPAPI uses
      *   when connecting to the server or waiting for response.
     D OTSWebSvcs_Port_getTimeout...
     D                 PR            10I 0
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Port_getTimeout+
     D                                     ')
      *
      *   Web service: Sets the user-agent that HTTPAPI uses
      *   to identify the client at the server.
     D OTSWebSvcs_Port_setUserAgent...
     D                 PR
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Port_setUserAgent+
     D                                     ')
     D  i_userAgent                        const  like(wsdl_userAgent_t )
      *
      *   Web service: Returns the user-agent that HTTPAPI uses
      *   to identify the client at the server.
     D OTSWebSvcs_Port_getUserAgent...
     D                 PR                         like(wsdl_userAgent_t )
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Port_getUserAgent+
     D                                     ')
      *
      *   Web service: Clears all error information
     D OTSWebSvcs_Port_clearErrors...
     D                 PR
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Port_clearErrors+
     D                                     ')
     D  io_errors                                 likeds(wsdl_errors_t )
      *
      *   Web service: Sets error information
     D OTSWebSvcs_Port_setErrors...
     D                 PR
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Port_setErrors+
     D                                     ')
     D  i_errors                           const  likeds(wsdl_errors_t )
      *
      *   Http: Returns cTrue in case of an error, else cFalse.
     D OTSWebSvcs_Port_isError...
     D                 PR              N
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Port_isError+
     D                                     ')
      *
      *   Http: Returns the last HTTP error (code) that occurred.
     D OTSWebSvcs_HttpError_getCode...
     D                 PR                  like(wsdl_http_ErrorNo_t  )
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _HttpError_getCode+
     D                                     ')
      *
      *   Http: Returns the last HTTP error (text) that occurred.
     D OTSWebSvcs_HttpError_getText...
     D                 PR                  like(wsdl_http_ErrorText_t)
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _HttpError_getText+
     D                                     ')
      *
      *   Soap: Returns the last SOAP error (code) that occurred.
     D OTSWebSvcs_SoapError_getCode...
     D                 PR                  like(wsdl_soap_faultcode_t  )
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _SoapError_getCode+
     D                                     ')
      *
      *   Soap: Returns the last SOAP error (text) that occurred.
     D OTSWebSvcs_SoapError_getText...
     D                 PR                  like(wsdl_soap_faultstring_t)
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _SoapError_getText+
     D                                     ')
      *
      *   Soap: Returns the last XML error (code) that occurred.
     D OTSWebSvcs_XmlError_getCode...
     D                 PR                  like(wsdl_xml_errorNo_t    )
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _XmlError_getCode+
     D                                     ')
      *
      *   Soap: Returns the last XML error (text) that occurred.
     D OTSWebSvcs_XmlError_getText...
     D                 PR                  like(wsdl_xml_ErrorText_t  )
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _XmlError_getText+
     D                                     ')
      *
      *   Registers an user callback procedure, that is called whenever
      *   a web service requires user authentification.
     D OTSWebSvcs_Port_registerLoginCallback...
     D                 PR
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Port_registerLoginCallback+
     D                                     ')
     D  i_pLoginProc                   *   value  procptr
      *
      *   Returns *ON if a login procedures has been registered.
     D OTSWebSvcs_Port_hasLoginCallback...
     D                 PR              N
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Port_hasLoginCallback+
     D                                     ')
      *
      *   Login to proxy server or web service.
     D OTSWebSvcs_Port_login...
     D                 PR            10I 0
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Port_login+
     D                                     ')
     D  i_http_err                   10I 0 value
     D  i_numAttempts                10I 0 value
      *
      *   Returns the name of the web service port.
     D OTSWebSvcs_Port_getName...
     D                 PR           512A          varying
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Port_getName+
     D                                     ')
      *
      *   Returns the UUID of the web service port.
     D OTSWebSvcs_Port_getUuid...
     D                 PR                         like(wsdl_uuid_t )
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Port_getUuid+
     D                                     ')
      *
      *   Adds an attachments to the list of attachments.
     D OTSWebSvcs_Attachments_put...
     D                 PR
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Attachments_put+
     D                                     ')
     D  i_attachmentID...
     D                                     const  like(wsdl_attachmentID_t )
     D  i_fileName                         const  like(wsdl_path_t         )
     D  i_uuid                             const  like(wsdl_uuid_t         )
     D                                            options(*nopass)
      *
      *   Returns the file name of the attachment that is associated to
      *   a given content ID.
     D OTSWebSvcs_Attachments_get...
     D                 PR                  like(wsdl_path_t     )
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Attachments_get+
     D                                     ')
     D  i_attachmentID...
     D                                     const  like(wsdl_attachmentID_t )
     D  i_uuid                             const  like(wsdl_uuid_t         )
     D                                            options(*nopass)
      *
      *   Returns the file name of the attachment that is associated to
      *   a given index.
     D OTSWebSvcs_Attachments_getAtPos...
     D                 PR                  likeds(wsdl_attachment_t )
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Attachments_getAtPos+
     D                                     ')
     D  i_index                      10I 0 const
     D  i_uuid                             const  like(wsdl_uuid_t         )
     D                                            options(*nopass)
      *
      *   Returns the number of attachments that were downloaded with the
      *   last call to the web service.
     D OTSWebSvcs_Attachments_getNumE...
     D                 PR            10I 0
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Attachments_getNumE+
     D                                     ')
     D  i_uuid                             const  like(wsdl_uuid_t         )
     D                                            options(*nopass)
      *
      *   Removes all attachments from the list of attachments of this web service.
     D OTSWebSvcs_Attachments_removeAll...
     D                 PR
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Attachments_removeAll+
     D                                     ')
     D  i_uuid                             const  like(wsdl_uuid_t         )
     D                                            options(*nopass)
      *
      *   Specifies the name of the folder where to put attachments in.
     D OTSWebSvcs_Attachments_setFolder...
     D                 PR
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Attachments_setFolder+
     D                                     ')
     D  i_folder                           const  like(wsdl_pathLong_t )
      *
      *   Returns the name of the folder where attachments are stored.
     D OTSWebSvcs_Attachments_getFolder...
     D                 PR                         like(wsdl_pathLong_t )
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Attachments_getFolder+
     D                                     ')
      *
      *   Enables redirection of the HTTP response message to a
      *   stream file in the IFS.
     D OTSWebSvcs_RedirectResponse_toStmf...
     D                 PR
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _RedirectResponse_toStmf+
     D                                     ')
     D  i_stmf                             const  like(wsdl_pathLong_t )
     D  i_replace                      N   const  options(*nopass: *omit)
     D  i_ccsid                      10I 0 const  options(*nopass: *omit)
     D  i_auth                       10I 0 const  options(*nopass: *omit)
      *
      *   Returns cTrue if response redirection is active, otherwise cFalse.
     D OTSWebSvcs_RedirectResponse_isActive...
     D                 PR              N
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _RedirectResponse_isActive+
     D                                     ')
      *
      *   Terminates a response redirection and closes the
      *   file that receiced the response.
     D OTSWebSvcs_RedirectResponse_write...
     D                 PR              N
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _RedirectResponse_write+
     D                                     ')
     D  i_data                         *   value
     D  i_length                     10I 0 value
      *
      *   Terminates a response redirection and closes the
      *   file that receiced the response.
     D OTSWebSvcs_RedirectResponse_terminate...
     D                 PR
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _RedirectResponse_terminate+
     D                                     ')
      *
      /ENDIF
      /IF DEFINED(PROTOTYPE_PMR049A)
      /EOF
      /ENDIF
      * ---------------------------------------------------------------------
      *
      * ------------------------------------
      *  Imported prototypes
      * ------------------------------------
      /COPY QBASICS1,PBASICS1                      Tools/400 Runtime Library
      /COPY QRPGLESRC,HTTPAPI_H                    HTTP-API Service Program
      *
      /COPY QWSDL2RPG,PWSDL2R71                    WSDL2RPG: HTTP Debug Log
      /COPY QWSDL2RPG,PWSDL2R89                    WSDL2RPG: List of Attachments
      *
      * ------------------------------------
      *  Internal prototypes
      * ------------------------------------
      *
     D getEndpoint...
     D                 PR         32767A          varying
     D                                     extproc('+
     D                                     getEndpoint+
     D                                     ')
      *
     D setEndpoint...
     D                 PR
     D                                     extproc('+
     D                                     setEndpoint+
     D                                     ')
     D  i_url                     32767A   const varying  options(*varsize)
      *
      * ------------------------------------
      *  Global fields & constants
      * ------------------------------------
      *
      *   Web service port name
     D cWEB_SERVICE_PORT_NAME...
     D                 C                   'OTSWebSvcs'
      *
      *   UUID of the web service as generated by WSDL2RPG
     D cWEB_SERVICE_UUID...
     D                 C                   '7D0CE801096319709C320004AC1144E3'
      *
      *   Default and current attachment folder
     D cATTACHMENT_FOLDER...
     D                 C                   '/tmp/attachments/'
      *
      *   Default POST data CCSID (1208 = UTF-8)
     D cPOST_DATA_CCSID...
     D                 C                   1208
      *
      *   Web service endpoint as specified in the WSDL file.
     D cURL            C                   'http://localhost:8080/axis2/service+
     D                                     s/OTSWebSvcsService'
      *
      *   Web service endpoint
     D g_url           S          32767A   varying inz(cURL)
      *
      *   Proxy server to use
     D g_proxy         DS                  likeds(wsdl_proxy_t     ) inz
      *
      *   HTTPAPI debug settings
     D g_httpDebug     DS                  likeds(wsdl_httpDebug_t ) inz
      *
      *   POST data CCSID (1208 = UTF-8)
     D g_post_ccsid...
     D                 S             10I 0 inz(cPOST_DATA_CCSID)
      *
      *   Timeout in seconds used when connecting to the server
      *   or waiting for response from the server.
     D g_timeout...
     D                 S             10I 0 inz(HTTP_TIMEOUT)
      *
      *   User-agent used when connecting to the server.
     D g_userAgent...
     D                 S                   like(wsdl_userAgent_t )
     D                                     inz(HTTP_USERAGENT)
      *
      *   Name of the directory used to store attachments
     D g_attachmentFolder...
     D                 S                   like(wsdl_pathLong_t )
     D                                     inz(cATTACHMENT_FOLDER)
      *
      *   Redirect response status information
     D g_redirectResponse...
     D                 DS                  qualified
     D  isActive                       N   inz(cFalse)
     D  ccsid                        10I 0 inz
     D  auth                         10I 0 inz
     D  options                      10I 0 inz
     D  fd                           10I 0 inz(-1)
     D  path                               like(wsdl_pathLong_t ) inz
      *
      *   Web service error information
     D g_errors        DS                  likeds(wsdl_errors_t    ) inz
      *
      *   User callback to supply login information
      *   Returns WSDL_SUCCESS if successful, WSDL_ERROR upon error.
     D g_getLoginDataImpl...
     D                 S               *   procptr inz
      *
      *   User callback to supply login information
      *   Returns WSDL_SUCCESS if successful, WSDL_ERROR upon error.
      *
      *   Parameter description:
      *     i_authType         Authentication type:
      *                          WSDL_AUTH_TYPE_HTTP  - HTTP server.
      *                          WSDL_AUTH_TYPE_PROXY - Proxy server.
      *     i_realm            Authentication realm.
      *     i_numAttempts      Number of login attempts.
      *     o_user             UserName to use.
      *     o_password         Password to use.
      *
     D OTSWebSvcs_Port_supplyLoginData...
     D                 PR            10I 0
     D                                     extproc('+
     D                                     OTSWebSvcs+
     D                                     _Port_supplyLoginData+
     D                                     ')
     D  i_authType                   14A          const  varying
     D  i_realm                     126A          const  varying
     D  i_numAttempts                10I 0        const
     D  o_user                       50A                 varying
     D  o_password                   50A                 varying
      *
      * =====================================================================
      *   *** public ***
      *   Web service: Returns the endpoint of the Web service
      * =====================================================================
     P OTSWebSvcs_Endpoint_get...
     P                 B                   export
      *
     D OTSWebSvcs_Endpoint_get...
     D                 PI         32767A          varying
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         return getEndpoint();

      /end-free
      *
     P OTSWebSvcs_Endpoint_get...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Web service: Sets the endpoint of the Web service
      * =====================================================================
     P OTSWebSvcs_Endpoint_set...
     P                 B                   export
      *
     D OTSWebSvcs_Endpoint_set...
     D                 PI
     D  i_url                     32767A   const varying  options(*varsize)
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         setEndpoint(%subst(i_url: 1: %len(i_url)));

         return;

      /end-free
      *
     P OTSWebSvcs_Endpoint_set...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Web service: Returns the host name of the Web Service endpoint
      * =====================================================================
     P OTSWebSvcs_Endpoint_getHost...
     P                 B                   export
      *
     D OTSWebSvcs_Endpoint_getHost...
     D                 PI         32767A          varying
      *
     D tmpUrl          S                   like(url_t ) inz
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         tmpUrl = URL_new(getEndpoint());

         return URL_getHost(tmpUrl);

      /end-free
      *
     P OTSWebSvcs_Endpoint_getHost...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Web service: Sets the host name of the Web service endpoint
      * =====================================================================
     P OTSWebSvcs_Endpoint_setHost...
     P                 B                   export
      *
     D OTSWebSvcs_Endpoint_setHost...
     D                 PI
     D  i_host                    32767A   const varying  options(*varsize)
      *
     D tmpUrl          S                   like(url_t ) inz
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         tmpUrl = URL_new(getEndpoint());
         URL_setHost(tmpUrl: %subst(i_host: 1: %len(i_host)));
         setEndpoint(URL_toString(tmpUrl));

         return;

      /end-free
      *
     P OTSWebSvcs_Endpoint_setHost...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Web service: Returns the port of the Web Service endpoint
      * =====================================================================
     P OTSWebSvcs_Endpoint_getPort...
     P                 B                   export
      *
     D OTSWebSvcs_Endpoint_getPort...
     D                 PI            10I 0
      *
     D tmpUrl          S                   like(url_t ) inz
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         tmpUrl = URL_new(getEndpoint());

         return URL_getPort(tmpUrl);

      /end-free
      *
     P OTSWebSvcs_Endpoint_getPort...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Web service: Sets the port of the Web service endpoint
      * =====================================================================
     P OTSWebSvcs_Endpoint_setPort...
     P                 B                   export
      *
     D OTSWebSvcs_Endpoint_setPort...
     D                 PI
     D  i_port                       10I 0 const
      *
     D tmpUrl          S                   like(url_t ) inz
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         tmpUrl = URL_new(getEndpoint());
         URL_setPort(tmpUrl: i_port);
         setEndpoint(URL_toString(tmpUrl));

         return;

      /end-free
      *
     P OTSWebSvcs_Endpoint_setPort...
     P                 E
      *
      * =====================================================================
      *   *** private, automatically called by WS_OPER() ***
      *   Web service: Initializes the web service port.
      * =====================================================================
     P OTSWebSvcs_Port_initialize...
     P                 B                   export
      *
     D OTSWebSvcs_Port_initialize...
     D                 PI
     D  i_operName                         const  like(wsdl_operName_t )
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         // This procedure is called from every web service
         // operation right at the beginning of the operation.
         // This procedure may be used to perform any type
         // of initialization that is the same for all web
         // service operations.
         // For example you may want to register a procedure
         // to supply login credentials like this:

         if (not OTSWebSvcs_Port_hasLoginCallback());
            OTSWebSvcs_Port_registerLoginCallback(
               %paddr('+
                  OTSWebSvcs_Port_supplyLoginData+
               '));
         endif;

         return;

      /end-free
      *
     P OTSWebSvcs_Port_initialize...
     P                 E
      *
      * =====================================================================
      *   *** private, automatically called by *_Port_login() ***
      *   Web service: Supplies login credentials for web services that
      *                require BASIC or DIGEST authentication.
      * =====================================================================
     P OTSWebSvcs_Port_supplyLoginData...
     P                 B                   export
      *
     D OTSWebSvcs_Port_supplyLoginData...
     D                 PI            10I 0
     D  i_authType                   14A          const  varying
     D  i_realm                     126A          const  varying
     D  i_numAttempts                10I 0        const
     D  o_user                       50A                 varying
     D  o_password                   50A                 varying
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         // This procedure is called when a web service requires
         // BASIC or DIGEST authentication.
         // You may use the realm value for reading the credentials
         // from a file. Make sure that you do not get into an endless
         // loop in case the credentials are retrieved from a file.
         // The credentials might be wrong!

         // Prevent endless loop when reading the credentials from a file
         // You may remove this IF statement when a user enters the
         // credentials.
         if (i_numAttempts > 1);
            return WSDL_ERROR;
         endif;

         // Set o_user and o_password here and remove the error message.
         // Return WSDL_SUCCESS to let the caller know that user and
         // password have been set, otherwise return WSDL_ERROR.

         clear USR0048;
         USR00481 = f_this();
         AppMsg_sendCancelMsg(AppMsg_newError('USR0048': USR0048));

         return WSDL_ERROR;

      /end-free
      *
     P OTSWebSvcs_Port_supplyLoginData...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Web service: Sets the proxy server to use for the connection
      * =====================================================================
     P OTSWebSvcs_Port_setHttpProxy...
     P                 B                   export
      *
     D OTSWebSvcs_Port_setHttpProxy...
     D                 PI
     D  i_server                    256A   const
     D  i_port                       10I 0 const
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         g_proxy.server = i_server;

         if (g_proxy.server = '');
            g_proxy.port = 0;
         else;
            g_proxy.port = i_port;
         endif;

         return;

      /end-free
      *
     P OTSWebSvcs_Port_setHttpProxy...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Web service: Returns the proxy server to use for the connection
      * =====================================================================
     P OTSWebSvcs_Port_getHttpProxy...
     P                 B                   export
      *
     D OTSWebSvcs_Port_getHttpProxy...
     D                 PI                         likeds(wsdl_proxy_t )
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         return g_proxy;

      /end-free
      *
     P OTSWebSvcs_Port_getHttpProxy...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Web service: Enables/disables the debug log of HTTP API
      * =====================================================================
     P OTSWebSvcs_Port_setHttpDebug...
     P                 B                   export
      *
     D OTSWebSvcs_Port_setHttpDebug...
     D                 PI
     D   i_status                      N   const
     D   i_fileName                 500A   const  varying  options(*nopass)
     D   i_verbose                     N   const  options(*nopass)
      *
      *  Parameter positions
     D p_fileName      C                   2
     D p_verbose       C                   3
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         g_httpDebug.status = i_status;

         if (%parms() >= p_fileName);
            g_httpDebug.fileName = i_fileName;
         else;
            g_httpDebug.fileName = '';
         endif;

         if (i_status);
            if (g_httpDebug.fileName = '');
               g_httpDebug.fileName = HTTP_API_DEFAULT_LOG_FILE;
            endif;
         else;
            g_httpDebug.fileName = '';
         endif;

         if (i_status);
            http_DebugLog_open(g_httpDebug.fileName);
         else;
            http_DebugLog_close();
         endif;

         if (%parms() >= p_verbose);
            http_DebugLog_setVerbose(i_verbose);
         else;
            http_DebugLog_setVerbose(cFalse);
         endif;

         return;

      /end-free
      *
     P OTSWebSvcs_Port_setHttpDebug...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Web service: Returns the HTTP API debug settings
      * =====================================================================
     P OTSWebSvcs_Port_getHttpDebug...
     P                 B                   export
      *
     D OTSWebSvcs_Port_getHttpDebug...
     D                 PI                         likeds(wsdl_httpDebug_t )
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (g_httpDebug.fileName = '');
            g_httpDebug.fileName = HTTP_API_DEFAULT_LOG_FILE;
         endif;

         return g_httpDebug;

      /end-free
      *
     P OTSWebSvcs_Port_getHttpDebug...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Web service: Sets the CCSID used for POST data.
      *   An application may call this procedure right before the web service
      *   operation in order to specify a POST ccsid different from 1208.
      *   Usually it is not necessary to call this procedure.
      * =====================================================================
     P OTSWebSvcs_Port_setPostCcsid...
     P                 B                   export
      *
     D OTSWebSvcs_Port_setPostCcsid...
     D                 PI
     D  i_post_ccsid                 10I 0 const
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         g_post_ccsid = i_post_ccsid;

         return;

      /end-free
      *
     P OTSWebSvcs_Port_setPostCcsid...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Web service: Returns the CCSID used for POST
      * =====================================================================
     P OTSWebSvcs_Port_getPostCcsid...
     P                 B                   export
      *
     D OTSWebSvcs_Port_getPostCcsid...
     D                 PI            10I 0
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         return g_post_ccsid;

      /end-free
      *
     P OTSWebSvcs_Port_getPostCcsid...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Web service: Sets the timeout that HTTPAPI uses
      *   when connecting to the server or waiting for response.
      *   Usually it is not necessary to call this procedure.
      * =====================================================================
     P OTSWebSvcs_Port_setTimeout...
     P                 B                   export
      *
     D OTSWebSvcs_Port_setTimeout...
     D                 PI
     D  i_timeout                    10I 0 const
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         g_timeout = i_timeout;

         return;

      /end-free
      *
     P OTSWebSvcs_Port_setTimeout...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Web service: Returns the timeout that HTTPAPI uses
      *   when connecting to the server or waiting for response.
      * =====================================================================
     P OTSWebSvcs_Port_getTimeout...
     P                 B                   export
      *
     D OTSWebSvcs_Port_getTimeout...
     D                 PI            10I 0
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         return g_timeout;

      /end-free
      *
     P OTSWebSvcs_Port_getTimeout...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Web service: Sets the user-agent that HTTPAPI uses
      *   to identify the client at the server.
      *   Usually it is not necessary to call this procedure.
      * =====================================================================
     P OTSWebSvcs_Port_setUserAgent...
     P                 B                   export
      *
     D OTSWebSvcs_Port_setUserAgent...
     D                 PI
     D  i_userAgent                        const  like(wsdl_userAgent_t )
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         g_userAgent = i_userAgent;

         return;

      /end-free
      *
     P OTSWebSvcs_Port_setUserAgent...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Web service: Returns the user-agent that HTTPAPI uses
      *   to identify the client at the server.
      * =====================================================================
     P OTSWebSvcs_Port_getUserAgent...
     P                 B                   export
      *
     D OTSWebSvcs_Port_getUserAgent...
     D                 PI                         like(wsdl_userAgent_t )
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         return g_userAgent;

      /end-free
      *
     P OTSWebSvcs_Port_getUserAgent...
     P                 E
      *
      * =====================================================================
      *   *** private, automatically called by WS_OPER() ***
      *   Web service: Clears all error information.
      * =====================================================================
     P OTSWebSvcs_Port_clearErrors...
     P                 B                   export
      *
     D OTSWebSvcs_Port_clearErrors...
     D                 PI
     D  io_errors                                 likeds(wsdl_errors_t )
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         clear g_errors;
         g_errors.errType = WSDL_HTTP_SUCCESS;

         io_errors = g_errors;

         return;

      /end-free
      *
     P OTSWebSvcs_Port_clearErrors...
     P                 E
      *
      * =====================================================================
      *   *** private, automatically called by WS_OPER() ***
      *   Web service: Sets error information of last service call.
      * =====================================================================
     P OTSWebSvcs_Port_setErrors...
     P                 B                   export
      *
     D OTSWebSvcs_Port_setErrors...
     D                 PI
     D  i_errors                           const  likeds(wsdl_errors_t )
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         g_errors = i_errors;

         return;

      /end-free
      *
     P OTSWebSvcs_Port_setErrors...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Http: Returns the last HTTP error (code) that occurred.
      *   An application should use this procedure to check whether or not
      *   the web service operation has bee successfully executed.
      * =====================================================================
     P OTSWebSvcs_Port_isError...
     P                 B                   export
      *
     D OTSWebSvcs_Port_isError...
     D                 PI              N
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (g_errors.errType = WSDL_HTTP_SUCCESS);
            return cFalse;
         else;
            return cTrue;
         endif;

      /end-free
      *
     P OTSWebSvcs_Port_isError...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Http: Returns the last HTTP error (code) that occurred.
      * =====================================================================
     P OTSWebSvcs_HttpError_getCode...
     P                 B                   export
      *
     D OTSWebSvcs_HttpError_getCode...
     D                 PI                  like(wsdl_http_ErrorNo_t  )
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         return g_errors.httpError.no;

      /end-free
      *
     P OTSWebSvcs_HttpError_getCode...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Http: Returns the last HTTP error (text) that occurred.
      * =====================================================================
     P OTSWebSvcs_HttpError_getText...
     P                 B                   export
      *
     D OTSWebSvcs_HttpError_getText...
     D                 PI                  like(wsdl_http_ErrorText_t)
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         return g_errors.httpError.text;

      /end-free
      *
     P OTSWebSvcs_HttpError_getText...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Soap: Returns the last SOAP error (code) that occurred.
      * =====================================================================
     P OTSWebSvcs_SoapError_getCode...
     P                 B                   export
      *
     D OTSWebSvcs_SoapError_getCode...
     D                 PI                  like(wsdl_soap_faultcode_t  )
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         return g_errors.soapFault.code;

      /end-free
      *
     P OTSWebSvcs_SoapError_getCode...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Soap: Returns the last SOAP error (text) that occurred.
      * =====================================================================
     P OTSWebSvcs_SoapError_getText...
     P                 B                   export
      *
     D OTSWebSvcs_SoapError_getText...
     D                 PI                  like(wsdl_soap_faultstring_t)
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         return g_errors.soapFault.string;

      /end-free
      *
     P OTSWebSvcs_SoapError_getText...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   XML: Returns the last XML error (code) that occurred.
      * =====================================================================
     P OTSWebSvcs_XmlError_getCode...
     P                 B                   export
      *
     D OTSWebSvcs_XmlError_getCode...
     D                 PI                  like(wsdl_xml_ErrorNo_t    )
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         return g_errors.xmlError.code;

      /end-free
      *
     P OTSWebSvcs_XmlError_getCode...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   XML: Returns the last XML error (text) that occurred.
      * =====================================================================
     P OTSWebSvcs_XmlError_getText...
     P                 B                   export
      *
     D OTSWebSvcs_XmlError_getText...
     D                 PI                  like(wsdl_xml_ErrorText_t  )
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         return g_errors.xmlError.text;

      /end-free
      *
     P OTSWebSvcs_XmlError_getText...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Registers an user callback procedure, that is called whenever
      *   a web service requires user authentification.
      *   An application may call this procedure in order to register a
      *   user and password provider different from *_Port_supplyLoginData().
      *   Usually *_Port_supplyLoginData() should be modified to match the
      *   requirements of the application.
      * =====================================================================
     P OTSWebSvcs_Port_registerLoginCallback...
     P                 B                   export
      *
     D OTSWebSvcs_Port_registerLoginCallback...
     D                 PI
  D  D  i_pLoginProc                   *   value  procptr
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         g_getLoginDataImpl = i_pLoginProc;

         return;

      /end-free
      *
     P OTSWebSvcs_Port_registerLoginCallback...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Returns *ON if a login procedures has been registered.
      *   This procedure is used by WS_OPER() but might also be called
      *   by the application to see whether or not a user and password
      *   provider is present.
      * =====================================================================
     P OTSWebSvcs_Port_hasLoginCallback...
     P                 B                   export
      *
     D OTSWebSvcs_Port_hasLoginCallback...
     D                 PI              N
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (g_getLoginDataImpl <> *NULL);
            return *ON;
         endif;

         return *OFF;

      /end-free
      *
     P OTSWebSvcs_Port_hasLoginCallback...
     P                 E
      *
      * =====================================================================
      *   *** private, automatically called by WS_OPER() ***
      *   Login to proxy server or web service.
      * =====================================================================
     P OTSWebSvcs_Port_login...
     P                 B                   export
      *
     D OTSWebSvcs_Port_login...
     D                 PI            10I 0
     D  i_http_err                   10I 0 value
     D  i_numAttempts                10I 0 value
      *
      *  Return value
     D rc              S             10I 0 inz
      *
      *  Helper fields
     D basic           S               N   inz
     D digest          S               N   inz
     D realm           S            124A   inz
     D authTarget      S             14A   inz varying
     D authType        S              1A   inz
     D userid          S             50A   inz varying
     D password        S             50A   inz varying
      *
     D getLoginDataImpl...
     D                 PR            10I 0
     D                                     extproc(g_getLoginDataImpl)
     D  i_authType                   14A          const  varying
     D  i_realm                     126A          const  varying
     D  i_numAttempts                10I 0        const
     D  o_user                       50A                 varying
     D  o_password                   50A                 varying
      *
     D authErr         S             10I 0 inz
     D err             S             10I 0 inz
     D errText         S             80A   inz
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (i_http_err = HTTP_NDAUTH);
            http_getauth(basic: digest: realm);
            authTarget = WSDL_AUTH_TYPE_HTTP;
         else;
            http_proxy_getauth(basic: realm);
            authTarget = WSDL_AUTH_TYPE_PROXY;
         endif;

         rc = getLoginDataImpl(authTarget: realm
                               : i_numAttempts: userid: password);
         if (rc <> 1);
            userid = '';
            password = '';
            return rc;
         endif;

         if (i_http_err = HTTP_NDAUTH);
            select;
            when (digest);
               authType = HTTP_AUTH_MD5_DIGEST;
               authErr = http_setAuth(HTTP_AUTH_MD5_DIGEST
                                      : userid: password);
            when (basic);
               authType = HTTP_AUTH_BASIC;
               authErr = http_setAuth(HTTP_AUTH_BASIC
                                      : userid: password);
            other;
               // WSDL_AUTH_NTLM must match the value of HTTP_AUTH_NTLM!
               authType = WSDL_AUTH_NTLM;
               authErr = http_setAuth(WSDL_AUTH_NTLM
                                      : userid: password);
            endsl;
         else;
            select;
            when (digest);
               authType = HTTP_AUTH_MD5_DIGEST;
               authErr = http_proxy_setAuth(HTTP_AUTH_MD5_DIGEST
                                            : userid: password);
            when (basic);
               authType = HTTP_AUTH_BASIC;
               authErr = http_proxy_setAuth(HTTP_AUTH_BASIC
                                            : userid: password);
            other;
               // not yet supported
               http_DebugLog_appendText(
                  '** NTLM authentication is not supported +
                   for proxy authentication');
               authErr = -1;
            endsl;
         endif;

         if (authErr = -1);
            errText = http_error(err);
            http_DebugLog_appendText('** Failed to login: ' + errText);
            if (authtype = WSDL_AUTH_NTLM);
               http_DebugLog_appendText('** Your version of HTTPAPI +
                                         does not support NTLM authentication');
            endif;
            rc = WSDL_ERROR;
         endif;

         userid = '';
         password = '';

         return rc;

      /end-free
      *
     P OTSWebSvcs_Port_login...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Returns the name of the web service port.
      *   This procedure is used by WS_OPER() but might also be called
      *   by the application for information purposes.
      * =====================================================================
     P OTSWebSvcs_Port_getName...
     P                 B                   export
      *
     D OTSWebSvcs_Port_getName...
     D                 PI                         like(wsdl_portName_t )
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         return cWEB_SERVICE_PORT_NAME;

      /end-free
      *
     P OTSWebSvcs_Port_getName...
     P                 E
      *
      * =====================================================================
      *   *** private, automatically called by WS_OPER() ***
      *   Returns the UUID of the web service port.
      * =====================================================================
     P OTSWebSvcs_Port_getUuid...
     P                 B                   export
      *
     D OTSWebSvcs_Port_getUuid...
     D                 PI                         like(wsdl_uuid_t )
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         return cWEB_SERVICE_UUID;

      /end-free
      *
     P OTSWebSvcs_Port_getUuid...
     P                 E
      *
      * =====================================================================
      *   *** private, automatically called by WS_OPER() ***
      *   Adds an attachments to the list of attachments.
      * =====================================================================
     P OTSWebSvcs_Attachments_put...
     P                 B                   export
      *
     D OTSWebSvcs_Attachments_put...
     D                 PI
     D  i_attachmentID...
     D                                     const  like(wsdl_attachmentID_t )
     D  i_fileName                         const  like(wsdl_path_t         )
     D  i_uuid                             const  like(wsdl_uuid_t         )
     D                                            options(*nopass)
      *
     D p_uuid          C                   3
      *
     D uuid            S                   like(i_uuid          ) inz
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (%parms() >= p_uuid);
            uuid = i_uuid;
         else;
            uuid = OTSWebSvcs_Port_getUuid();
         endif;

         Attachments_put(Attachments_theInstance()
                         : uuid
                         : i_attachmentID
                         : i_fileName);

         return;

      /end-free
      *
     P OTSWebSvcs_Attachments_put...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Returns the file name of the attachment that is associated to
      *   a given content ID.
      *   An application can use this procedure to get an attachments
      *   of the last web service operation.
      * =====================================================================
     P OTSWebSvcs_Attachments_get...
     P                 B                   export
      *
     D OTSWebSvcs_Attachments_get...
     D                 PI                  like(wsdl_path_t     )
     D  i_attachmentID...
     D                                     const  like(wsdl_attachmentID_t )
     D  i_uuid                             const  like(wsdl_uuid_t         )
     D                                            options(*nopass)
      *
     D p_uuid          C                   2
      *
     D uuid            S                   like(i_uuid          ) inz
     D fileName        S                   like(wsdl_path_t     ) inz
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (%parms() >= p_uuid);
            uuid = i_uuid;
         else;
            uuid = OTSWebSvcs_Port_getUuid();
         endif;

         fileName = Attachments_get(Attachments_theInstance()
                                    : uuid
                                    : i_attachmentID);
         return fileName;

      /end-free
      *
     P OTSWebSvcs_Attachments_get...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Returns the file name of the attachment that is associated to
      *   a given index.
      *   An application can use this procedure to get an attachments
      *   of the last web service operation.
      * =====================================================================
     P OTSWebSvcs_Attachments_getAtPos...
     P                 B                   export
      *
     D OTSWebSvcs_Attachments_getAtPos...
     D                 PI                  likeds(wsdl_attachment_t )
     D  i_index                      10I 0 const
     D  i_uuid                             const  like(wsdl_uuid_t         )
     D                                            options(*nopass)
      *
     D p_uuid          C                   2
      *
     D uuid            S                   like(i_uuid          ) inz
     D attachment      DS                  likeds(wsdl_attachment_t ) inz
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (%parms() >= p_uuid);
            uuid = i_uuid;
         else;
            uuid = OTSWebSvcs_Port_getUuid();
         endif;

         attachment = Attachments_getAtPos(Attachments_theInstance()
                                           : uuid
                                           : i_index);
         return attachment;

      /end-free
      *
     P OTSWebSvcs_Attachments_getAtPos...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Returns the number of attachments that were downloaded with
      *   the last call of the web service.
      * =====================================================================
     P OTSWebSvcs_Attachments_getNumE...
     P                 B                   export
      *
     D OTSWebSvcs_Attachments_getNumE...
     D                 PI            10I 0
     D  i_uuid                             const  like(wsdl_uuid_t         )
     D                                            options(*nopass)
      *
     D p_uuid          C                   1
      *
     D uuid            S                   like(i_uuid          ) inz
     D numE            S             10I 0 inz
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (%parms() >= p_uuid);
            uuid = i_uuid;
         else;
            uuid = OTSWebSvcs_Port_getUuid();
         endif;

         numE = Attachments_getNumAttachments(
                      Attachments_theInstance(): uuid);

         return numE;

      /end-free
      *
     P OTSWebSvcs_Attachments_getNumE...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Removes all attachments from the list of attachments of
      *   this web service.
      *   An application should call this procedure once that the
      *   attachments of the last web service operation are obsolete.
      *   This procedure is also used by WS_OPER() to remove all attachments
      *   before the next web service call.
      * =====================================================================
     P OTSWebSvcs_Attachments_removeAll...
     P                 B                   export
      *
     D OTSWebSvcs_Attachments_removeAll...
     D                 PI
     D  i_uuid                             const  like(wsdl_uuid_t         )
     D                                            options(*nopass)
      *
     D p_uuid          C                   1
      *
     D uuid            S                   like(i_uuid          ) inz
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (%parms() >= p_uuid);
            uuid = i_uuid;
         else;
            uuid = OTSWebSvcs_Port_getUuid();
         endif;

         Attachments_removeAll(Attachments_theInstance(): uuid);

         return;

      /end-free
      *
     P OTSWebSvcs_Attachments_removeAll...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Specifies the name of the folder where to put attachments in.
      *   An application may use this procedure to specify a folder where
      *   to store attachements. The default value is '/tmp/attachments/'.
      * =====================================================================
     P OTSWebSvcs_Attachments_setFolder...
     P                 B                   export
      *
     D OTSWebSvcs_Attachments_setFolder...
     D                 PI
     D  i_folder                           const  like(wsdl_pathLong_t )
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         g_attachmentFolder = i_folder;

         g_attachmentFolder = %trimR(%xlate('\': '/': g_attachmentFolder));
         if (not f_endsWith('/': g_attachmentFolder));
            g_attachmentFolder = g_attachmentFolder + '/';
         endif;

         return;

      /end-free
      *
     P OTSWebSvcs_Attachments_setFolder...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Returns the name of the folder where attachments are stored.
      * =====================================================================
     P OTSWebSvcs_Attachments_getFolder...
     P                 B                   export
      *
     D OTSWebSvcs_Attachments_getFolder...
     D                 PI                         like(wsdl_pathLong_t )
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         return g_attachmentFolder;

      /end-free
      *
     P OTSWebSvcs_Attachments_getFolder...
     P                 E
      *
      * =====================================================================
      *   *** public ***
      *   Enables redirection of the HTTP response message to a
      *   stream file in the IFS.
      * =====================================================================
     P OTSWebSvcs_RedirectResponse_toStmf...
     P                 B                   export
      *
     D OTSWebSvcs_RedirectResponse_toStmf...
     D                 PI
     D  i_stmf                             const  like(wsdl_pathLong_t )
     D  i_replace                      N   const  options(*nopass: *omit)
     D  i_ccsid                      10I 0 const  options(*nopass: *omit)
     D  i_auth                       10I 0 const  options(*nopass: *omit)
      *
      *  Parameter positions
     D p_replace       C                   2
     D p_ccsid         C                   3
     D p_auth          C                   4
      *
      *  Optional parameter fields
     D replace         S                   like(i_replace ) inz
     D ccsid           S                   like(i_ccsid   ) inz
     D auth            S                   like(i_auth    ) inz
      *
      *  Helper fields
     D options         S             10I 0 inz
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         OTSWebSvcs_RedirectResponse_terminate();

         if (%trim(i_stmf) = '');
            g_redirectResponse.isActive = cFalse;
            g_redirectResponse.ccsid    = 0;
            g_redirectResponse.auth     = 0;
            g_redirectResponse.options  = 0;
            g_redirectResponse.fd       = -1;
            g_redirectResponse.path     = '';
            return;
         endif;

         http_DebugLog_appendText(
         '** Response redirected to: ' + i_stmf);

         if (%parms() >= p_replace and %addr(i_replace) <> *NULL);
            replace = i_replace;
         else;
            replace = cFalse;
         endif;

         if (%parms() >= p_ccsid and %addr(i_ccsid) <> *NULL);
            ccsid = i_ccsid;
         else;
            ccsid = 1208;   // UTF-8
         endif;

         if (%parms() >= p_auth and %addr(i_auth) <> *NULL);
            auth = i_auth;
         else;
            auth = S_IRWXU + S_IRWXG + S_IRWXO;
         endif;

         options = O_CREAT + O_SHARE_RDONLY + O_WRONLY + O_CCSID;
         if (replace);
            options = options + O_TRUNC;
         else;
            options = options + O_EXCL + O_APPEND;
         endif;

         g_redirectResponse.isActive = cTrue;
         g_redirectResponse.ccsid    = ccsid;
         g_redirectResponse.auth     = auth;
         g_redirectResponse.options  = options;
         g_redirectResponse.fd       = -1;
         g_redirectResponse.path     = i_stmf;

         return;

      /end-free
      *
     P OTSWebSvcs_RedirectResponse_toStmf...
     P                 E
      *
      * =====================================================================
      *   *** private, automatically called by WS_OPER() ***
      *   Returns cTrue if response redirection is active, otherwise cFalse.
      * =====================================================================
     P OTSWebSvcs_RedirectResponse_isActive...
     P                 B                   export
      *
     D OTSWebSvcs_RedirectResponse_isActive...
     D                 PI              N
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         return g_redirectResponse.isActive;

      /end-free
      *
     P OTSWebSvcs_RedirectResponse_isActive...
     P                 E
      *
      * =====================================================================
      *   *** private, automatically called by WS_OPER() ***
      *   Terminates a response redirection and closes the
      *   file that receiced the response.
      * =====================================================================
     P OTSWebSvcs_RedirectResponse_write...
     P                 B                   export
      *
     D OTSWebSvcs_RedirectResponse_write...
     D                 PI              N
     D  i_data                         *   value
     D  i_length                     10I 0 value
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         // Open output file
         if (g_redirectResponse.fd = -1);
            g_redirectResponse.fd = open(g_redirectResponse.path
                                        : g_redirectResponse.options
                                        : g_redirectResponse.auth
                                        : g_redirectResponse.ccsid);
            if (g_redirectResponse.fd = -1);
               http_DebugLog_appendText(
               '** '+ %char(%timestamp()) +': Failed to open: ' +
                                              g_redirectResponse.path);
               return cFalse;
            endif;
         endif;

         // Append data to output file
         if (write(g_redirectResponse.fd: i_data: i_length) <> i_length);
               http_DebugLog_appendText(
               '** '+ %char(%timestamp()) +': Failed to append ' +
                                              %char(i_length) + ' bytes to: ' +
                                              g_redirectResponse.path);
            return cFalse;
         endif;

         return cTrue;

      /end-free
      *
     P OTSWebSvcs_RedirectResponse_write...
     P                 E
      *
      * =====================================================================
      *   *** private, automatically called by WS_OPER() ***
      *   Terminates a response redirection and closes the
      *   file that receiced the response.
      * =====================================================================
     P OTSWebSvcs_RedirectResponse_terminate...
     P                 B                   export
      *
     D OTSWebSvcs_RedirectResponse_terminate...
     D                 PI
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (g_redirectResponse.fd <> -1);
            callp close(g_redirectResponse.fd);
            g_redirectResponse.fd = -1;
         endif;

         g_redirectResponse.path = '';
         g_redirectResponse.isActive = cFalse;

         return;

      /end-free
      *
     P OTSWebSvcs_RedirectResponse_terminate...
     P                 E
      *
      * =====================================================================
      *   Internal procedure to get the endpoint.
      * =====================================================================
     P getEndpoint...
     P                 B
      *
     D getEndpoint...
     D                 PI         32767A          varying
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         return g_url;

      /end-free
      *
     P getEndpoint...
     P                 E
      *
      * =====================================================================
      *   Internal procedure to set the endpoint.
      * =====================================================================
     P setEndpoint...
     P                 B
      *
     D setEndpoint...
     D                 PI
     D  i_url                     32767A   const varying  options(*varsize)
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         g_url = %subst(i_url: 1: %len(i_url));

      /end-free
      *
     P setEndpoint...
     P                 E
      *

      /IF NOT DEFINED(PROTOTYPE_PMR049A01)
      *======================================================================
      *  Generated by WSDL2RPG 1.15.2 / 17.10.2012
      *  Built on Oct 27, 2012 (13:43:22)
      *  Built for V6R1M0
      *  Based on WS_OPER v1.15.2
      *======================================================================
      *
      *   This source member is the RPG web service stub of the
      *   following Web Service operation:
      *
      *      Port      :  OTSWebSvcs
      *      Operation :  dequeue2()
      *
      *   Please search for 'INFO:' to get basic information how to call
      *   the web service.
      *
      *   Default attachment handling (for demonstration) was added to
      *   WS_OPER but is disabled by default.
      *
      *   In order to enable or disable default attachment handling you have
      *   to define or undefine the following compiler condition name:
      *      DEFAULT_ATTACHMENT_HANDLING
      /UNDEFINE DEFAULT_ATTACHMENT_HANDLING
      *
      *   By default attachments are stored in folder:
      *      '/tmp/attachments'
      *
      *   You can change the default attachment folder by calling the
      *   following procedure before calling the web service:
      *      OTSWebSvcs_Attachments_setFolder()
      *
      *   Default attachment handling was added to demonstrate how
      *   to manage attachments. Please search the generate stub
      *   module for 'TODO:' to see what code belongs to attachment
      *   support.
      *
      *======================================================================
      *   Pre-Compiler tags used by STRPREPRC to retrieve creation
      *   commands from the source member.
      * ---------------------------------------------------------------------
      * >>PRE-COMPILER<<
      *   >>CRTCMD<< CRTRPGMOD    MODULE(&LI/&OB) +
      *                           SRCFILE(&SL/&SF) +
      *                           SRCMBR(&SM);
      *   >>COMPILE<<
      *     >>PARM<< TRUNCNBR(*NO);
      *     >>PARM<< DBGVIEW(*LIST);
      *   >>END-COMPILE<<
      *   >>EXECUTE<<
      * >>END-PRE-COMPILER<<
      *======================================================================
     H NOMAIN
     H DEBUG
     H OPTION(*SRCSTMT : *NODEBUGIO)
     H EXTBININT(*YES)
      *
      *  Do not change or remove this compiler condition!
      /DEFINE NO_CONST_ON_INPUT_PARAMETERS
      /ENDIF
      /IF NOT DEFINED(PROTOTYPE_DEFINED_PMR049A01)
      /DEFINE PROTOTYPE_DEFINED_PMR049A01
      *
      * INFO:
      * This is the procedure you call to consume the Web Service:
      * ----------------------------------------------------------
      * Operation: dequeue2
      * Returns  : dequeue2Response
      *
      * INFO:
      * Define your own fields using the type templates used in the prototype
      * below. Use LIKE(*_t) or LIKEDS(*_t) to define these fields.
      * All type templates of this web service are defined in web service
      * module:   PMR049A
      *
     D OTSWebSvcs_dequeue2...
     D                 PR                  likeds(impl_dequeue2Response_t)
     D                                     extproc('OTSWebSvcs_dequeue2')
     D  i_impl_dequeue2...
     D                                     likeds(impl_dequeue2_t)
      /IF NOT DEFINED(NO_CONST_ON_INPUT_PARAMETERS)
     D                                     const
      /ENDIF
     D  o_msg                              like(wsdl_errText_t )
      *
      /COPY QWSDL2RPG,TYPES_H
      *
      /DEFINE PROTOTYPE_PMR049A
      /COPY QWSDL2RPG,PMR049A                      Web Service: Web Service Proc
      /UNDEFINE PROTOTYPE_PMR049A
      *
      /ENDIF
      /IF DEFINED(PROTOTYPE_PMR049A01)
      /EOF
      /ENDIF
      * ---------------------------------------------------------------------
      *
      /COPY QBASICS1,PBASICS1                      Tools/400 Runtime Library
      /COPY QMIME,PMIME                            Tools/400 MIME Parser
      /COPY QMIME,HTTPMIME_H                       Tools/400 MIME Parser to HTTP API adapter
      /COPY QRPGLESRC,HTTPAPI_H                    HTTP-API Service Program
      /COPY QWSDL2RPG,PWSDL2R70                    WSDL2RPG: HTTP API Header Extensions
      /COPY QWSDL2RPG,PWSDL2R71                    WSDL2RPG: HTTP Debug Log
      /COPY QWSDL2RPG,PWSDL2R79                    WSDL2RPG: Static Array
      /COPY QWSDL2RPG,PWSDL2R86                    WSDL2RPG: Stream
      /COPY QWSDL2RPG,PWSDL2R87                    WSDL2RPG: ManagedMemoryDataSource
      /COPY QWSDL2RPG,PWSDL2R88                    WSDL2RPG: Public Helper Procedures
      /COPY QWSDL2RPG,PWSDL2R90                    WSDL2RPG: AppMsg
      /COPY QWSDL2RPG,PWSDL2R94                    WSDL2RPG: MultiRef
      /COPY QWSDL2RPG,PWSDL2R97                    WSDL2RPG: eXpat Adapter
      /COPY QWSDL2RPG,PWSDL2R98                    WSDL2RPG: UnMarshaller/Marshaller
      /COPY QWSDL2RPG,PWSDL2R42                    WSDL2RPG: User name and password
      *
      * ------------------------------------
      *  Internal prototypes
      * ------------------------------------
      *
      *   Reopens a given input stream in order to send it over
      *   the wire again.
     D reOpenInputStream...
     D                 PR                         like(wsdl_hStream_t    )
     D                                     extproc('+
     D                                     reOpenInputStream+
     D                                     ')
     D  i_hDataSource                      const  like(wsdl_hDataSource_t)
     D  i_hInpStream                       value  like(wsdl_hStream_t    )
      *
      *   Login in to proxy server or http server.
     D login...
     D                 PR            10I 0
     D                                     extproc('+
     D                                     login+
     D                                     ')
     D  i_http_err                   10I 0 value
     D  i_numAttempts                10I 0 value
      *
      *   Sets the content type and the SOAP action of the POST message.
     D HTTP_setContentTypeAndSOAPAction...
     D                 PR
     D                                     extproc('+
     D                                     HTTP_setContentTypeAndSOAPAction+
     D                                     ')
     D  o_addlHdrs                 1024A          varying
     D  i_pUserData                    *   value
      *
     D impl_dequeue2ResponseStart...
     D                 PR
     D                                     extproc('impl_dequeue2ResponseStart')
     D  userdata                       *   value
     D  depth                        10I 0 value
     D  namespace                  1024A   varying const
     D  name                       1024A   varying const
     D  path                      24576A   varying const
     D  attrs                          *   dim(32767)
     D                                     const options(*varsize)
     D impl_dequeue2ResponseEnd...
     D                 PR
     D                                     extproc('impl_dequeue2ResponseEnd')
     D  userdata                       *   value
     D  depth                        10I 0 value
     D  namespace                  1024A   varying const
     D  name                       1024A   varying const
     D  path                      24576A   varying const
     D  value                     65535A   varying
     D  attrs                          *   dim(32767)
     D                                     const options(*varsize)
     D tns2_TransactionBlock2Start...
     D                 PR
     D                                     extproc('tns2_TransactionBlock2Start+
     D                                     ')
     D  userdata                       *   value
     D  depth                        10I 0 value
     D  namespace                  1024A   varying const
     D  name                       1024A   varying const
     D  path                      24576A   varying const
     D  attrs                          *   dim(32767)
     D                                     const options(*varsize)
     D tns2_TransactionBlock2End...
     D                 PR
     D                                     extproc('tns2_TransactionBlock2End')
     D  userdata                       *   value
     D  depth                        10I 0 value
     D  namespace                  1024A   varying const
     D  name                       1024A   varying const
     D  path                      24576A   varying const
     D  value                     65535A   varying
     D  attrs                          *   dim(32767)
     D                                     const options(*varsize)
      *
      *   Receive response of HTTP post operation.
     D HTTP_receiveResponse...
     D                 PR            10I 0 extproc('+
     D                                     HTTP_receiveResponse+
     D                                     ')
     D  i_hStream                    10I 0 value
     D  i_data                         *   value
     D  i_length                     10I 0 value
      *
      *   Parses or redirects the web service response.
     D parseOrRedirectResponse...
     D                 PR              N   extproc('+
     D                                     parseOrRedirectResponse+
     D                                     ')
     D  i_data                         *   value
     D  i_length                     10I 0 value
      *
      *   SOAP message: Envelope
     D SOAPMessage_Envelope...
     D                 PR                  extproc('+
     D                                     SOAPMessage_Envelope+
     D                                     ')
     D   userdata                      *   value
     D   depth                       10I 0 value
     D   namespace                 1024A   varying const
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
      *
      *   SOAP message: fault information
     D SOAPMessage_FaultStart...
     D                 PR                  extproc('+
     D                                     SOAPMessage_FaultStart+
     D                                     ')
     D   userdata                      *   value
     D   depth                       10I 0 value
     D   namespace                 1024A   varying const
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
      *
      *   SOAP message: fault information
     D SOAPMessage_FaultEnd...
     D                 PR                  extproc('+
     D                                     SOAPMessage_FaultEnd+
     D                                     ')
     D   userdata                      *   value
     D   depth                       10I 0 value
     D   namespace                 1024A   varying const
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   value                    65535A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
      *
      *   SOAP message: fault details
     D SOAPMessage_FaultDetailStart...
     D                 PR                  extproc('+
     D                                     SOAPMessage_FaultDetailStart+
     D                                     ')
     D   userdata                      *   value
     D   depth                       10I 0 value
     D   namespace                 1024A   varying const
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
      *
      *   SOAP message: fault details
     D SOAPMessage_FaultDetailEnd...
     D                 PR                  extproc('+
     D                                     SOAPMessage_FaultDetailEnd+
     D                                     ')
     D   userdata                      *   value
     D   depth                       10I 0 value
     D   namespace                 1024A   varying const
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   value                    65535A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
      *
      *   SOAP message: NULL callback procedure
     D SOAPMessage_unexpectedElementStart...
     D                 PR
     D                                     extproc('+
     D                                     SOAPMessage_unexpectedElementStart+
     D                                     ')
     D   userdata                      *   value
     D   depth                       10I 0 value
     D   namespace                 1024A   varying const
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
      *
      *   SOAP message: NULL callback procedure
     D SOAPMessage_unexpectedElementEnd...
     D                 PR
     D                                     extproc('+
     D                                     SOAPMessage_unexpectedElementEnd+
     D                                     ')
     D   userdata                      *   value
     D   depth                       10I 0 value
     D   namespace                 1024A   varying const
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   value                    65535A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
      *
     D ignoreUnexpectedSoapHeader...
     D                 PR              N
     D                                     extproc('+
     D                                     ignoreUnexpectedSoapHeader+
     D                                     ')
      *
     D getOperationUuid...
     D                 PR                          like(wsdl_uuid_t )
     D                                     extproc('+
     D                                     getOperationUuid+
     D                                     ')
      *
     D getPortName...
     D                 PR                          like(wsdl_portName_t )
     D                                     extproc('+
     D                                     getPortName+
     D                                     ')
      *
     D getOperationName...
     D                 PR                          like(wsdl_operName_t )
     D                                     extproc('+
     D                                     getOperationName+
     D                                     ')
      *
     D getPostCcsid...
     D                 PR            10I 0
     D                                     extproc('+
     D                                     getPostCcsid+
     D                                     ')
      *
     D getTimeout...
     D                 PR            10I 0
     D                                     extproc('+
     D                                     getTimeout+
     D                                     ')
      *
     D getUserAgent...
     D                 PR                         like(wsdl_userAgent_t )
     D                                     extproc('+
     D                                     getUserAgent+
     D                                     ')
      *
     D mustRedirectStmf...
     D                 PR              N
     D                                     extproc('+
     D                                     mustRedirectStmf+
     D                                     ')
      *
      * ------------------------------------
      *  Global fields & constants
      * ------------------------------------
      *
      *   UUID of the web service operation as generated by WSDL2RPG
      *   (Using UUID of web service port for all operations by default)
      *cOPERATION_UUID...
      *                C                   '74799801096319709C320004AC1144E3'
      *
      *   SOAP response header
      *
      *   Reference to the 'respSoapHeader' field.
     D g_pRespSoapHeader...
     D                 S               *   inz
      *
      *   XMLSAXParser handle
     D g_hSAXParser    S                   like(xmlSaxParser_handle_t) inz
      *
      *   MIME parser
     D g_hMIMEParser   S                   like(mime_hMime_t ) inz
      *
      *   MIME message indicator
     D g_isMimeMessage...
     D                 S               N   inz(cFalse)
      *
      *   Content ID of the SOAP message part
     D g_SOAPMessageID...
     D                 S            512A   varying inz
      *
      *   Indicator "parse SOAP message"
     D g_doParseSOAPMessage...
     D                 S               N   inz(cFalse)
      *
      *   Indicator "SOAP message parsed"
     D g_SOAPMessage_done...
     D                 S               N   inz(cFalse)
      *
      *   Body part counter
     D g_BodyPart_counter...
     D                 S             10I 0 inz
      *
      *   HTTP response "initialized" indicator
     D g_HTTP_isInit...
     D                 S               N   inz(cFalse)
      *
      *   Error information of web service operation
     D g_errors        DS                  likeds(wsdl_errors_t    ) inz
      *
      *   Switch for AXIS bug AXIS-2095
     D g_isAXIS_2095   S               N   inz(cFalse)
      *
      * -------------------------------------------
      *  TODO: Added to implement default
      *        attachment handling.
      * -------------------------------------------
      /IF DEFINED(DEFAULT_ATTACHMENT_HANDLING)
      /COPY QWSDL2RPG,CLIB                         C Runtime Library
      *
      *  User data scoped to the current part
     D partUserData_t...
     D                 DS                  qualified               based(pDummy)
     D  FD                           10i 0
      *
      /ENDIF
      * =====================================================================
      * Operation: dequeue2
      * Returns  : dequeue2Response
      * =====================================================================
     P OTSWebSvcs_dequeue2...
     P                 B                   export
     D OTSWebSvcs_dequeue2...
     D                 PI                  likeds(impl_dequeue2Response_t)
     D  i_impl_dequeue2...
     D                                     likeds(impl_dequeue2_t)
     D  o_msg                       128A   varying
      *
      *  Return value
     D rtnValue        DS                  likeds(impl_dequeue2Response_t)
     D                                     inz
      *
      *  Local fields
     D isUnexpectedError...
     D                 S               N   inz(cFalse)
     D isRedirect      S               N   inz(cFalse)
     D request         S          65535A   varying inz
     D url             S          32767A   varying
     D rc              S             10I 0 inz
     D rcvm0200        DS                  likeds(rcvm0200_t ) inz
     D msg             DS                  likeds(msg_t      ) inz
     D headers         DS                  likeds(headers_t  ) inz
      *
     D hDataSource     S                   like(wsdl_hDataSource_t   ) inz
     D hOutStream      S                   like(wsdl_hStream_t       ) inz
     D hSAXParser      S                   like(xmlSaxParser_handle_t) inz
     D hMIMEParser     S                   like(mime_hMime_t         ) inz
     D hInpStream      S                   like(wsdl_hStream_t       ) inz
     D contentType     S                   like(wsdl_contentType_t   ) inz
      *
      *   Proxy server to use
     D httpProxy       DS                  likeds(wsdl_proxy_t     ) inz
      *
      *  Login helper fields
     D err             S             10I 0 inz
     D lastErr         S             10I 0 inz(-1)
     D numAttempts     S             10I 0 inz
      *
      *  Dynamic array index fields
      *
      *  Dynamic array item fields
      *
      *  User data
     D userData        DS                  likeds(impl_dequeue2Response_t)
     D                                     inz
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         o_msg = '';

         monitor;

            // Initialize web service stub
            OTSWebSvcs_Port_initialize(
                  getOperationName());

            // Enable/disable HTTP debug log
            // Starting with v1.15 the debug log is started in
            // procedure http_DebugLog_open() which is called by
            // WebServiceStub_Port_setHttpDebug().

            http_DebugLog_appendText(
            '** ' + %char(%timestamp()) + ': Entering ' + f_this() + '()');

            // Initialize map to manage <multiRef> elements
            MultiRef_new();

            // Remove all attachments of this service from the list of attachments
            OTSWebSvcs_Attachments_removeAll(
                  getOperationUuid());

            // Set proxy server to use
            httpProxy = OTSWebSvcs_Port_getHttpProxy();
            http_setproxy(httpProxy.server: httpProxy.port);

            // Set CCSID for POST data according
            // to the encoding of the SOAP envelope
            HTTP_SetCCSIDs(getPostCcsid(): HTTP_EBCDIC);

            // Create and open data source to store the request message
            hDataSource = ManagedMemoryDataSource_new(1024*1024*4); // 4 MB cache

            contentType = 'text/xml';

            // Produce SOAP request message
            http_DebugLog_appendTextVerbose(
            '** ' + %char(%timestamp()) + ': Producing request messsage');

            hOutStream = ManagedMemoryDataSource_OutputStream_open(
                               hDataSource: contentType: getPostCcsid());

            request =
               '<?xml version="1.0" encoding="UTF-8"?>'                     +
               '<soapenv:Envelope'                                          +
               ' xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/";' +
            ' xmlns:impl="http://websvcs.otswebws";' +
               '>'                                                          +
               '<soapenv:Body>'                                             +
            '';

         if (%len(request) > 0);
            // Add previous bytes of request message to output stream
            ManagedMemoryDataSource_OutputStream_write(hOutStream: %addr(requ...
            est: *DATA): %len(request));
            clear request;
         endif;

         request = request +
         '<impl:dequeue2>' +
         '<subscriberId>' +
         Marshaller_toInt(
            i_impl_dequeue2.subscriberId
            ) +
         '</subscriberId>' +
         '<transactionIdIn>' +
         Marshaller_toLong(
            i_impl_dequeue2.transactionIdIn
            ) +
         '</transactionIdIn>' +
         '</impl:dequeue2>' +
               '</soapenv:Body>'                                            +
               '</soapenv:Envelope>';

            // Add remaining bytes of request message to output stream
            if (%len(request) > 0);
               ManagedMemoryDataSource_OutputStream_write(
                     hOutStream: %addr(request) + 2: %len(request));
            endif;

            // Close output stream and finish the request message
            ManagedMemoryDataSource_OutputStream_close(hOutStream);

            http_DebugLog_appendTextVerbose(
            '** ' + %char(%timestamp()) + ': Finished request message');

            http_DebugLog_appendTextVerbose(
            '** ' + %char(%timestamp()) + ': Preparing to send message');

            // Open input stream
            hInpStream = ManagedMemoryDataSource_InputStream_open(hDataSource);

            // Clear error code
            OTSWebSvcs_Port_clearErrors(
                  g_errors);

            // HTTPAPI: Enables additional headers
            http_xproc(HTTP_POINT_ADDL_HEADER
                       : %paddr('HTTP_setContentTypeAndSOAPAction')
                       : %addr(headers));

            headers.contentType =
                  ManagedMemoryDataSource_getContentType(hDataSource);
            headers.soapAction  = '';

            // ---------------------------------------
            //   Post request and parse response
            // ---------------------------------------

            // Create parser (callbacks style: HTTP API)
            if (not mustRedirectStmf());
               XMLSAXParser_new(hSAXParser: cTrue);
               XMLSAXParser_setDoNamespaces(hSAXParser: cTrue);
               XMLSAXParser_registerCallback(hSAXParser
                  : cXML_CB_SAX_STARTELEMENT
                  : %paddr('SOAPMessage_Envelope'));
               XMLSAXParser_prepareParse(hSAXParser: %addr(userData));
            endif;

            // Create MIME parser in case we need it
            hMIMEParser = MIMEParser_new();
            MIMEParser_setDecodeData(hMIMEParser: cTrue);
            http_mime_DataSink_initialize(hMIMEParser
                                          : *NULL
                                          : %paddr('HTTPDataSink_startPart')
                                          : %paddr('HTTPDataSink_bodyData')
                                          : %paddr('HTTPDataSink_endPart'));

            // Make parser available for HTTP_receiveResponse()
            g_hSAXParser    = hSAXParser;
            g_hMIMEParser   = hMIMEParser;
            g_isMimeMessage = cFalse;
            g_HTTP_isInit   = cFalse;
            g_SOAPMessageID = '';
            g_doParseSOAPMessage = cFalse;
            g_SOAPMessage_done   = cFalse;
            g_BodyPart_counter   = 0;

            // Make SOAP response header available to SOAPMessage_Envelope
            g_pRespSoapHeader = *NULL;

            // eXpat: Post request and parse response
            url = OTSWebSvcs_Endpoint_get();
            dou (err <> HTTP_NDAUTH and err <> HTTP_PXNDAUTH);
               // Get document from server and handle http redirects
               //   301 Moved Permanently
               //   302 Found
               //   303 See Other
               //   307 Temporary Redirect
               dou (not isRedirect);
                  http_DebugLog_appendText(
                  '** ' + %char(%timestamp()) + ': Sending request to server');
                  rc = http_url_post_raw2(
                     url
                     : hInpStream
                     : %paddr(
                          'WSDL2R87_ManagedMemoryDataSource_InputStream_read')
                     : ManagedMemoryDataSource_getSize(hDataSource)
                     : 0
                     : %paddr('HTTP_receiveResponse')
                     : getTimeout()
                     : getUserAgent()
                     : '');
                  if (rc = 301 or rc = 302 or rc = 303 or rc = 307);
                     url = http_redir_loc();
                     // Reopen data stream
                     hInpStream = reOpenInputStream(hDataSource: hInpStream);
                     isRedirect = cTrue;
                  else;
                     isRedirect = cFalse;
                  endif;
               enddo;

               // The first time we request a document that requires user/password
               // it will return a HTTP_NDAUTH error.
               if (rc <> 1);
                  http_error(err);
                  if (err = HTTP_NDAUTH or err = HTTP_PXNDAUTH);
                     if (not OTSWebSvcs_Port_hasLoginCallback());
                        leave;
                     endif;

                     if (err <> lastErr);
                        lastErr = err;
                        numAttempts = 0;
                     endif;
                     numAttempts = numAttempts + 1;

                     if (login(err: numAttempts) <> 1);
                        leave;
                     endif;

                     // Reopen data stream
                     hInpStream = reOpenInputStream(hDataSource: hInpStream);
                  endif;
               else;
                  MultiRef_finalize();
                  err = 0;
               endif;
            enddo;

            // Preserve parser error code and message text
            if (err = HTTP_RDWERR);
               g_errors.xmlError.code = XMLToolkit_getError(
                                              hSAXParser
                                              : g_errors.xmlError.text
                                              : g_errors.xmlError.line
                                              : g_errors.xmlError.column);
            endif;

            if (not mustRedirectStmf());
               XMLSAXParser_endParse(hSAXParser);
            endif;

            if (g_isMimeMessage);
               MIMEParser_endParse(hMIMEParser);
               g_isMimeMessage = cFalse;
            endif;

            g_HTTP_isInit = cFalse;

         on-error;
            isUnexpectedError = cTrue;
            rcvm0200 = f_rcvPgmMsg(cMsg_Any: *: cMsg_Act_Same: 0
                                   : cMsg_Same: cMsg_ToMyself);
            http_DebugLog_appendRcvMsg(rcvm0200);
            msg = f_cvtRcvMsgToMsg(rcvm0200);
            g_errors.errType        = WSDL_HTTP_ERROR_UNEXPECTED;
            g_errors.httpError.no   = WSDL_HTTP_ERROR_UNEXPECTED;
            g_errors.httpError.text = f_rtvMsgText(msg);
            rc    = g_errors.httpError.no;
            o_msg = g_errors.httpError.text;
         endmon;

         g_hSAXParser  = *NULL;
         g_hMIMEParser = *NULL;

         if (not isUnexpectedError);
            if (err <> 0);
               g_errors.errType = WSDL_HTTP_ERROR;

               // Set http error code and message text
               g_errors.httpError.no   = err;
               g_errors.httpError.text = http_error();

               // Return error message text to caller
               if (g_errors.httpError.text <> '');
                  o_msg = g_errors.httpError.text;
               else;
                  o_msg = OTSWebSvcs_SoapError_getText();
               endif;
               clear rtnValue;
            else;
               o_msg = '';
               rtnValue = userData;
            endif;
         endif;

         if (OTSWebSvcs_RedirectResponse_isActive());
            OTSWebSvcs_RedirectResponse_terminate();
         endif;

         if (not XMLSAXParser_isNull(hSAXParser));
            XMLSAXParser_delete(hSAXParser);
         endif;

         if (not MIMEParser_isNull(hMIMEParser));
            MIMEParser_delete(hMIMEParser);
         endif;

         if (not ManagedMemoryDataSource_isNull(hDataSource));
            if (ManagedMemoryDataSource_Stream_isOpen(hInpStream));
               ManagedMemoryDataSource_InputStream_close(hInpStream);
            endif;
            if (ManagedMemoryDataSource_Stream_isOpen(hOutStream));
               ManagedMemoryDataSource_OutputStream_close(hOutStream);
            endif;
            ManagedMemoryDataSource_delete(hDataSource);
         endif;

         if (not MultiRef_isNull());
            MultiRef_delete();
         endif;

         // Set error information of last service call
         OTSWebSvcs_Port_setErrors(
               g_errors);

         http_DebugLog_appendText(
         '** ' + %char(%timestamp()) + ': Leaving ' + f_this() + '()');

         if (http_DebugLog_isOpen());
            http_DebugLog_close();
         endif;

         return rtnValue;

      /end-free
      *
     P OTSWebSvcs_dequeue2...
     P                 E
      *
      *
      * ==================================================================
      * Return value: impl:dequeue2Response
      * ==================================================================
     P impl_dequeue2ResponseStart...
     P                 B
     D impl_dequeue2ResponseStart...
     D                 PI
     D  userdata                       *   value
     D  depth                        10I 0 value
     D  namespace                  1024A   varying const
     D  name                       1024A   varying const
     D  path                      24576A   varying const
     D  attrs                          *   dim(32767)
     D                                     const options(*varsize)
      *
     D currentItem     DS                  likeds(impl_dequeue2Response_t)
     D                                     based(pCurrentItem)
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         // Get access to current item
         pCurrentItem = userdata;

         select;
         when (depth = 1);
            if (MultiRef_isReference(attrs));
               MultiRef_put(
                  attrs
                  : XMLSAXParser_getUserData()
                  : depth
                  : namespace
                  : name
                  : path
                  : XMLSAXParser_getStartCallback()
                  : XMLSAXParser_getEndCallback()
                  : *omit
                  : %addr(currentItem)
                  : %size(currentItem)
                  );
            endif;
            return;

         when (depth = 2
                and
                name = 'dequeue2Return');
            p_assert(namespace = ''
               : 'Namespace should be empty');
            XMLSAXParser_delegateElementProcessing(
               %addr(currentItem.dequeue2Return)
               : %paddr('tns2_TransactionBlock2Start')
               : %paddr('tns2_TransactionBlock2End')
               );
            return;

         endsl;

         return;

      /end-free
      *
     P impl_dequeue2ResponseStart...
     P                 E
      *
      * ==================================================================
      * Return value: impl:dequeue2Response
      * ==================================================================
     P impl_dequeue2ResponseEnd...
     P                 B
     D impl_dequeue2ResponseEnd...
     D                 PI
     D  userdata                       *   value
     D  depth                        10I 0 value
     D  namespace                  1024A   varying const
     D  name                       1024A   varying const
     D  path                      24576A   varying const
     D  value                     65535A   varying
     D  attrs                          *   dim(32767)
     D                                     const options(*varsize)
      *
     D currentItem     DS                  likeds(impl_dequeue2Response_t)
     D                                     based(pCurrentItem)
      *
     D itemValue       DS                  likeds(wsdl_fullElementData_t)
     D                                     inz
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         // Get access to current item
         pCurrentItem = userdata;

         // Get full element data
         itemValue = XMLSAXParser_getFullElementData();

         select;
         endsl;

         return;

      /end-free
      *
     P impl_dequeue2ResponseEnd...
     P                 E
      *
      * ==================================================================
      * Return value: impl:dequeue2Return
      * ==================================================================
     P tns2_TransactionBlock2Start...
     P                 B
     D tns2_TransactionBlock2Start...
     D                 PI
     D  userdata                       *   value
     D  depth                        10I 0 value
     D  namespace                  1024A   varying const
     D  name                       1024A   varying const
     D  path                      24576A   varying const
     D  attrs                          *   dim(32767)
     D                                     const options(*varsize)
      *
     D currentItem     DS                  likeds(tns2_TransactionBlock2_t)
     D                                     based(pCurrentItem)
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         // Get access to current item
         pCurrentItem = userdata;

         select;
         when (depth = 1);
            p_assert(namespace = ''
               : 'Namespace should be empty');
            if (MultiRef_isReference(attrs));
               MultiRef_put(
                  attrs
                  : XMLSAXParser_getUserData()
                  : depth
                  : namespace
                  : name
                  : path
                  : XMLSAXParser_getStartCallback()
                  : XMLSAXParser_getEndCallback()
                  : *omit
                  : %addr(currentItem)
                  : %size(currentItem)
                  );
            endif;
            return;

         when (depth = 2
                and
                name = 'count');
            p_assert(namespace = ''
               : 'Namespace should be empty');
            // Value is retrieved in corresponding END procedure
            if (MultiRef_isReference(attrs));
               MultiRef_put(
                  attrs
                  : XMLSAXParser_getUserData()
                  : depth
                  : namespace
                  : name
                  : path
                  : XMLSAXParser_getStartCallback()
                  : XMLSAXParser_getEndCallback()
                  : *omit
                  : %addr(currentItem.count)
                  : %size(currentItem.count)
                  );
            endif;
            return;

         when (depth = 2
                and
                name = 'transactions');
            p_assert(namespace = ''
               : 'Namespace should be empty');
            // Value is retrieved in corresponding END procedure
            if (MultiRef_isReference(attrs));
               MultiRef_put(
                  attrs
                  : XMLSAXParser_getUserData()
                  : depth
                  : namespace
                  : name
                  : path
                  : XMLSAXParser_getStartCallback()
                  : XMLSAXParser_getEndCallback()
                  : *omit
                  : %addr(currentItem.transactions)
                  : %size(currentItem.transactions)
                  );
            endif;
            return;

         when (depth = 2
                and
                name = 'transactionIdOut');
            p_assert(namespace = ''
               : 'Namespace should be empty');
            // Value is retrieved in corresponding END procedure
            if (MultiRef_isReference(attrs));
               MultiRef_put(
                  attrs
                  : XMLSAXParser_getUserData()
                  : depth
                  : namespace
                  : name
                  : path
                  : XMLSAXParser_getStartCallback()
                  : XMLSAXParser_getEndCallback()
                  : *omit
                  : %addr(currentItem.transactionIdOut)
                  : %size(currentItem.transactionIdOut)
                  );
            endif;
            return;

         endsl;

         return;

      /end-free
      *
     P tns2_TransactionBlock2Start...
     P                 E
      *
      * ==================================================================
      * Return value: impl:dequeue2Return
      * ==================================================================
     P tns2_TransactionBlock2End...
     P                 B
     D tns2_TransactionBlock2End...
     D                 PI
     D  userdata                       *   value
     D  depth                        10I 0 value
     D  namespace                  1024A   varying const
     D  name                       1024A   varying const
     D  path                      24576A   varying const
     D  value                     65535A   varying
     D  attrs                          *   dim(32767)
     D                                     const options(*varsize)
      *
     D currentItem     DS                  likeds(tns2_TransactionBlock2_t)
     D                                     based(pCurrentItem)
      *
     D itemValue       DS                  likeds(wsdl_fullElementData_t)
     D                                     inz
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         // Get access to current item
         pCurrentItem = userdata;

         // Get full element data
         itemValue = XMLSAXParser_getFullElementData();

         select;
         when (depth = 2
                and
                name = 'count');
            p_assert(namespace = ''
               : 'Namespace should be empty');
            if (not Value_isNil(attrs));
               UnMarshaller_setFieldIdentifier(name: path);
               currentItem.count =
                  UnMarshaller_toInt(value);
            endif;

         when (depth = 2
                and
                name = 'transactions');
            p_assert(namespace = ''
               : 'Namespace should be empty');
            if (not Value_isNil(attrs));
               UnMarshaller_setFieldIdentifier(name: path);
               currentItem.transactions =
                  UnMarshaller_toBase64Binary(value); // = BASE64TYPE(*BINARY)              //RADDAT
                  // : getPostCcsid());                  = BASE64TYPE(*CHAR)                //RADDAT
            endif;

         when (depth = 2
                and
                name = 'transactionIdOut');
            p_assert(namespace = ''
               : 'Namespace should be empty');
            if (not Value_isNil(attrs));
               UnMarshaller_setFieldIdentifier(name: path);
               currentItem.transactionIdOut =
                  UnMarshaller_toLong(value);
            endif;

         endsl;

         return;

      /end-free
      *
     P tns2_TransactionBlock2End...
     P                 E
      *
      * =====================================================================
      *   Reopens a given input stream in order to send it over
      *   the wire again.
      * =====================================================================
     P reOpenInputStream...
     P                 B
      *
     D reOpenInputStream...
     D                 PI                         like(wsdl_hStream_t    )
     D  i_hDataSource                      const  like(wsdl_hDataSource_t)
     D  i_hInpStream                       value  like(wsdl_hStream_t    )
      *
      *  Return value
     D hInpStream      S                   like(wsdl_hStream_t       ) inz
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         ManagedMemoryDataSource_InputStream_close(i_hInpStream);
         hInpStream =
               ManagedMemoryDataSource_InputStream_open(i_hDataSource);

         return hInpStream;

      /end-free
      *
     P reOpenInputStream...
     P                 E
      *
      * =====================================================================
      *   Login in to proxy server or http server.
      * =====================================================================
     P login...
     P                 B
      *
     D login...
     D                 PI            10I 0
     D  i_http_err                   10I 0 value
     D  i_numAttempts                10I 0 value
      *
      *  Return value
     D rc              S             10I 0 inz
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         http_DebugLog_appendText(
         '** ' + %char(%timestamp()) + ': Requesting user name and password');

         rc = OTSWebSvcs_Port_login(
                    i_http_err: i_numAttempts);

         return rc;

      /end-free
      *
     P login...
     P                 E
      *
      * =====================================================================
      *   Sets the content type and the SOAP action of the POST message.
      * =====================================================================
     P HTTP_setContentTypeAndSOAPAction...
     P                 B
      *
     D HTTP_setContentTypeAndSOAPAction...
     D                 PI
     D  o_addlHdrs                 1024A          varying
     D  i_pUserData                    *   value
      *
      *  User Data
     D headers         DS                  likeds(headers_t) based(i_pUserData)
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         o_addlHdrs = cHTTP_HEADER_CONTENT_TYPE + ': ' +
                      headers.contentType + cEBCDIC_CRLF +
                      cHTTP_HEADER_SOAP_ACTION + ': ' +
                      headers.soapAction + cEBCDIC_CRLF;

      /end-free
      *
     P HTTP_setContentTypeAndSOAPAction...
     P                 E
      *
      * =====================================================================
      *   Receive response of HTTP post operation.
      * =====================================================================
     P HTTP_receiveResponse...
     P                 B
      *
     D HTTP_receiveResponse...
     D                 PI            10I 0
     D  i_hStream                    10I 0 value
     D  i_data                         *   value
     D  i_length                     10I 0 value
      *
     D rc              S             10I 0 inz(-1)
     D contentType     S           1024A   inz
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         http_DebugLog_appendTextVerbose(
         '** ' + %char(%timestamp()) + ': Entering ' + f_this() + '()');

         if (not g_HTTP_isInit);
            http_DebugLog_appendText(
            '** '+%char(%timestamp())+': Preparing to parse received message');
            select;
            when (http_getContentType() = 'text');
               if (http_getContentSubType() = 'html');
                  if (f_exist('WSDL2RPG': '*LIBL': '*MSGF'));
                     clear USR0030;
                     USR00301 = getPortName();
                     AppMsg_sendCancelMsg(AppMsg_newError('USR0030': USR0030));
                  else;
                     AppMsg_sendCancelMsg(
                        f_newMsg('CPF9898'
                              : 'Unexpected HTML data received from web service'
                              : '*ESCAPE'
                              : 'QCPFMSG'));
                  endif;
               endif;
            when (http_getContentType() = 'multipart');
               contentType = %trim(http_header('content-type'));
               MIMEParser_beginParse(g_hMIMEParser);
               MIMEParser_setContentType(g_hMIMEParser: contentType);
               g_SOAPMessageID = http_getContentTypeAttr('start': cTrue);
               g_isMimeMessage = cTrue;
               http_DebugLog_appendText(
               '** ' + %char(%timestamp()) + ': Detected MIME message');
            endsl;
            g_HTTP_isInit = cTrue;
         endif;

         if (g_isMimeMessage);
            if (MIMEParser_parse(g_hMIMEParser: i_data: i_length) = cTrue);
               rc = i_length;
            else;
               rc = -1;
               http_DebugLog_appendText(
               '** '+ %char(%timestamp()) +': Failed parsing MIME message');
            endif;
         else;
            if (parseOrRedirectResponse(i_data: i_length) = cTrue);
               rc = i_length;
            else;
               rc = -1;
               http_DebugLog_appendText(
               '** '+ %char(%timestamp()) +': Failed parsing XML message');
            endif;
         endif;

         http_DebugLog_appendTextVerbose(
         '** ' + %char(%timestamp()) + ': Leaving ' + f_this() + '()');

         return rc;

      /end-free
      *
     P HTTP_receiveResponse...
     P                 E
      *
      * =====================================================================
      *   Parses or redirects the web service response.
      * =====================================================================
     P parseOrRedirectResponse...
     P                 B
      *
     D parseOrRedirectResponse...
     D                 PI              N
     D  i_data                         *   value
     D  i_length                     10I 0 value
      *
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (OTSWebSvcs_RedirectResponse_isActive());
            // Append HTTP response to output file
            if (not OTSWebSvcs_RedirectResponse_write(
                          i_data: i_length));
               http_DebugLog_appendText(
               '** '+ %char(%timestamp()) +': Failed to redirect +
                                              XML message');
               return cFalse;
            endif;
         else;
            // Parse HTTP response
            if (not XMLSAXParser_parse(g_hSAXParser: i_data: i_length) = cTrue);
               http_DebugLog_appendText(
               '** '+ %char(%timestamp()) +': Failed parsing XML message');
               return cFalse;
            endif;
         endif;

         return cTrue;

      /end-free
      *
     P parseOrRedirectResponse...
     P                 E
      *
      * =====================================================================
      *   Starts a MIME body part.
      *   This procedure is called whenever a new part is started.
      * =====================================================================
      *   Parameters:
      *     i_pPart            Handle of the current part.
      *     i_pUserData        Pointer to user data as specified at
      *                        http_mime_DataSink_initialize().
      * =====================================================================
     P HTTPDataSink_startPart...
     P                 B
      *
     D HTTPDataSink_startPart...
     D                 PI
     D  i_pPart                        *   const
     D  i_pUserData                    *   const
      *
     D contentID       S            512A   varying inz
     D contentSubType  S             16A   varying inz
      *
      * -------------------------------------------
      *  TODO: Add fields to open
      *        the file and to store the
      *        file descriptor.
      * -------------------------------------------
      /IF DEFINED(DEFAULT_ATTACHMENT_HANDLING)
     D contentType     S             10I 0 inz
     D fileName        S           1024A   varying inz
     D fileExt         S             10A   varying inz
      *
     D partUserData    DS                  likeds(partUserData_t )
     D                                     based(pPartUserData)
      /ENDIF
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (http_mime_Part_getType(i_pPart) <> cMIME_BASICPART);
            return;
         endif;

         g_BodyPart_counter = g_BodyPart_counter + 1;

         contentID      = http_mime_Part_getContentID(i_pPart);
         contentSubType = http_mime_Part_getContentSubType(i_pPart);

         if (not g_SOAPMessage_done);
            if (g_SOAPMessageID <> '');
               if (contentSubType = 'xml' and contentID = g_SOAPMessageID);
                  g_doParseSOAPMessage = cTrue;
                  return;
               endif;
            else;
               if (g_BodyPart_counter = 1);
                  g_doParseSOAPMessage = cTrue;
                  return;
               endif;
            endif;
         endif;

         // -----------------------------------------
         // TODO:
         // Add your code to handle attachments here!
         // E.g.: Open output file.
         // -----------------------------------------
      /IF DEFINED(DEFAULT_ATTACHMENT_HANDLING)

         // Ignore all attachments that are not a BasicPart
         if (http_mime_Part_getType(i_pPart) <> cMIME_BASICPART);
            return;
         endif;

         fileName       = http_mime_Part_getFileName(i_pPart);
         contentID      = http_mime_Part_getContentID(i_pPart);
         contentType    = http_mime_Part_getContentType(i_pPart);
         contentSubType = http_mime_Part_getContentSubType(i_pPart);

         if (contentType = cMIME_TYPE_TEXT);
            fileExt = 'txt';
         else;
            fileExt = contentSubType;
         endif;

         fileName = OTSWebSvcs_Attachments_getFolder()
                    + %char(%timestamp()) + '_' + contentID + '_'
                    + fileName  + '.' + fileExt;
         fileName = %xlate(':<>': '___': fileName);

         // Assign filename to content-ID and put it into the list of attachments
         OTSWebSvcs_Attachments_put(
               contentID
               : fileName
               : getOperationUuid());

         // Produce the user data of that Part to
         // store the file descriptor of the open file.
         pPartUserData = %alloc(%size(partUserData_t));
         clear partUserData;

         partUserData.FD = open(fileName
                                : O_CREAT + O_EXCL +
                                  O_SHARE_RDONLY + O_WRONLY + O_CCSID
                                : S_IRWXU + S_IRWXG + S_IRWXO
                                : 819);   // CCSID does not matter because
                                          // we write binary data

         // Set user data of the current Part.
         http_mime_Part_setUserData(i_pPart: pPartUserData);
      /ENDIF

         return;

      /end-free
      *
     P HTTPDataSink_startPart...
     P                 E
      *
      * =====================================================================
      *   Receives MIME part body data.
      *   This procedure is called whenever new body data is available.
      * =====================================================================
      *   Parameters:
      *     i_pPart            Handle of the current part.
      *     i_pUserData        Pointer to user data as specified at
      *                        http_mime_DataSink_initialize().
      *     i_data             Pointer to decoded body data.
      *     i_size             Size of decoded body data.
      * =====================================================================
     P HTTPDataSink_bodyData...
     P                 B
      *
     D HTTPDataSink_bodyData...
     D                 PI
     D  i_pPart                        *   const
     D  i_pUserData                    *   const
     D  i_data                         *   const
     D  i_size                       10I 0 const
      *
      * -------------------------------------------
      *  TODO: Add fields to write
      *        the attachment to the file
      *        opened in HTTPDataSink_startPart().
      * -------------------------------------------
      /IF DEFINED(DEFAULT_ATTACHMENT_HANDLING)
     D rc              S             10I 0 inz
      *
     D partUserData    DS                  likeds(partUserData_t )
     D                                     based(pPartUserData)
      /ENDIF
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (g_doParseSOAPMessage);
            parseOrRedirectResponse(i_data: i_size);
            return;
         endif;

         // -----------------------------------------
         // TODO:
         // Add your code to handle attachments here!
         // E.g.: Write received data to output file.
         // -----------------------------------------

      /IF DEFINED(DEFAULT_ATTACHMENT_HANDLING)
         // Gain access to the user data of the current Part.
         pPartUserData = http_mime_Part_getUserData(i_pPart);
         if (pPartUserData = *NULL);
            return;
         endif;

         // Return to caller if no file is open.
         if (partUserData.FD <= 0);
            return;
         endif;

         // Append attachment data to the file.
         rc = write(partUserData.FD: i_data: i_size);
      /ENDIF

         return;

      /end-free
      *
     P HTTPDataSink_bodyData...
     P                 E
      *
      * =====================================================================
      *   Ends a MIME body part.
      *   This procedure is called whenever a new part ends.
      * =====================================================================
      *   Parameters:
      *     i_pPart            Handle of the current part.
      *     i_pUserData        Pointer to user data as specified at
      *                        http_mime_DataSink_initialize().
      * =====================================================================
     P HTTPDataSink_endPart...
     P                 B
      *
     D HTTPDataSink_endPart...
     D                 PI
     D  i_pPart                        *   const
     D  i_pUserData                    *   const
      *
      * -------------------------------------------
      *  TODO: Add fields to close the file
      *        opened in HTTPDataSink_startPart().
      * -------------------------------------------
      /IF DEFINED(DEFAULT_ATTACHMENT_HANDLING)
     D rc              S             10I 0 inz
      *
     D partUserData    DS                  likeds(partUserData_t )
     D                                     based(pPartUserData)
      /ENDIF
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (http_mime_Part_getType(i_pPart) <> cMIME_BASICPART);
            return;
         endif;

         if (g_doParseSOAPMessage);
            g_doParseSOAPMessage = cFalse;
            g_SOAPMessage_done   = cTrue;
            return;
         endif;

         // -----------------------------------------
         // TODO:
         // Add your code to handle attachments here!
         // E.g.: Close output file.
         // -----------------------------------------
      /IF DEFINED(DEFAULT_ATTACHMENT_HANDLING)

         // Gain access to the user data of the current Part.
         pPartUserData = http_mime_Part_getUserData(i_pPart);
         if (pPartUserData = *NULL);
            return;
         endif;

         // Return to caller if no file is open.
         if (partUserData.FD <= 0);
            return;
         endif;

         // Close the file.
         callp close(partUserData.FD);
         partUserData.FD = 0;

         // Free memory allocated in HTTPDataSink_startPart()
         dealloc(N) pPartUserData;
      /ENDIF

         return;

      /end-free
      *
     P HTTPDataSink_endPart...
     P                 E
      *
      * =====================================================================
      *   SOAP message: Envelope
      * =====================================================================
     P SOAPMessage_Envelope...
     P                 B
      *
     D SOAPMessage_Envelope...
     D                 PI
     D   userdata                      *   value
     D   depth                       10I 0 value
     D   namespace                 1024A   varying const
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (depth = 1 and f_lcase(name) = 'html');
            if (f_exist('WSDL2RPG': '*LIBL': '*MSGF'));
               clear USR0030;
               USR00301 = getPortName();
               AppMsg_sendCancelMsg(AppMsg_newError('USR0030': USR0030));
            else;
               AppMsg_sendCancelMsg(
                     f_newMsg('CPF9898'
                              : 'Unexpected HTML data received from web service'
                              : '*ESCAPE'
                              : 'QCPFMSG'));
            endif;
         endif;

         select;
         when (path = '/Envelope/Header');
            XMLSAXParser_delegateElementProcessing(
               g_pRespSoapHeader
               : %paddr('SOAPMessage_unexpectedElementStart')
               : %paddr('SOAPMessage_unexpectedElementEnd'));
           return;

         when (path = '/Envelope/Body');

            select;
            when (name = 'Fault');
               XMLSAXParser_delegateElementProcessing(
                  %addr(g_errors.soapFault)
                  : %paddr('SOAPMessage_FaultStart')
                  : %paddr('SOAPMessage_FaultEnd'));
              return;

            when (MultiRef_isData(attrs));
               XMLSAXParser_delegateElementProcessing(
                  *NULL
                  : MultiRef_getStartCallback()
                  : MultiRef_getEndCallback());
               return;

            other;
               XMLSAXParser_delegateElementProcessing(
                  userdata
                  : %paddr('impl_dequeue2ResponseStart')
                  : %paddr('impl_dequeue2ResponseEnd'));
              return;
            endsl;

         endsl;

         return;

      /end-free
      *
     P SOAPMessage_Envelope...
     P                 E
      *
      * =====================================================================
      *   SOAP message: fault information
      * =====================================================================
     P SOAPMessage_FaultStart...
     P                 B
      *
     D SOAPMessage_FaultStart...
     D                 PI
     D   userdata                      *   value
     D   depth                       10I 0 value
     D   namespace                 1024A   varying const
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
      *
     D fault...
     D                 DS                  based(userdata)
     D                                     likeds(wsdl_soapFault_t )
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (depth = 1);
            return;
         endif;

         select;
         when (name = 'detail');
            XMLSAXParser_delegateElementProcessing(
               %addr(fault.detail)
               : %paddr('SOAPMessage_FaultDetailStart')
               : %paddr('SOAPMessage_FaultDetailEnd'));
         endsl;

      /end-free
      *
     P SOAPMessage_FaultStart...
     P                 E
      *
      * =====================================================================
      *   SOAP message: fault information
      * =====================================================================
     P SOAPMessage_FaultEnd...
     P                 B
      *
     D SOAPMessage_FaultEnd...
     D                 PI
     D   userdata                      *   value
     D   depth                       10I 0 value
     D   namespace                 1024A   varying const
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   value                    65535A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
      *
     D fault...
     D                 DS                  based(userdata)
     D                                     likeds(wsdl_soapFault_t )
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (depth = 1);
            return;
         endif;

         select;
         when (name = 'faultcode');
            fault.code = value;
         when (name = 'faultstring');
            fault.string = value;
         endsl;

      /end-free
      *
     P SOAPMessage_FaultEnd...
     P                 E
      *
      * =====================================================================
      *   SOAP message: fault details
      * =====================================================================
     P SOAPMessage_FaultDetailStart...
     P                 B
      *
     D SOAPMessage_FaultDetailStart...
     D                 PI
     D   userdata                      *   value
     D   depth                       10I 0 value
     D   namespace                 1024A   varying const
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
      *
     D detail...
     D                 DS                  based(userdata)
     D                                     likeds(wsdl_soap_faultDetail_t)
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (depth = 1);
            return;
         endif;

         select;
         endsl;

      /end-free
      *
     P SOAPMessage_FaultDetailStart...
     P                 E
      *
      * =====================================================================
      *   SOAP message: fault details
      * =====================================================================
     P SOAPMessage_FaultDetailEnd...
     P                 B
      *
     D SOAPMessage_FaultDetailEnd...
     D                 PI
     D   userdata                      *   value
     D   depth                       10I 0 value
     D   namespace                 1024A   varying const
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   value                    65535A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
      *
     D detail...
     D                 DS                  based(userdata)
     D                                     likeds(wsdl_soap_faultDetail_t)
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (depth = 1);
            return;
         endif;

         select;
         when (name = 'hostname');
            detail.hostname = value;
         endsl;

      /end-free
      *
     P SOAPMessage_FaultDetailEnd...
     P                 E
      *
      * =====================================================================
      *   SOAP message: NULL callback procedure
      * =====================================================================
     P SOAPMessage_unexpectedElementStart...
     P                 B
      *
     D SOAPMessage_unexpectedElementStart...
     D                 PI
     D   userdata                      *   value
     D   depth                       10I 0 value
     D   namespace                 1024A   varying const
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (ignoreUnexpectedSoapHeader());
            http_DebugLog_appendText(
               'Warning: Received unexpected Soap header: <' + name + '>');
            return;
         endif;

         if (f_exist('WSDL2RPG': '*LIBL': '*MSGF'));
            clear USR0042;
            USR00421 = 'SOAPMessage_unexpectedElementStart';
            USR00422 = 'SOAPMessage_unexpectedElementEnd';
            AppMsg_sendCancelMsg(AppMsg_newError('USR0042': USR0042));
         else;
            AppMsg_sendCancelMsg(
               f_newMsg('CPF9898'
                     : 'Unexpected Soap element received from web service.'
                     : '*ESCAPE'
                     : 'QCPFMSG'));
         endif;

         return;

      /end-free
      *
     P SOAPMessage_unexpectedElementStart...
     P                 E
      *
      * =====================================================================
      *   SOAP message: NULL callback procedure
      * =====================================================================
     P SOAPMessage_unexpectedElementEnd...
     P                 B
      *
     D SOAPMessage_unexpectedElementEnd...
     D                 PI
     D   userdata                      *   value
     D   depth                       10I 0 value
     D   namespace                 1024A   varying const
     D   name                      1024A   varying const
     D   path                     24576A   varying const
     D   value                    65535A   varying const
     D   attrs                         *   dim(32767)
     D                                     const options(*varsize)
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         if (ignoreUnexpectedSoapHeader());
            http_DebugLog_appendText(
               'Warning: Received unexpected Soap header: ' + value);
            http_DebugLog_appendText(
               'Warning: Received unexpected Soap header: </' + name + '>');
            return;
         endif;

         if (f_exist('WSDL2RPG': '*LIBL': '*MSGF'));
            clear USR0042;
            USR00421 = 'SOAPMessage_unexpectedElementStart';
            USR00422 = 'SOAPMessage_unexpectedElementEnd';
            AppMsg_sendCancelMsg(AppMsg_newError('USR0042': USR0042));
         else;
            AppMsg_sendCancelMsg(
               f_newMsg('CPF9898'
                     : 'Unexpected Soap element received from web service.'
                     : '*ESCAPE'
                     : 'QCPFMSG'));
         endif;

         return;

      /end-free
      *
     P SOAPMessage_unexpectedElementEnd...
     P                 E
      *
      * =====================================================================
      *   Specifies, whether unexpected Soap headers are ignored or not.
      * =====================================================================
     P ignoreUnexpectedSoapHeader...
     P                 B
      *
     D ignoreUnexpectedSoapHeader...
     D                 PI              N
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         return cFalse;

      /end-free
      *
     P ignoreUnexpectedSoapHeader...
     P                 E
      *
      * =====================================================================
      *   Returns the UUID of this web service operation.
      *   All attachments and allocated memory block are attached to
      *   this UUID.
      * =====================================================================
     P getOperationUuid...
     P                 B
      *
     D getOperationUuid...
     D                 PI                          like(wsdl_uuid_t )
      *
      *  Return value
     D uuid            S                   like(wsdl_uuid_t ) inz
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         uuid = OTSWebSvcs_Port_getUuid();

         return uuid;

      /end-free
      *
     P getOperationUuid...
     P                 E
      *
      * =====================================================================
      *   Returns the name of the web service port.
      * =====================================================================
     P getPortName...
     P                 B
      *
     D getPortName...
     D                 PI                          like(wsdl_portName_t )
      *
      *  Return value
     D name            S                   like(wsdl_portName_t ) inz
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         name = OTSWebSvcs_Port_getName();

         return name;

      /end-free
      *
     P getPortName...
     P                 E
      *
      * =====================================================================
      *   Returns the name of this web service operation.
      * =====================================================================
     P getOperationName...
     P                 B
      *
     D getOperationName...
     D                 PI                          like(wsdl_operName_t )
      *
      *  Return value
     D name            S                   like(wsdl_operName_t ) inz
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         name = 'dequeue2';

         return name;

      /end-free
      *
     P getOperationName...
     P                 E
      *
      * =====================================================================
      *   Returns the CCSID of the remote POST data.
      * =====================================================================
     P getPostCcsid...
     P                 B
      *
     D getPostCcsid...
     D                 PI            10I 0
      *
      *  Return value
     D post_ccsid      S             10I 0 inz(1208)
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         post_ccsid = OTSWebSvcs_Port_getPostCcsid();

         return post_ccsid;

      /end-free
      *
     P getPostCcsid...
     P                 E
      *
      * =====================================================================
      *   Returns the timeout in seconds that HTTPAPI waits
      *   for a connection to the server.
      * =====================================================================
     P getTimeout...
     P                 B
      *
     D getTimeout...
     D                 PI            10I 0
      *
      *  Return value
     D timeoutSecs     S             10I 0 inz(HTTP_TIMEOUT)
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         timeoutSecs = OTSWebSvcs_Port_getTimeout();

         return timeoutSecs;

      /end-free
      *
     P getTimeout...
     P                 E
      *
      * =====================================================================
      *   Returns the user agent identification used by HTTPAPI
      *   to identify the client to the server.
      * =====================================================================
     P getUserAgent...
     P                 B
      *
     D getUserAgent...
     D                 PI                         like(wsdl_userAgent_t )
      *
      *  Return value
     D userAgent       S                   like(wsdl_userAgent_t )
     D                                     inz(HTTP_USERAGENT)
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         userAgent = OTSWebSvcs_Port_getUserAgent();

         return userAgent;

      /end-free
      *
     P getUserAgent...
     P                 E
      *
      * =====================================================================
      *   Returns cTrue if the response must be redirected to a stream
      *   file, otherwise cFalse.
      * =====================================================================
     P mustRedirectStmf...
     P                 B
      *
     D mustRedirectStmf...
     D                 PI              N
      *
      *  Return value
     D mustRedirectStmf...
     D                 S               N   inz(cFalse)
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free

         mustRedirectStmf =
            OTSWebSvcs_RedirectResponse_isActive();

         return mustRedirectStmf;

      /end-free
      *
     P mustRedirectStmf...
     P                 E
      *

      * =====================================================================
      *  Generated by WSDL2RPG 1.15.2 / 17.10.2012
      *  Built on Oct 27, 2012 (13:23:07)
      *  Built for V6R1M0
      *  Based on WS_PGM v1.15.2
      * =====================================================================
      *   Sample program to show how to call the
      *     OTSWebSvcs_dequeue2()
      *   Web service.
      * =====================================================================
      *   Pre-Compiler tags used by STRPREPRC to retrieve creation
      *   commands from the source member.
      * ---------------------------------------------------------------------
      * >>PRE-COMPILER<<
      *   >>CRTCMD<< CRTRPGMOD    MODULE(&LI/&OB) +
      *                           SRCFILE(&SL/&SF) +
      *                           SRCMBR(&SM);
      *   >>COMPILE<<
      *     >>PARM<< TRUNCNBR(*NO);
      *     >>PARM<< DBGVIEW(*LIST);
      *   >>END-COMPILE<<
      *   >>EXECUTE<<
      *   >>CMD<<    CRTPGM       PGM(&LI/&OB) +
      *                           MODULE(*PGM) +
      *                           BNDSRVPGM(*LIBL/PMR049A +
      *                                     *LIBL/WSDL2RPGRT    +
      *                                     *LIBL/HTTPAPIR4     +                             RADDAT
      *                                     ) +
      *                           DETAIL(*BASIC) +
      *                           ACTGRP(*NEW);
      * >>END-PRE-COMPILER<<
      * =====================================================================
     H DEBUG
     H OPTION(*SRCSTMT : *NODEBUGIO)
     H EXTBININT(*YES)
      *
      *  Include generated web service stub module to
      *  define the prototype of the web service procedure
      *  and the required type definitions (aka reference fields).
      /DEFINE PROTOTYPE_PMR049A01
      /COPY QWSDL2RPG,PMR049A01
      /UNDEFINE PROTOTYPE_PMR049A01
      *                                                                                       RADDAT
      /COPY QRPGLESRC,HTTPAPI_H                   HTTP API                                    RADDAT
      *
      *  Program entry point
     D PMR049A01T...
     D                 PR
      *
      *  Sends a message to the command line.
     D sndMsg...
     D                 PR                  extproc('sndMsg')
     D  i_text                      128A   value  varying
      *                                                                                       RADDAT
      *  eXpat end element callback procxedure                                                RADDAT
     D Incoming        PR                                                                     RADDAT
     D   userdata                      *   value                                              RADDAT
     D   depth                       10I 0 value                                              RADDAT
     D   name                      1024A   varying const                                      RADDAT
     D   path                     24576A   varying const                                      RADDAT
     D   value                    65535A   varying const                                      RADDAT
     D   Attrs                         *   dim(32767)                                         RADDAT
     D                                     const options(*varsize)                            RADDAT
      *
     D userData_t      S           1024A   varying based(pDummy)                              RADDAT
      *                                                                                       RADDAT
      * =====================================================================
      *  Program entry point
      * =====================================================================
     D PMR049A01T...
     D                 PI
      *
      *  Web service error message text
     D errText         S                   like(wsdl_errText_t ) inz
      *
      *  Request message
      *  These fields needs to be filled with reasonable values
      *  right before calling the web service.
     D parameters      DS                  likeds(impl_dequeue2_t)
     D                                     inz
      *
      *  Response message
      *  This structure contains the result values returned by
      *  the web service.
     D dequeue2Response...
     D                 DS                  likeds(impl_dequeue2Response_t)
     D                                     inz
      *
      *  Text of messages sent to the command line
     D text            S            128A   varying inz
      *
      *  Dynamic array index fields
      *                                                                                       RADDAT
      *  eXpar user data                                                                      RADDAT
     D result          S                   like(userData_t ) inz                              RADDAT
      *                                                                                       RADDAT
      *  eXpar return value                                                                   RADDAT
     D rc              S             10I 0 inz                                                RADDAT
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -                         RADDAT
      /free

         // Enable/disable http api debug log
         // (Enable the http api debug log in case of problems with the web service)
         OTSWebSvcs_Port_setHttpDebug(
            *ON: '/home/raddatz/wsdl2rpg/PMR049A01T.log');                                  //RADDAT

         // Specify a proxy server if your network requires it.
         OTSWebSvcs_Port_setHttpProxy(
            'proxy.obi.de': 8080);                                                          //RADDAT
                                                                                            //RADDAT
         // Switch to local test service                                                    //RADDAT
         OTSWebSvcs_Endpoint_setPort(8080);                                                 //RADDAT
         OTSWebSvcs_Endpoint_setHost(Job_getTcpIpAddr());                                   //RADDAT

         // Set the paramater values of the request message
         // of the web service.
         //    assign values here
         parameters.subscriberId = 123;                                                     //RADDAT
         parameters.transactionIdIn = 456;                                                  //RADDAT

         // Now let's call the web service.
         dequeue2Response =
            OTSWebSvcs_dequeue2(
                parameters:
                errText);

         // If the Web service finished successfully ...
         if (not OTSWebSvcs_Port_isError());
            // ... get response data from response data structure
            rc = http_parse_xml_string(
                    %addr(dequeue2Response.dequeue2Return.transactions) + 2
                    : %len(dequeue2Response.dequeue2Return.transactions)
                    : OTSWebSvcs_Port_getPostCcsid() // = 1208
                    : *null
                    : %paddr(incoming)
                    : %addr(result));                                                       //RADDAT
                                                                                            //RADDAT
            if (rc <> 0);                                                                   //RADDAT
               text = http_error();                                                         //RADDAT
               sndMsg(text);                                                                //RADDAT
            else;                                                                           //RADDAT
               if (result <> 'Hello World');                                                //RADDAT
                  sndMsg('Result does not match ''Hello World''');                          //RADDAT
               else;                                                                        //RADDAT
                  sndMsg('*** Success ***');                                                //RADDAT
               endif;                                                                       //RADDAT
            endif;                                                                          //RADDAT

         else;
            // ... else show error messages ordered by priority:
            // 1. HTTP error information
            text = %char(
                      OTSWebSvcs_HttpError_getCode()
                      ) + ': ' +
                   OTSWebSvcs_HttpError_getText()
                   ;
            sndMsg(text);
            // 2. SOAP error information
            if (OTSWebSvcs_SoapError_getCode()
                  <> '');
               text = OTSWebSvcs_SoapError_getCode()
                      + ': ' +
                      OTSWebSvcs_SoapError_getText()
                      ;
               sndMsg(text);
            endif;
            // 3. XML parser error information
            if (OTSWebSvcs_XmlError_getCode()
                  <> 0);
               text = %char(OTSWebSvcs_XmlError_getCode())
                      + ': ' +
                      OTSWebSvcs_XmlError_getText()
                      ;
               sndMsg(text);
            endif;
         endif;

         *inlr = *on;

      /end-free
      *                                                                                       RADDAT
      * =====================================================================                 RADDAT
      *  eXpat end element callback procedure                                                 RADDAT
      * =====================================================================                 RADDAT
     P Incoming        B                                                                      RADDAT
     D Incoming        PI                                                                     RADDAT
     D   userdata                      *   value                                              RADDAT
     D   depth                       10I 0 value                                              RADDAT
     D   name                      1024A   varying const                                      RADDAT
     D   path                     24576A   varying const                                      RADDAT
     D   value                    65535A   varying const                                      RADDAT
     D   attrs                         *   dim(32767)                                         RADDAT
     D                                     const options(*varsize)                            RADDAT
      *                                                                                       RADDAT
     D result          S                   like(userData_t ) based(userdata)                  RADDAT
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -                         RADDAT
      /free
                                                                                            //RADDAT
         if ( path = '');                                                                   //RADDAT
                                                                                            //RADDAT
            select;                                                                         //RADDAT
            when name = 'Test';                                                             //RADDAT
               result = value;                                                              //RADDAT
            endsl;                                                                          //RADDAT
                                                                                            //RADDAT
         endif;                                                                             //RADDAT
                                                                                            //RADDAT
      /end-free
     P                 E                                                                      RADDAT
      *
      * =====================================================================
      *  *** private ***
      *  Sends a message to the command line.
      * =====================================================================
     P sndMsg...
     P                 B
      *
     D sndMsg...
     D                 PI
     D  i_text                      128A   value  varying
      *
      *  Local fields
     D msgKey          S              4A   inz
      *
      *  Qualified message file name
     D qMsgF           DS                  qualified inz
     D  name                         10A
     D  lib                          10A
      *
      *  API error code
     D errCode         DS                  qualified inz
     D  bytPrv                       10I 0
     D  bytAvl                       10I 0
     D  excID                         7A
     D  reserved                      1A
     D  excDta                      256A
      *
      *  Send Program Message (QMHSNDPM) API
     D QMHSNDPM        PR                         extpgm('QMHSNDPM')
     D   i_msgID                      7A   const
     D   i_qMsgF                     20A   const
     D   i_msgData                32767A   const  options(*varsize )
     D   i_length                    10I 0 const
     D   i_msgType                   10A   const
     D   i_callStkE               32767A   const  options(*varsize )
     D   i_callStkC                  10I 0 const
     D   o_msgKey                     4A
     D   io_ErrCode               32767A          options(*varsize )
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      /free
         clear qMsgF;
         qMsgF.name = 'QCPFMSG';
         qMsgF.lib  = '*LIBL';
         clear errCode;
         errCode.bytPrv = %size(errCode);
         QMHSNDPM('CPF9897': qMsgF: i_text: %len(i_text): '*INFO'
                  : '*CTLBDY': 1: msgKey: errCode);
         return;
      /end-free
      *
     P sndMsg...
     P                 E
      *

HTTPAPI Ver 1.25beta2 released 2012-03-06
NTLM Ver 1.2 released 2012-10-23
OS/400 Ver V6R1M0

New iconv() objects set, PostRem=819. PostLoc=0. ProtRem=819. ProtLoc=0

WSDL2RPG Ver 1.15.2 released 2012-10-12 (V6R1M0)

** 2012-10-27-16.05.21.719000: Entering OTSWebSvcs_dequeue2()
New iconv() objects set, PostRem=1208. PostLoc=0. ProtRem=819. ProtLoc=0
** 2012-10-27-16.05.21.734000: Sending request to server
http_persist_open(): entered
http_long_ParseURL(): entered
DNS resolver retrans: 2
DNS resolver retry  : 2
DNS resolver options: x'00001136'
DNS default domain: gfd.de
DNS server found: 10.200.16.13
DNS server found: 10.200.16.12
http_persist_post(): entered
http_persist_req(POST) entered.
http_long_ParseURL(): entered
http_long_ParseURL(): entered
do_oper(POST): entered
There are 0 cookies in the cache
POST http://10.6.100.251:8080/axis2/services/OTSWebSvcsService HTTP/1.1
Host: 10.6.100.251:8080
User-Agent: http-api/1.24
Content-Length: 300
Content-Type: text/xml
SOAPAction: 


sendraw(): entered
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; xmlns:impl="http://websvcs.otswebws";><soapenv:Body><impl:dequeue2><subscriberId>123</subscriberId><transactionIdIn>456</transactionIdIn></impl:dequeue2></soapenv:Body></soapenv:Envelope>
recvresp(): entered
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=UTF-8
Date: Sat, 27 Oct 2012 14:05:21 GMT
Transfer-Encoding: chunked
Proxy-Connection: Keep-Alive
Connection: Keep-Alive


SetError() #13: HTTP/1.1 200 OK
recvresp(): end with 200
recvdoc parms: chunked 0
header_load_cookies() entered
recvchunk(): entered
get_chunk_size(): entered
19c

chunk size = 412
get_chunk_size returned 412
calling comm_blockread
<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/";><soapenv:Body><ns2:dequeue2Response xmlns:ns2="http://websvcs.otswebws";><dequeue2Return><count>3</count><transactions>PD94bWwgdmVyc2lvbj0nMS4wJyBlbmNvZGluZz0nVVRGLTgnPz48VGVzdD5IZWxsbyBXb3JsZDwvVGVzdD4=</transactions><transactionIdOut>7941</transactionIdOut></dequeue2Return></ns2:dequeue2Response>
comm_blockread returned 412
** 2012-10-27-16.05.21.865000: Preparing to parse received message


get_chunk_size(): entered
22

chunk size = 34
get_chunk_size returned 34
calling comm_blockread
</soapenv:Body></soapenv:Envelope>
comm_blockread returned 34


get_chunk_size(): entered
0

chunk size = 0
get_chunk_size returned 0
http_close(): entered
HTTPAPI Ver 1.25beta2 released 2012-03-06
NTLM Ver 1.2 released 2012-10-23
OS/400 Ver V6R1M0

** 2012-10-27-16.05.21.984000: Leaving OTSWebSvcs_dequeue2()
HTTPAPI Ver 1.25beta2 released 2012-03-06
NTLM Ver 1.2 released 2012-10-23
OS/400 Ver V6R1M0

New XML iconv() objects set, xml_Remote=1208. xml_Local=1208
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------