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

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: [1]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.
   From: Giel van der Merwe [mailto:Giel.vanderMerwe@xxxxxxxxxx]
   Sent: Tuesday, April 29, 2014 1:03 AM
   To: xxx,xxx,xxx
   Subject: RE: Size file XML
   I have been on leave for the last week and am only now starting to look
   at this again,
   When calling this:
   http_url_post_raw
   I get an http error:
   recvdoc: saveproc: Not all data was written!
   I will have to gebug this proc to try and understand the real problem
   Giel van der Merwe
   -----Original Message-----
   From:
   ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx<mailto:ftpapi-bounces@lists.scott
   klement.com> [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf
   Of Scott Klement
   Sent: 17 April 2014 08:24 PM
   To: ftpapi@xxxxxxxxxxxxxxxxxxxxxx<mailto:ftpapi@xxxxxxxxxxxxxxxxxxxxxx>
   Subject: Re: Size file XML
   Hello,
   Can you explain a bit of why getting 101 results will "blow you out of
   the water"? I understand that it's causing you problems, but I don't
   understand exactly which problems or why. Perhaps your program is
   loading the results into an array that has only 20 elements, so you
   need to skip the other 81? If so, why not just skip them? Or is the
   problem the amount of time it takes to send over the network? But that
   seems unlikely as the data doesn't look very big.
   Please clarify.
   On 4/17/2014 7:34 AM, Giel van der Merwe wrote:
   > [cid:image001.gif@01CF5A49.11496990]
   >
   > Hi there all you clever people,
   >
   >
   > I am sort of new to the whole XML/AS400, and I hope someone has a
   > simple answer, I call a web service at MAPIT getting
   > GEO(LATITUDES/LONGATUDES) codes for a specific physical address,
   >
   >
   > Sometimes I get a couple of results and then all works well, but
   > sometimes like the attached result I get 101 results, this then tends
   > to blow me out of the water, Is there a way I can just tell the
   > program to send me what you can, because I am only interested in the
   > first 20 GEOCODEINFORMATION records in anyway
   >
   >
   > Code:
   >
   > [1][cid:image004.png@01CF5A4A.128A7FA0] 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));
   >
   > [2][cid:114041714345501902@mail40.mimecast.co.za]
   >
   >
   ______________________________________________________________________
   > _
   >
   > The provisions of Sections 11,12, and 13 of the Electronic
   > Communications and Transactions Act, 25 of 2002, in so far as
   > e-contracting is concerned is expressly excluded and contracted out
   by
   > Barloworld South Africa (Pty) Ltd ("Barloworld") and no data message
   > or electronic communication will be recognised as having legal
   > contractual status as per the aforementioned provisions under any
   circumstances.
   > All contracts concluded by Barloworld, its Business Units, Divisions
   > and Subsidiaries will only be legally binding and recognised once
   > reduced to physical writing and physically signed by a duly
   authorised
   > representative of Barloworld.
   >
   > All other provisions of the Electronic Communications and
   Transactions
   > Act, 25 of 2002 are accepted.
   >
   >
   ______________________________________________________________________
   > _
   >
   > Note:This message is for the named person's use only. It may contain
   > confidential, proprietary or legally privileged information. No
   > confidentiality or privilege is waived or lost by any
   mistransmission.
   > If you receive this message in error, please immediately delete it
   and
   > all copies of it from your system, destroy any hard copies of it and
   > notify the sender. You must not, directly or indirectly, use,
   > disclose, distribute, print, or copy any part of this message if you
   > are not the intended recipient. Avis and any of its subsidiaries each
   > reserve the right to monitor all e-mail communications through its
   > networks.Any views expressed in this message are those of the
   > individual sender, except where the message states otherwise and the
   > sender is authorized to state them to be the views of any such
   entity.
   > Thank You.
   >
   >
   ______________________________________________________________________
   > _
   >
   > References
   >
   > 1.
   >
   [2]http://vmisfiisintrac/Avis.WebServices.Mapit/GisService.asmx/Search?
   s1
   > =MONTE%20CASINO&s2=SANDTON&type=Point&countryCode=ZAF
   > 2. [3]http://www.avis.co.za/
   >
   >
   >
   >
   ----------------------------------------------------------------------
   > - This is the FTPAPI mailing list. To unsubscribe, please go to:
   > [4]http://www.scottklement.com/mailman/listinfo/ftpapi
   >
   -----------------------------------------------------------------------

References

   1. mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
   2. http://vmisfiisintrac/Avis.WebServices.Mapit/GisService.asmx/Search?s1
   3. http://www.avis.co.za/
   4. http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------