tags:

views:

278

answers:

3

I am developing an AIR application with Flex Builder that requires me to make two HTTPService requests at the same time. They both use different instances of the HTTPService AS3 class. Both services are calling a RESTful API which is currently running on my localhost (XAMPP) and takes a few seconds to respond (much quicker on live server).

The problem is that most of the time one of the calls fails, however occasionally they do both work. Its also random as to which call will fail.

Thanks in advance,

Chris

Both calls use code something like this. This code is basically repeated in two classes.

//in constructor 
brokerageService = new HTTPService();
brokerageService.resultFormat = HTTPService.RESULT_FORMAT_E4X;
brokerageService.addEventListener(ResultEvent.RESULT, onBrokerageResult);
brokerageService.addEventListener(FaultEvent.FAULT, onFault); 
//call 
public function findBrokerages(type:String, value:String):void{
        var url:String = serviceURL + "Contacts/findBrokerage/" + type + "/" + value + ".xml";
        brokerageService.url = url;
        brokerageService.send();
} 
//response 
private function onBrokerageResult(e:ResultEvent):void{

        var response:XML = brokerageService.lastResult as XML;
        etc...
} 
// handle error 
private function onFault(e:FaultEvent):void{
        trace(e.target + " " + e.target.url);
        trace(e);
        dispatchEvent(new ServiceEvent(ServiceEvent.CONNECTION_PROBLEM, true));
}
A: 

Can you paste the details of the error message you are getting? Are you sure this isn't a problem with the XMPP service? Try testing the service by sending the same requests with a tool like curl.

elevine
Error message is:[FaultEvent fault=[RPC Fault faultString="HTTP request error" faultCode="Server.Error.Request" faultDetail="Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://www.domain.com/dummpyAPI.xml" errorID=2032]. URL: http://www.domain.com/dummpyAPI.xml"] messageId="5477D9B6-DD93-2B11-12E5-02F736E7EC43" type="fault" bubbles=false cancelable=true eventPhase=2]If you can offer advice on how i might quickly test with CURL that would be appreciated.
Chris Rowe
CURL is available on most *nix systems, mac, or cygwin (for windows). Details for using it are here: http://curl.haxx.se/docs/manpage.html . If you are just doing a GET request, than you can use your web browser to test it. Another option is the Poster plugin for Firefox: https://addons.mozilla.org/en-US/firefox/addon/2691
elevine
A: 

I've resorted to resending the service request if a fault event occurs, up to a maximum of three times.

Its not my ideal solution but it works.

Chris

Chris Rowe
A: 

I found myself getting these errors when I was getting malformed XML as a result, the E4X wouldn't/couldn't handle it. Try resending a failed request, and make the resultformat plain text, then check the output.

If I open the XML in Firefox it renders correctly. I usually find that this is a good test for well structured XML.
Chris Rowe