Catching UnknownHostException of RetrievalUrl in WorldWindJava 2.1 in Netbeans

巧了我就是萌 提交于 2019-12-24 00:52:53

问题


I use WorldWindGlCanvas in a netbeans TopComponent. When top component is opened WorldWInd try to connect to some url (for example worldwind20.arc.nasa.gov). If there is not internet connection UnknowHostException is occured and a dialog is shown to show this exception. I want to catch this exception. Note that I know that worldwind could work offline and I can set it work offline but I want to set worldwind online so that it use online tiles when internet connection is provided and it uses cached tiles if there is no internet connection. Is there any way to catch this exception?


回答1:


Looking at the source code for World Wind, there doesn't appear to be a way to catch that exception.

Upon manually disconnecting my Internet connection, I received a stack trace of the following:

Jun 16, 2017 6:19:43 PM 
gov.nasa.worldwind.util.SessionCacheRetrievalPostProcessor run
SEVERE: Retrieval failed for https://worldwind26.arc.nasa.gov/elev?EXCEPTIONS=application/vnd.ogc.se_xml&REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.3.0
Jun 16, 2017 6:19:43 PM gov.nasa.worldwind.util.SessionCacheUtils retrieveSessionData
SEVERE: Exception while retrieving resources for https://worldwind26.arc.nasa.gov/elev?EXCEPTIONS=application/vnd.ogc.se_xml&REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.3.0
java.net.UnknownHostException: worldwind26.arc.nasa.gov
...
at gov.nasa.worldwind.retrieve.HTTPRetriever.doRead(HTTPRetriever.java:48)
at gov.nasa.worldwind.retrieve.URLRetriever.read(URLRetriever.java:368)
at gov.nasa.worldwind.retrieve.URLRetriever.call(URLRetriever.java:244)
at gov.nasa.worldwind.retrieve.URLRetriever.call(URLRetriever.java:27)
at gov.nasa.worldwind.util.SessionCacheUtils.retrieveSessionData(SessionCacheUtils.java:80)
at gov.nasa.worldwind.util.SessionCacheUtils.getOrRetrieveSessionCapabilities(SessionCacheUtils.java:170)
at gov.nasa.worldwind.terrain.BasicElevationModel.retrieveResources(BasicElevationModel.java:2028)
at gov.nasa.worldwind.terrain.BasicElevationModel$3.run(BasicElevationModel.java:2118)
at java.lang.Thread.run(Thread.java:745)

Based on that stack trace, I investigated a few source files:

URLRetriever.java:

try {
        ...
} catch (Exception e) {
        if (!(e instanceof java.net.SocketTimeoutException || e instanceof UnknownHostException
            || e instanceof SocketException)) {
                Logging.logger().log(Level.SEVERE,
                Logging.getMessage("URLRetriever.ErrorReadingFromConnection", this.url.toString()), e);
        }
        throw e;
}

SessionCacheUtils.java:

try {
        retriever.call();
    } catch (Exception e) {
        String message = Logging.getMessage("layers.TiledImageLayer.ExceptionRetrievingResources", url.toString());
        Logging.logger().log(java.util.logging.Level.SEVERE, message, e);
    }

It appears to be handled internally, and thus you seem to be out of luck.



来源:https://stackoverflow.com/questions/44598508/catching-unknownhostexception-of-retrievalurl-in-worldwindjava-2-1-in-netbeans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!