tags:

views:

186

answers:

3

I have a wrapper around a HTTPService which handles the RESULT, FAULT and INVOKE events that may be triggered by the send() method. I have verified that the correct event handlers are called on successful requests, HTTP errors (e. g. 404) and on invocation.

I'm testing against a Jetty running on localhost. When it's turned off, i. e. my browser would give me "Can't establish connection", only the INVOKE event is triggered, and there's no error thrown. This means that the call completes normally, but nothing ever happens, leading to a very frustrating user experience.

What's going wrong here, is this a bug or am I doing something wrong? How do I detect when the connection could not be established?

I tried stepping through the framework's source code in the debugger, but that's another can of worms, and a source of a lot frustration. Apparently I can't seem to find the correct SDK version (after the source that shipped with my SDK didn't work, I tried 3.0 through 3.5 from this download page), as the debugger jumps to the wrong lines. I get deepest using version 3.5, but then it gets out of sync again, somewhere down in AsyncInvoker.invoke(). I'm running Flex Builder Linux, alpha 5.

+1  A: 

This works for me with Flex 3.5:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"&gt;

  <mx:Script>
    import mx.controls.Alert;
  </mx:Script>

  <mx:applicationComplete>
    srv.send();
  </mx:applicationComplete>

  <mx:HTTPService id="srv" url="http://localhost:8080/foo.xml"&gt;
    <mx:fault>
      Alert.show("can't connect");
    </mx:fault>
  </mx:HTTPService>

</mx:Application>

The Alert shows when my local server is down.

James Ward
Interesting. I don't use the MXML component, but the AS class (i. e. `mx.rpc.http.HTTPService` instead of `mx.rpc.http.mxml.HTTPService`).I'll give your code a spin and see how it works out.
Hanno Fietz
You can do it that way to by registering a fault event handler on your instance of HTTPService.
James Ward
A: 

Hi there, Just came across this one, and maybe it helps!

<mx:Script>
    <![CDATA[

        import mx.rpc.events.ResultEvent;

        private function faultHandler(event:mx.rpc.events.FaultEvent):void
        {
            var faultInfo:String="fault description: "+event.fault.description+"\n\n";
            faultInfo+="fault faultstring: "+event.fault.faultstring+"\n\n";
            mx.controls.Alert.show(faultInfo,"Fault Information");
            var eventInfo:String="event target: "+event.target+"\n\n";
            eventInfo+="event type: "+event.type+"\n\n";
            mx.controls.Alert.show(eventInfo,"Event Information");  
        }
    ]]>
</mx:Script>
<mx:HTTPService
      fault="faultHandler(event)"/>

I just used the code myself and found two changes you would need to make to use it I think it is FLEX 2 code. Anyway here is the FLEX 3 code!

        <mx:Script>
        <![CDATA[

            import mx.rpc.events.ResultEvent;

            private function faultHandler(event:mx.rpc.events.FaultEvent):void {

                var faultInfo:String="fault details: "+event.fault.faultDetail+"\n\n";
                faultInfo+="fault faultString: "+event.fault.faultString+"\n\n";
                mx.controls.Alert.show(faultInfo,"Fault Information");

                var eventInfo:String="event target: "+event.target+"\n\n";
                eventInfo+="event type: "+event.type+"\n\n";
                mx.controls.Alert.show(eventInfo,"Event Information");  
            }           
        ]]>
    </mx:Script>
aktell
Thanks. That's a slightly more verbose version of James' code. Did it work for you? The main difference with yours and James' to my code is that I'm using the base class for MXML component. I'll give it a spin.
Hanno Fietz
A: 

Hi there,

Yes, my one works the way I send it no problems at all. Unfortuately I can't help with Linux etc. aktell

aktell