8 Replies Latest reply on Apr 21, 2009 3:58 PM by fuyuko1979

    Air HTTPService Stream Error #2032

    fuyuko1979

      Hi there,

       

      I am currently creating an Air app which loads 1 or more xml on creation complete.

      So what it does is, it searches for xml files in a given folder by looping over the contents in this folder, if it's an xml then it loads it using HTTPService, it then retrieves the xml data then moves the xml file to another folder, this repeats until all xml files have been loaded.

       

      This is all working fine except sometimes not all xml files get loaded and I encounter the #2032 error, is this because I am loading multiple xml files one after the other in a loop?

      This does not seem to happen if there is only one xml but two or more starts to get a bit temperamental.

       

      Any help would be greatly appreciated, thank you,

       

      Fuyuko

        • 1. Re: Air HTTPService Stream Error #2032
          ATIF FAROOQ Level 3

          hi,

             why dont you move all of the xml's to your destination directory first and then load all of the xml's in to your App one by one synchronously.

          • 2. Re: Air HTTPService Stream Error #2032
            fuyuko1979 Level 1

            hi there, thanks for your reply, what I am making is a little application which sits in a folder and every hour it looks for new xml files within that folder - this means it has no prior knowledge of how many xml files there may be or what their names are.

            These xml files get send from a remote location by ftp and once my app detects the file(s) it then loads each one, extracts the data and then saves it in to a database. Once the data is saved then the file gets moved to a directory called "Processed" so it means that I can't move the xml file until the data gets saved to a database.

            There will be times where there may be more than one xml files in this folder, and that is why I set up a loop at creation complete to loop over all xml files and then to load each one at a time..... is this not synchronously loading?

             

            The whole process is moving as far as I can see, it's just that the loading of the xml's does not happen every single time....

            • 3. Re: Air HTTPService Stream Error #2032
              fuyuko1979 Level 1

              hi there, I figured it out, I had defined a local httpService object in my method, I changed this to define it as a private var at the top of  my script and now everything works fine.

              • 4. Re: Air HTTPService Stream Error #2032
                Michael Borbor Level 4

                Great, please close the thread.

                • 5. Re: Air HTTPService Stream Error #2032
                  fuyuko1979 Level 1

                  oh sorry I spoke too soon, it is not fixed at all...

                  • 6. Re: Air HTTPService Stream Error #2032
                    Michael Borbor Level 4

                    Could you post the code that you use to load  and parse the xml?

                    • 7. Re: Air HTTPService Stream Error #2032
                      fuyuko1979 Level 1

                      Hi there, thanks for your reply.  ok here is the code, when I instantiated the HTTPService object at the top as a private var it works 100% BUT now for some reason it tries to open the same xml three times for all three files! the first time it works, but the second and third time it errors(obviously!).

                      The code in red is the older code which I thought would be the way to do this but almost 50% of the time one of the files does not get loaded and instead gives me the dreaded #2032 error.....

                       

                                  private var fileName:String;
                                  private var dir:File = new File("file:///C:/wamp/www/FileWatcher/Data");
                                  private var processedLocation:File = new File("file:///C:/wamp/www/FileWatcher/Data/processed");

                                  private var service:HTTPService = new HTTPService();
                                 
                                 
                                  private function init():void
                                  {
                                     
                                      //get direcotry listing inside Data
                                      dir.getDirectoryListingAsync();
                                     
                                      //call function to retrieve the names of each file
                                      dir.addEventListener(FileListEvent.DIRECTORY_LISTING, getFileName);
                                  }
                                 
                                  private function getFileName(event:FileListEvent):void
                                  {
                                      for each(var item:File in event.files)
                                      {
                                          //trace(item.name);
                                         
                                           if(item.name!="processed" && item.name!="log.txt")
                                          { 
                                              //set variable to the item name
                                              fileName = item.name;
                                             
                                              //call function to open this file and load the xml contents
                                               getData(fileName);
                                          }
                                      }
                                  }
                                 
                                  private function getData(fileName:String):void
                                  {

                                     var service:HTTPService = new HTTPService();
                                      var urlString:String = "http://localhost/FileWatcher/Data/"+fileName;
                                      service.resultFormat="e4x";
                                      service.url = urlString;
                                      service.addEventListener(ResultEvent.RESULT, function(e:ResultEvent):void{resultHandler(e, fileName)});
                                      service.addEventListener(FaultEvent.FAULT, function(e:FaultEvent):void{faultHandler(e, fileName)});
                                     
                                      service.send();    
                                  }

                       

                                   private function faultHandler(evt:FaultEvent, fileName:String):void
                                  {
                                      var myDate:Date = new Date();
                                      var formattedDate:String = dateFormatter.format(myDate);
                                      var dateString:String = formattedDate+myDate.milliseconds;
                                     
                                      var message:String = "Fault occurred at "+dateString+" The origin of the fault is "+evt.message;
                                      trace("**********************ERROR**********************");
                                      trace("Loading data for "+fileName+" was unsuccessful at "+dateString+"\r\n");
                                  }
                                 
                                  private function resultHandler(evt:ResultEvent, fileName:String):void
                                  {
                                      //trace("result is "+evt.result.toString());
                                      //write data in to the database here
                                     
                                      //get directory listings inside Data
                                      var directory:File = new File("file:///C:/wamp/www/FileWatcher/Data");
                                      directory.getDirectoryListingAsync();
                                     
                                      //call function to move each file to the new location
                                  }

                      • 8. Re: Air HTTPService Stream Error #2032
                        fuyuko1979 Level 1

                        ok, i've answered my own question.

                        It was a timing issue where the application was doing too many things at one time causing occassional stream errors.

                        Fixed the issue by making the application strictly linear.