gpt4 book ai didi

Java 和 Xerces : can't find property XMLConstants. ACCESS_EXTERNAL_DTD

转载 作者:行者123 更新时间:2023-11-28 22:15:55 25 4
gpt4 key购买 nike

我在此博客上查找了类似的帖子,但找不到我的问题的答案,所以我决定寻求帮助。

我用 Java 编写了这个简单的函数:

 public void open(InputStream stream) throws FoliumFatalException {
try {
InputSource is = new InputSource(stream);
DocumentBuilderFactory dfact = DocumentBuilderFactory.newInstance();

// /* OWASP: inhibit access to External Entities */
dfact.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
dfact.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");

_doc = dfact.newDocumentBuilder().parse(is);

} catch (Throwable t) {
_logger.error(t, t);
throw new FoliumFatalException("ENG-0017", "Errore di parsing su stream", t);
}

}

我的目标是应用公开的 OWASP 标准 here ,但出现以下错误:

 java.lang.IllegalArgumentException: Property 'http://javax.xml.XMLConstants/property/accessExternalDTD' is not recognized.
java.lang.IllegalArgumentException: Property 'http://javax.xml.XMLConstants/property/accessExternalDTD' is not recognized.
at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.setAttribute(Unknown Source) ~[xercesImpl-2.8.0.jar:?]
at agora.folium.engine.impl.j2ee.FoliumJ2eeXmlParserImpl.open(FoliumJ2eeXmlParserImpl.java:108) [classes/:?]
at agora.folium.engine.impl.FoliumAbstractEngine.loadServices(FoliumAbstractEngine.java:268) [classes/:?]
at agora.folium.engine.impl.j2ee.FoliumJ2eeEngineImpl.startup(FoliumJ2eeEngineImpl.java:110) [classes/:?]
at agora.folium.engine.Folium.startup(Folium.java:258) [classes/:?]
at agora.folium.control.impl.j2ee.FoliumActionServlet.init(FoliumActionServlet.java:94) [classes/:?]
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1230) [catalina.jar:7.0.85]
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1174) [catalina.jar:7.0.85]
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1066) [catalina.jar:7.0.85]
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5370) [catalina.jar:7.0.85]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5668) [catalina.jar:7.0.85]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) [catalina.jar:7.0.85]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1015) [catalina.jar:7.0.85]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:991) [catalina.jar:7.0.85]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652) [catalina.jar:7.0.85]
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:712) [catalina.jar:7.0.85]
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:2002) [catalina.jar:7.0.85]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_141]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_141]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_141]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_141]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_141]

我正在使用 Eclipse Oxygen、Tomcat 7 和 Java 1.8。

最佳答案

javax.xml.XMLConstants.ACCESS_EXTERNAL_DTDJAXP 1.5 中定义, 但 Xerces 不支持它。如果您不能删除 Xerces 依赖项,则应该在 Xerces 之前将另一个实现添加到您的类路径中。

或者,由于 JDK 包含 Xerces 的实现,您可以 configure DocumentBuilderFactory 使用 System.properties 返回 JDK 版本。

System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
"com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");

关于Java 和 Xerces : can't find property XMLConstants. ACCESS_EXTERNAL_DTD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53299280/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com