首页 > 解决方案 > 访问 WMTS 服务的 Geotools 抛出 stackoverflow 解析 XML

问题描述

我正在访问
http://geodata.nationaalgeoregister.nl/luchtfoto/infrarood/wmts?request=GetCapabilities&service=WMTS
(这是荷兰 PDOK 网站上的众多免费服务之一

我正在使用 JMapFrame(Java 1.8u131x86,Geotools 18.3 模块不支持摇摆)。它抛出:

May 07, 2018 4:37:29 PM org.geotools.xml.resolver.SchemaCache resolveLocation
INFO: Cached XML schema: http://schemas.opengis.net/wmts/1.0/wmtsGetCapabilities_response.xsd
May 07, 2018 4:37:30 PM org.geotools.xml.resolver.SchemaCache resolveLocation
INFO: Cached XML schema: http://schemas.opengis.net/wmts/1.0/wmts.xsd
May 07, 2018 4:37:30 PM org.geotools.xml.resolver.SchemaCache resolveLocation
INFO: Cached XML schema: http://schemas.opengis.net/wmts/1.0/wmtsKVP.xsd
May 07, 2018 4:37:31 PM org.geotools.data.ows.AbstractOpenWebService internalIssueRequest
SEVERE: Failed to execute request http://geodata.nationaalgeoregister.nl/luchtfoto/infrarood/wmts?REQUEST=GetCapabilities&VERSION=1.3.0&SERVICE=WMS
Exception in thread "main" java.lang.StackOverflowError
    at java.io.InputStream.<init>(InputStream.java:45)
    at java.io.FileInputStream.<init>(FileInputStream.java:123)
    at java.io.FileInputStream.<init>(FileInputStream.java:93)
    at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90)
    at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:623)
    at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:148)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:805)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:770)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:274)
    at org.geotools.xml.SchemaFactory.getRealInstance(SchemaFactory.java:323)
    at org.geotools.xml.SchemaFactory.getInstance(SchemaFactory.java:309)
    at org.geotools.xml.handlers.xsi.SchemaHandler.compress(SchemaHandler.java:386)
    at org.geotools.xml.handlers.xsi.RootHandler.getSchema(RootHandler.java:118)
    at org.geotools.xml.XSISAXHandler.getSchema(XSISAXHandler.java:258)
    at org.geotools.xml.SchemaFactory.getRealInstance(SchemaFactory.java:334)
    at org.geotools.xml.SchemaFactory.getInstance(SchemaFactory.java:309)
    at org.geotools.xml.handlers.xsi.SchemaHandler.compress(SchemaHandler.java:386)
    at org.geotools.xml.handlers.xsi.RootHandler.getSchema(RootHandler.java:118)
    at org.geotools.xml.XSISAXHandler.getSchema(XSISAXHandler.java:258)
    at org.geotools.xml.SchemaFactory.getRealInstance(SchemaFactory.java:334)
    at org.geotools.xml.SchemaFactory.getInstance(SchemaFactory.java:309)
    at org.geotools.xml.handlers.xsi.SchemaHandler.compress(SchemaHandler.java:386)
    at org.geotools.xml.handlers.xsi.RootHandler.getSchema(RootHandler.java:118)
    at org.geotools.xml.XSISAXHandler.getSchema(XSISAXHandler.java:258)
    at org.geotools.xml.SchemaFactory.getRealInstance(SchemaFactory.java:334)
    at org.geotools.xml.SchemaFactory.getInstance(SchemaFactory.java:309)
    at org.geotools.xml.handlers.xsi.SchemaHandler.compress(SchemaHandler.java:386)

Web 服务返回的 XML 似乎未按预期格式化。我能做些什么吗?

标签: javaxmlxsdgeotools

解决方案


如果您使用带有 WMTS url 的 WMSServer,则查找模式似乎存在问题 - 我打开了一个错误

但简单的答案是像这样构造它:

URL url = new URL("http://geodata.nationaalgeoregister.nl/luchtfoto/infrarood/wmts?request=GetCapabilities&service=WMTS");
try {
  wmts = new WebMapTileServer(url);
} catch (ServiceException | IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  System.exit(2);
}
WMTSCapabilities capabilities = wmts.getCapabilities();
List<WMTSLayer> wmtsLayers = capabilities.getLayerList();

推荐阅读