7 Replies Latest reply on Aug 30, 2007 1:31 PM by DEfusion

    Thinking of creating a custom HTTPService, advice needed

    DEfusion
      We're working with CakePHP on the backend, currently I'm getting everything back from CakePHP in JSON via a HTTPService.

      I'm wanting to add a application-wide solution to handling the debug data that CakePHP can dump on the end of the response, I was thinking of creating a custom HTTPService that we can use that will strip out any of the CakePHP debug data from the response and display it somewhere within our Flex app (a little debug window). Everything else would then get the response without the CakePHP debug in there.

      However I'm struggling at the first hurdle (changing the result in the event, as it's a read-only property) and wondered if anyone had any advice, alternative solutions etc.

      Thanks in advance,

      -D
        • 1. Thinking of creating a custom HTTPService, advice needed
          levancho Level 3
          maybe?
          you could Extend HTTPService
          and Extend ResultEvent with your SpecialResultEvent,and then add whatever you want to SpecialResultEvent ,including modified result in a forexample new JSONResult property or MyModdeedresultProperty.

          or Create a Result Piping technique.

          internally listen for httpservice and when its back parse the event, do stuff and dispatch new custom Event abc with CustomEventObject with modified Result in it.



          • 2. Re: Thinking of creating a custom HTTPService, advice needed
            DEfusion Level 1
            levancho: That's what I was looking at this morning, extending the HTTPService, but I can't figure out how to make it return a custom ResultEvent object - I'm still pretty new to Flex and don't fully understand the internals of stuff like the HTTPService.
            • 3. Thinking of creating a custom HTTPService, advice needed
              levancho Level 3
              I am not 100% sure it will let you but you can try to extend HTPService and override dispatchEvent method . and dispatch subclass of your Result Event class maybe?
              so framework will call your dispatchEvent method.?
              will that work ? maybe
              • 4. Thinking of creating a custom HTTPService, advice needed
                levancho Level 3
                oor, now that I think of you can create wrapper around HTTPService class to (not extending it, )
                myclass {
                private var _internalHttpService:HTTPService ;


                then wrapp all public methods of HTTPSerivce with corresponding once in this class for example

                public function sent(_obj:Object=null) : void {
                internalHttpService.send(obj);
                }etc ..

                than you register internal listener for your internalHttpService result/fault and parse result internaly and then dispatch new public Custom parsedResultEvent that all other parts of your application are waiting for.

                with this approach you can just extend EventDispatcher so that class can dispatch custom events.
                • 5. Re: Thinking of creating a custom HTTPService, advice needed
                  DEfusion Level 1
                  I've managed to override the dispatchEvent method when extending the HTTPService, and it looks like that could be the way forward. At the moment I've got it checking to see if the event it's dispatching is a result event and if so then I'm doing my stuff and changing that event to my custom one.

                  Question now is, there will be many of these custom HTTPServices allover my application and I want to be able to dump any CakeDebug I get in the response to a central location in the application --- what would be the best way to do that (without passing round the CakeDebugManager -- or whatever I create). I can't have the CakeDebugManager add a listener to every HTTPService as I'll need a reference to the HTTPService and that will break my encapsulation.

                  As I say, I'm still new to Flex.
                  • 6. Thinking of creating a custom HTTPService, advice needed
                    levancho Level 3
                    do it oposite way let customREsultParser add debug info to some centract location collection or hastable

                    e.g in result Parser:

                    // I just got done with parsing,
                    hashtable way :
                    SomeDebugmanager.getInstance().addCakeDebug("myURLName",thissDebugstuff).;

                    list way :
                    SomeDebugmanager.getInstance().addCakeDebug(thissDebugstuff).;

                    with hashtable way you will have extra peice of info : relationship about which cakeDump belongs to which HTTPService url.
                    • 7. Re: Thinking of creating a custom HTTPService, advice needed
                      DEfusion Level 1
                      Can you expand on that a little further, I'm not quite sure what the getInstance() does, I've looked at the IDeferredInstance interface and tried implementing that in a simple class, but surely I still need a reference to SomeDebugManager in order to call the getInstance() method on it.