Select to view content in your preferred language

How to handle layer loading error when target server is down?

937
4
12-28-2010 12:47 PM
RoyceSimpson
Frequent Contributor
I've got a reference to a map service that is hosted by an external agency and today their server was down.  LayerEvent.LOAD_ERROR fires but too late... after the crossdomain.xml security exception is thrown (because it can't be loaded if no server is present). 

I'm not quite sure the best way to handle this and hoping someone has dealt with this and can offer some suggestions.

Thanks,
-Royce
Tags (2)
0 Kudos
4 Replies
by Anonymous User
Not applicable
You could try and wrap your request in a try ... catch block to catch the Security exception, or you could attempt to download the policy file to see if it exists before you load the layer using URLLoader and using its events for example:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html?filter_f...
0 Kudos
RoyceSimpson
Frequent Contributor
You could try and wrap your request in a try ... catch block to catch the Security exception, or you could attempt to download the policy file to see if it exists before you load the layer using URLLoader and using its events for example:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html?filter_f...


Thanks Michael,
I've actually tried both your suggestions and got stumped on both accounts.
With the try/catch block... I put "map.addLayer(layer)" in the try section and the catch never got triggered, even though I still got the crossdomain.xml exception at runtime.  So I'm not to sure which code should be going in there.

In terms of the URLLoader example,  I tried a solution based on that exact example and was having an issue with the load taking so long... The error event would eventually fire but only after a lengthy URL load timeout window... by that time, the app is up and the user is interacting, which would lead to a mess of code changes to enable and disable various controls that are linked to that map service.

In other words, if you have to wait the 30+/- seconds for the request to timeout (looking for the non existent server) all kinds of goofiness ensues because the user is already into the app and interacting.

-Royce
0 Kudos
RoyceSimpson
Frequent Contributor
Ok, so I got this working but not all that happy with the solution.

I setup an initial URLStream of the map service in question with a Complete event to fire when the data has been full retrieved.  If the target server is down, that won't happen for about 30 seconds.  If the target server is up, the event will fire very quickly (under a second).  Either way, I have a module level boolean flag that gets set to true when that event fires.

In the meantime, I also set a Timer to fire a tick event after 2 seconds.  When the event is triggered, it checks the stream flag.  If true, then I go ahead and create the map layer and load it into the map. 

If the timer completes at the end of the two seconds and the flag is still false, the stream is closed, set to null and I don't load the map service.  I then notify the end user that the service not available.

Seems like there should be a MUCH easier way to do this.  Hopefully I've missed something elementary.

Have a great New Year's all.
-r
0 Kudos
RichardWatson
Deactivated User
Related discussion:

http://forums.arcgis.com/threads/15721-checking-if-a-service-is-availible

The same issue exists in all the RESTful clients.
0 Kudos