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

RE: Size file XML



If you had how you call this program to get the error that might help us troubleshoot.  Since you are just trying to accumulate the response into a varying field I am not sure you need all the %subst stuff.  Here is an example of an incoming procedure of mine and it is fairly simple.  I did define my response field quite large (9999999) so I wouldn't fill it up.  You may not need the HTTP_xlate() call but I did in my case.

     p ProcessLogs     b
     D ProcessLogs     PI            10I 0
     D   peFD                        10I 0 value
     D   peData                   65535A   options(*varsize)
     D   peLength                    10I 0 value


      /free
       if peLength > 0;
         HTTP_xlate(peLength : peData : TO_EBCDIC);

         Response += %subst(peData : 1 : peLength);
       ENDIF;

       return peLength;

      /end-free

     p ProcessLogs     e        

Scott

-----Original Message-----
From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Giel van der Merwe
Sent: Monday, May 05, 2014 6:04 AM
To: HTTPAPI and FTPAPI Projects
Subject: RE: Size file XML

The problem seems to be in the INCOMING procedure when the NEXTPOS field is greater than the DATALEN. Here is my code -

     *******************************************************************
     ** DESCRIPTION: HERE WE CONNECT TO A WEB SERVICE, WE GIVE IT       		**
     **              THE ADRESS AND TRY AND GET AN ACCURATE GEO CODE    		**
     **      AUTHOR: GIEL VAN DER MERWE                                 				**
     **        DATE: 18 MARCH 2014                                      					**
     *******************************************************************

     H DFTACTGRP(*NO) BNDDIR('LIBHTTP/HTTPAPI')
     H BNDDIR('QC2LE')

      /copy libhttp/qrpglesrc,httpapi_h

     D cmd             pr                  extpgm('QCMDEXC')
     D  command                     200A   const
     D  length                       15P 5 const

     D translate       pr                  extpgm('QDCXLATE')
     D  length                        5p 0 const
     D  data                      32766A   options(*varsize)
     D   table                       10A   const

     D Enc             s                   like(HTTP_URL_ENCODER)
     D url             s          32767A   varying
     D
     D SOAP            s           8192A   varying
     D Xml             s           5000A   varying
     D result          s             45A
     D wait            s              1A
     D str             s             10A
     D xmlPath         s            100A
     D
     D retdata         s          32766A   inz(*Blanks) varying
     D retdata$        s               *   inz(%addr(retdata))
     D retdatac        s          32766A   based(retdata$)
     D retlen          s             10I 0
     D nextpos         s             10I 0 inz(1)
     D rc              s             10I 0
     D answer          s           1000A   varying
     D SoapAction      s            100
     D  len            s              5p 0
     D cnvdta          s           3000A
     D   tag           s            500A

     *****************************
     ** Address Data Structure ***
     *****************************
     D DSAddr          ds                  qualified dim(20)
     D   dsgeo_x                     17A
     D   dsgeo_y                     17A
     D   dsgeo_tpe                   10A
     D   dsgeo_dsc                   40A
     D   dsgeo_sub                   50A
     D   dsgeo_twn                   50A
     D   dsgeo_prv                   50A
     D   dsgeo_cnt                   50A
     D   dsgeo_ccd                    6A
     D   dsgeo_dst                    5A
     D   dsgeo_mth                   10A

     ************************
     ** define input parms **
     ************************
     D addr1           s             50A
     D addr2           s             50A
     D addr3           s             50A
     D geot            s             10A
     D env             s             50A
     D SubIn           s             50A
     D TwnIn           s             50A
     D RodIn           s             50A

     D incoming        PR            10I 0
     D   descriptor                  10I 0 value
     D   data                      8192A   options(*varsize)
     D   datalen                     10I 0 value

     D getdata         PR          3000A
     D   tag                        500A   value

     D seldata         PR

     D selPoi          PR

     c     *entry        plist
     c                   parm                    addr1
     c                   parm                    addr2
     c                   parm                    addr3
     c                   parm                    geot
     c                   parm                    env
     c                   parm                    SubIn
     c                   parm                    TwnIn
     c                   parm                    RodIn
     c                   parm                    geo_x            17
     c                   parm                    geo_y            17
     c                   parm                    geo_tpe          10
     c                   parm                    geo_dsc          40
     c                   parm                    geo_sub          50
     c                   parm                    geo_twn          50
     c                   parm                    geo_prv          50
     c                   parm                    geo_cnt          50
     c                   parm                    geo_ccd           6
     c                   parm                    geo_dst           5
     c                   parm                    geo_mth          10

     c                   clear                   retdatac

      /free
          SOAP = '<?xml version="1.0" encoding="UTF-8"?>'
          + '<soap:Envelope'
          + ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";'
          + ' xmlns:xsd="http://www.w3.org/2001/XMLSchema";'
          + ' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";>'
          + '<soap:Body>'
          + '<Search xmlns="http://gis.avis.co.za";>'
          + '<s1>'+ %trim(addr1) + '</s1>'
          + '<s2>'+ %trim(addr2) + '</s2>'
          + '<type>'+ %trim(geot) + '</type>'
          + '<countryCode>'+ %trim(addr3) + '</countryCode>'
          + '</Search>'
          + '</soap:Body>'
          + '</soap:Envelope>';

         SoapAction = 'http://gis.avis.co.za/Search';

          url = %trim(env)+ 'WebServices.Mapit/GisService.asmx';

          if http_url_post_raw(url
                                : %addr(SOAP) + 2
                                : %len(SOAP)
                                : 1
                                : %paddr('INCOMING')
                                : HTTP_TIMEOUT
                                : HTTP_USERAGENT
                                : 'text/xml'
                                : %Trim(SoapAction)) =1;
             cnvdta = %trim(retdata);
             len = %len(%trim(cnvdta));
      /end-free
     c                   callp     translate(len:cnvdta:'QTCPEBC   ')
      * get tag information
      /free
             getdata('X');
             getdata('Y');
             getdata('Type');
             getdata('Desc');
             getdata('Suburb');
             getdata('Town');
             getdata('Province');
             getdata('Country');
             getdata('CountryCode');
             getdata('Distance');
             getdata('Match');
          If geot = 'Road';
             seldata();
          Endif;
          If geot = 'Point';
             selPoi();
          Endif;
          else;
             result = http_error();
          endif;

        //  dsply answer ' ' wait;
          *inlr = *on;
          return;
      /end-free
     P*******************************************************************
     P*  this procedure will receive the raw data received from UPS    **
     P*******************************************************************
     P incoming        B
     D incoming        PI            10I 0
     D   descriptor                  10I 0 value
     D   data                      8192A   options(*varsize)
     D   datalen                     10I 0 value

     C* Make sure we don't overflow the string:
     c                   eval      retlen = (nextpos + datalen) - 1
     c                   if        retlen > %size(retdata)
     c                   eval      datalen=datalen-(retlen-%size(retdata))
     c                   endif

     C* If there is nothing to write, return THAT...
     c                   if        datalen < 1
     c                   return    0
     c                   endif

     C* Giel added this
     C                   IF        datalen <= nextpos
     C                   return    0
     C                   ENDIF

     C* Here we add any data sent to the end of our 'retdata' string:
     c                   eval      %subst(retdata: nextpos) =
     c                                %subst(data:1:datalen)
     c                   eval      nextpos = nextpos + datalen

     c* We always return the amount of data that we wrote.   Note
     C*  that if http-api sees that we didn't write as much data as
     C*  it sent us, it'll abort the process with an error message.
     c                   return    datalen
     P                 E
      *
     P***************************************************************
     P*  this procedure will extract the data to a data structure  **
     P***************************************************************
     P getdata         B

     D Start           S             10  0
     D End             S             10  0
     D StartTag        S            500A   Varying
     D EndTag          S            500A   Varying
     D value           S           1000A   Varying
     D AddCnt          S             10  0 inz(0)
     D SavStart        S             10  0 inz(1)
     D SavEnd          S             10  0 inz(1)

     D getdata         PI          3000A
     D   tag                        500A   value

     C                   Eval      StartTag = '<' + %Trim(tag) + '>'
     C                   Eval      EndTag = '</' + %Trim(tag) + '>'

      * ONLY WORK WITH THE FIRST 20 RECORDS RECEIVED
     C                   DOW       AddCnt < 20
     C                   EVAL      AddCnt = AddCnt + 1
     C                   EVAL      value = *BLANKS
     C                   Eval      Start = %Scan(StartTag:cnvdta:SavStart) +
     C                                     %len(StartTag)
     C                   Eval      End = %Scan(EndTag:cnvdta:SavEnd)

     C                   IF        Start < SavStart
     C                   Return    value
     C                   ENDIF

     c                   IF        End > Start
     C                   EVAL      value = %SubSt(cnvdta:Start:End-Start)
     c                   ELSE
     c                   EVAL      value = *BLANKS
     c                   ENDIF

     C                   EVAL      SavStart = Start + 1
     C                   EVAL      SavEnd = End + 1

      * MOVE THE DATA INTO THE CORRECT FIELD IN THE ARRAYS
     C                   IF        tag = 'X'
     C                   EVAL      DSAddr(AddCnt).dsgeo_x = value
     C                   ENDIF

     C                   IF        tag = 'Y'
     C                   EVAL      DSAddr(AddCnt).dsgeo_y = value
     C                   ENDIF

     C                   IF        tag = 'Type'
     C                   EVAL      DSAddr(AddCnt).dsgeo_tpe = value
     C                   ENDIF

     C                   IF        tag = 'Desc'
     C                   EVAL      DSAddr(AddCnt).dsgeo_dsc = value
     C                   ENDIF

     C                   IF        tag = 'Suburb'
     C                   EVAL      DSAddr(AddCnt).dsgeo_sub = value
     C                   ENDIF

     C                   IF        tag = 'Town'
     C                   EVAL      DSAddr(AddCnt).dsgeo_twn = value
     C                   ENDIF

     C                   IF        tag = 'Province'
     C                   EVAL      DSAddr(AddCnt).dsgeo_prv = value
     C                   ENDIF

     C                   IF        tag = 'Country'
     C                   EVAL      DSAddr(AddCnt).dsgeo_cnt = value
     C                   ENDIF

     C                   IF        tag = 'CountryCode'
     C                   EVAL      DSAddr(AddCnt).dsgeo_ccd = value
     C                   ENDIF

     C                   IF        tag = 'Distance'
     C                   EVAL      DSAddr(AddCnt).dsgeo_dst = value
     C                   ENDIF

     C                   IF        tag = 'Match'
     C                   EVAL      DSAddr(AddCnt).dsgeo_mth = value
     C                   ENDIF

     C                   ENDDO

     C                   Return    value

     P                 E
     P*********************************************************************************
     P*  this procedure will try and select the correct one out of the data received **
     P*********************************************************************************
     P seldata         B

     D AddCnt1         S             10  0 inz(0)
     D Result1         S             10  0 inz(0)
     D Result2         S             10  0 inz(0)
     D Result3         S             10  0 inz(0)
     D Result4         S             10  0 inz(0)
     D Up              C                   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
     D Lo              C                   'abcdefghijklmnopqrstuvwxyz'
     D WRod            S             50A
     D WRodR           S             50A
     D WSub            S             50A
     D WSubR           S             50A
     D WTwn            S             50A
     D WTxt            S              5A

     D seldata         PI

      * USE ONLY THE FIRST 20 RECORDS RECEIVED
     C                   DOW       AddCnt1 < 20
     C                   EVAL      AddCnt1 = AddCnt1 + 1
     C                   EVAL      Result1 = 0
     C                   EVAL      Result2 = 0
     C                   EVAL      Result3 = 0
     C                   EVAL      Result4 = 0
     C                   EVAL      WRod = ' '
     C                   EVAL      WSub = ' '
     C                   EVAL      WTwn = ' '
     C                   EVAL      WRodR = DSAddr(AddCnt1).dsgeo_dsc
     C                   EVAL      WSubR = DSAddr(AddCnt1).dsgeo_sub

      * TRANSLATE EVERYTHING INTO UPPER CASE
     C                   Eval      WRod = %Xlate(Lo:Up:RodIn)
     C                   Eval      WSub = %Xlate(Lo:Up:SubIn)
     C                   Eval      WTwn = %Xlate(Lo:Up:TwnIn)
     C                   Eval      WRodR = %Xlate(Lo:Up:WRodR)
     C                   Eval      WSubR = %Xlate(Lo:Up:WSubR)

      * USE THE ROAD SENT IN SO SEE IF IT IS THE CORRECT RECORD
     C                   IF        %Len(%Trim(WRodR)) >= %Len(%Trim(WRod))
     C                   EVAL      Result1 = %Scan((%Trim(WRod)):WRodR)
     C                   ELSE
     C                   IF        WRodR <> ' '
     C                   EVAL      Result3 = %Scan((%Trim(WRodR)):WRod)
     C                   ENDIF
     C                   ENDIF
      * IF NOT FOUND USE A PARTIAL SEARCH
     C                   IF        Result1 = 0 and Result3 = 0 and WRodR <> ' '
     C                   EVAL      Wtxt = %SubSt(WRodR:1:5)
     C                   EVAL      Result1 = %Scan((%Trim(Wtxt)):WRod)
     C                   ENDIF

      * USE THE ROAD SENT IN SO SEE IF IT IS THE CORRECT RECORD
     C                   If        %Len(%Trim(WSubR)) >= %Len(%Trim(WSub))
     C                   EVAL      Result2 = %Scan((%Trim(WSub)):WSubR)
     C                   ELSE
     C                   IF        WSubR <> ' '
     C                   EVAL      Result4 = %Scan((%Trim(WSubR)):WSub)
     C                   ENDIF
     C                   ENDIF

      * IF NOT FOUND USE A PARTIAL SEARCH
     C                   IF        Result2 = 0 and Result4 = 0 and WSubR <> ' '
     C                   EVAL      Wtxt = %SubSt(WSubR:1:5)
     C                   EVAL      Result2 = %Scan((%Trim(Wtxt)):WSub)
     C                   ENDIF

      * IF THE RIGHT ONE IS FOUND MOVE IT TO THE OUTPUT PARAMETERS
     C                   If        ((Result1 > 0) OR (Result3 > 0)) and
     C                             ((Result2 > 0) OR (Result4 > 0))
     C                   EVAL      geo_x = DSAddr(AddCnt1).dsgeo_x
     C                   EVAL      geo_y = DSAddr(AddCnt1).dsgeo_y
     C                   EVAL      geo_tpe = DSAddr(AddCnt1).dsgeo_tpe
     C                   EVAL      geo_dsc = DSAddr(AddCnt1).dsgeo_dsc
     C                   EVAL      geo_sub = DSAddr(AddCnt1).dsgeo_sub
     C                   EVAL      geo_twn = DSAddr(AddCnt1).dsgeo_twn
     C                   EVAL      geo_prv = DSAddr(AddCnt1).dsgeo_prv
     C                   EVAL      geo_cnt = DSAddr(AddCnt1).dsgeo_cnt
     C                   EVAL      geo_ccd = DSAddr(AddCnt1).dsgeo_ccd
     C                   EVAL      geo_dst = DSAddr(AddCnt1).dsgeo_dst
     C                   EVAL      geo_mth = DSAddr(AddCnt1).dsgeo_mth
     C                   RETURN
     C                   Endif

     C                   ENDDO

     C                   Return
     P                 E
     P***********************************************************************
     P*  this procedure will try and select the correct POINT OF INTEREST  **
     P***********************************************************************
     P selPoi          B

     D AddCnt2         S             10  0 inz(0)
     D Result5         S             10  0 inz(0)
     D Result6         S             10  0 inz(0)
     D Up              C                   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
     D Lo              C                   'abcdefghijklmnopqrstuvwxyz'
     D WPoi            S             50A
     D WPoiR           S             50A

     D selPoi          PI

      * USE ONLY THE FIRST 20 RECORDS RECEIVED
     C                   DOW       AddCnt2 < 20
     C                   EVAL      AddCnt2 = AddCnt2 + 1
     C                   EVAL      Result5 = 0
     C                   EVAL      Result6 = 0
     C                   EVAL      WPoiR = DSAddr(AddCnt2).dsgeo_dsc
     C                   EVAL      WPoi = %Xlate(Lo:Up:Addr1)
     C                   EVAL      WPoiR = %Xlate(Lo:Up:WPoiR)

      * USE THE POI DESCRIPTION RECEIVED AND COMPARE IT TO WHAT WE HAVE
     C                   If        %Len(%Trim(WPoiR)) >= %Len(%Trim(WPoi))
     C                   EVAL      Result5 = %Scan((%Trim(WPoi)):WPoiR)
     C                   ELSE
     C                   IF        WPoiR <> ' '
     C                   EVAL      Result6 = %Scan((%Trim(WPoiR)):WPoi)
     C                   ENDIF
     C                   ENDIF

      * IF THE RIGHT ONE IS FOUND MOVE IT TO THE OUTPUT PARAMETERS
     C                   If        (Result5 > 0) or (Result6 > 0)
     C                   EVAL      geo_x = DSAddr(AddCnt2).dsgeo_x
     C                   EVAL      geo_y = DSAddr(AddCnt2).dsgeo_y
     C                   EVAL      geo_tpe = DSAddr(AddCnt2).dsgeo_tpe
     C                   EVAL      geo_dsc = DSAddr(AddCnt2).dsgeo_dsc
     C                   EVAL      geo_sub = DSAddr(AddCnt2).dsgeo_sub
     C                   EVAL      geo_twn = DSAddr(AddCnt2).dsgeo_twn
     C                   EVAL      geo_prv = DSAddr(AddCnt2).dsgeo_prv
     C                   EVAL      geo_cnt = DSAddr(AddCnt2).dsgeo_cnt
     C                   EVAL      geo_ccd = DSAddr(AddCnt2).dsgeo_ccd
     C                   EVAL      geo_dst = DSAddr(AddCnt2).dsgeo_dst
     C                   EVAL      geo_mth = DSAddr(AddCnt2).dsgeo_mth
     C                   RETURN
     C                   Endif

     C                   Enddo

     C                   Return
     P                 E

-----Original Message-----
From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Mike Krebs
Sent: 29 April 2014 07:37 PM
To: HTTPAPI and FTPAPI Projects
Subject: RE: Size file XML

This doesn't look to be very private information although you might be hitting an internal server...Please post the program code and someone here can pretty quickly help with what we see. Sometimes the debug is useful as well.

Reply to list please. That is how everyone benefits.


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