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

Re: "SOAP ACTION" value in HTTPAPI V1.15



On Mon, 18 Sep 2006, Charette, William wrote:
>
> It seems the value of the SOAP ACTION field is 64 bytes, I have one
> that is 65.

Instead of using the peSoapAction parameter (which has a 64 byte limit) 
use an ADDL_HEADER exit point.  This lets you specify any HTTP header with 
a 1024 character limit.

To provide an example of this, I've created EXAMPLE20.  It's identical to 
EXAMPLE18, except that it uses the ADDL_HEADER callback instead of the 
peSoapAction parameter.  AFIAK, this should work just fine with ver 1.15, 
though I've only tested it with 1.16.


       *  This example is identical to EXAMPLE18 except that it
       *  passes the SOAPAction using an "additonal header callback"
       *  this makes it possible to pass much longer SOAPAction
       *  strings.
       *
       *  This sample calls the Currency Exchange Rate Web service
       *  provided by WebserviceX.net. For more info, search for it
       *  at   http://www.WebserviceX.net
       *
       *  To Compile (requires V5R1):
       *     CRTBNDRPG PGM(EXAMPLE20) SRCFILE(libhttp/QRPGLESRC)
       *
       *  To Run:
       *     CALL EXAMPLE20 PARM('USD' 'JPY' 12.00)
       *
       *  (This shows the value of USD 12.00 in Japanese currency.)
       *
      H DFTACTGRP(*NO) BNDDIR('HTTPAPI':'QC2LE')

      D EXAMPLE20       PR                  ExtPgm('EXAMPLE20')
      D   Country1                     3A   const
      D   Country2                     3A   const
      D   Amount                      15P 5 const
      D EXAMPLE20       PI
      D   Country1                     3A   const
      D   Country2                     3A   const
      D   Amount                      15P 5 const

       /copy httpapi_h

      D Incoming        PR
      D   rate                         8F
      D   depth                       10I 0 value
      D   name                      1024A   varying const
      D   path                     24576A   varying const
      D   value                    32767A   varying const
      D   attrs                         *   dim(32767)
      D                                     const options(*varsize)
      D Add_SOAPACTION  PR
      D   Header                    1024A   varying
      D   UserData                      *   value

      D SOAP            s          32767A   varying
      D rc              s             10I 0
      D rate            s              8F
      D Result          s             12P 2

       /free
        SOAP =
         '<?xml version="1.0" encoding="US-ASCII" standalone="no"?>'
        +'<SOAP-ENV:Envelope'
        +'    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";'
        +'    xmlns:tns="http://www.webserviceX.NET/";>'
        +'<SOAP-ENV:Body>'
        +'  <tns:ConversionRate>'
        +'      <tns:FromCurrency>'+ %trim(Country1) +'</tns:FromCurrency>'
        +'      <tns:ToCurrency>'+ %trim(Country2) + '</tns:ToCurrency>'
        +'  </tns:ConversionRate>'
        +'</SOAP-ENV:Body>'
        +'</SOAP-ENV:Envelope>';

        http_debug(*ON);

        //  This tells HTTPAPI to call our subprocedure (in this example,
        //  the subprocedure is name ADD_SOAPACTION) when assembling the
        //  HTTP headers to send to the remote server.

        http_xproc( HTTP_POINT_ADDL_HEADER
                  : %paddr(Add_SOAPACTION) );

        rc = http_url_post_xml(
                   'http://www.webservicex.net/CurrencyConvertor.asmx'
                          : %addr(SOAP) + 2
                          : %len(SOAP)
                          : *NULL
                          : %paddr(Incoming)
                          : %addr(rate)
                          : HTTP_TIMEOUT
                          : HTTP_USERAGENT
                          : 'text/xml' );

        if (rc <> 1);
           http_crash();
        else;
           Result = %dech(Amount * rate: 12: 2);
           http_comp(%trim(Country1) + ' ' + %char(%dec(Amount:12:2))
                     + ' = ' + %trim(Country2) + ' '+ %char(Result));
        endif;

        *inlr = *on;

       /end-free

      P Incoming        B
      D Incoming        PI
      D   rate                         8F
      D   depth                       10I 0 value
      D   name                      1024A   varying const
      D   path                     24576A   varying const
      D   value                    32767A   varying const
      D   attrs                         *   dim(32767)
      D                                     const options(*varsize)

      D atof            PR             8F   extproc('atof')
      D   string                        *   value options(*string)

       /free
           if (name = 'ConversionRateResult');
              rate = atof(value);
           endif;
       /end-free
      P                 E

       *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       * HTTPAPI will call this (because we set it with http_xproc)
       * just before sending the HTTP headers to the remote server.
       * This procedure lets us add any header we like to the
       * HTTP request.
       *
       * In this example, I'll use it to supply the SoapAction:
       * header.  This way, I can supply a SOAPAction that's up to
       * 1024 characters long.
       *
       * NOTE: Make sure you leave off the SOAPAction header on the
       *       HTTP_url_post_xml, above, otherwise you'll send two
       *       of them!
       *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      P Add_SOAPACTION  B
      D Add_SOAPACTION  PI
      D   Header                    1024A   varying
      D   UserData                      *   value
       /free
          Header = 'SOAPAction: '
                 + 'http://www.webserviceX.NET/ConversionRate'
                 + x'0d25';
       /end-free
      P                 E
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------