4 Replies Latest reply on Jan 22, 2010 8:48 AM by DBrummett

    HTTPService Result

    DBrummett

      I'm trying to send several requests over an HTTPService, and I'm a bit of a hard time.  From my debugging it all most looks like the result event will get thrown several times for a single request.  Can anybody confirm or deny this?

       

      My basic use case is : Login -> Send Query -> Get More -> Get More (repeat until END tag is recieved) -> Logout.

       

      This is the result event handler I'm using for the HTTPService:

      sendQuery() and queryMore() are functions which send requests to the HTTPService.

       

      public function onResult(event : ResultEvent) : void {

      if (!loggedIn) {

      serviceSessionId = event.result.PIEngineResponse.response;

      loggedIn = true;

      sendQuery();

      } else if ((event.result.PIEngineResponse.response == null) && (!queriedMore)) {

      queriedMore = true;

      queryMore();

      } else if ((event.result.PIEngineResponse.response != "END") && (!queriedMore)) {

      queriedMore = true;

      queryMore();

      } else if ((event.result.PIEngineResponse.response != "END") && (queriedMore)) {

      providerSummaryData.concat(xmlRecievedHandler(event.result.PIEngineResponse.response.webRo wSet));

      queryMore();

      } else if (event.result.PIEngineResponse.response == "END") {

      Alert.show("Recieved all data.", "Success");

      }

      }

       

      Any help would be greatly appreciated.

       

      Thanks,

      Dan

        • 1. Re: HTTPService Result
          archemedia Level 4

          What is the result function in your HTTPService? is it onResult? In that case, I'm afraid you're invoking loops on the service.

           

          I can't figure out what you are trying to do, please elaborate

           

          Dany

          • 2. Re: HTTPService Result
            DBrummett Level 1

            Thank you for your reply.

            You are correct the result function I have set in the HTTPService is onResult, and the looping is semi-intentional.

             

            The service I'm trying to communicate with allows me to make one method call to send a query and a batch size, then make a different method call to retrieve a batch of data from the query result.  As you can imagine if the query results in more records than the batch size then I will have to make several calls to retrieve batches  which is why I am trying to create a loop.  The escape case of the loop is if the HTTPService's result has a certain property set to "END" this is the flag that notifies that there are no more batches to retrieve.

             

            The problem that I'm seeing is that I can make the first method call to send the query and batch size, then I can make the second method call to retrieve the first batch of results, but after that is when things start breaking.  I never seem to be able to retrieve the rest of the batches, and the onResult event handler seems to create an infinite loop.

             

            Could you point me in the right direction?

             

            Thanks,

            Dan

            • 3. Re: HTTPService Result
              archemedia Level 4

              I have a few questions:

               

              - Am I right that you can't alter the service itself?

              - When you call the service for the first time, you have to give a batch size right? But you don't know this size because you don't know the number of records returned by the service?

              - After you first call, do you know the exact amount of records to retreive?

               

              I have a solution in mind but I need to know the exact behaviour of the service!

               

              Dany

              • 4. Re: HTTPService Result
                DBrummett Level 1

                I have actually gotten this to work myself by defining a separate event handler for each method call.  I'll answer your questions, then I'll explain what I believe caused the problem and how I resolved it.

                 

                Answers to your questions:

                     -No I cannot alter the service.  It is all ready being used by another production system.

                     -I know the result of the query could contain several thousand records, so to prevent data transfer issues the result is sent across in batches.  I set the batch size depending on the record size (if each record has 100 columns then the batch size should be smaller than if each record has only 3 columns).  If you've used the SalesForce.com API this is exactly like the Batch Size property they use.

                     -I do not know the exact number of records until I have received them all (when I receive the END tag).

                 

                My answer to the issue:

                     I believe the issue was caused by cacheing.  The method call to "Get Next Batch" contains the same URL parameters every time, so the first call to "Get Next Batch" looks exactly the same as the 7th call to "Get Next Batch".  I believe that there is some cacheing going on either in the Adobe HTTPService client or somewhere in the operating system that was causing each subsequent call to "Get Next Batch" to automatically return the initial first response.

                     To resolve the issue I added an extra URL parameter to the "Get Next Batch" parameters.  I did NOT change the service to recognize this parameter, so basically on the server side this parameter will get ignored but it will not cause any kind of error.  Each time I make a call to "Get Next Batch" I increment the value of this parameter so that any possible cacheing will be avoided.

                 

                Here is an example:

                     Method calls that cause cacheing:

                          first call : http://someserver:8456/services/PIEngine?wait=true&request=GetNext&session=XXXXXXXXXX

                          second call : http://someserver:8456/services/PIEngine?wait=true&request=GetNext&session=XXXXXXXXXX

                          You can see that the second call is the exact same as the first.

                     My modification that avoids cacheing:

                          first call : http://someserver:8456/services/PIEngine?wait=true&request=GetNext&session=XXXXXXXXXX&coun t=1

                          second call : http://someserver:8456/services/PIEngine?wait=true&request=GetNext&session=XXXXXXXXXX&coun t=2

                          The count parameter changes every time the method gets called which avoids any cacheing, and the service does not recognize the count         parameter so it will be ignored on the server side.

                 

                I would be happy to hear your possible solution, perhaps it is better than mine.

                 

                Thanks,

                Dan