在TransformerFactory中设置功能accessExternalDTD [英] Set feature accessExternalDTD in TransformerFactory
问题描述
出于安全原因,我添加了以下语句:
For security reasons I'm adding the statement:
transformerFactory.setFeature("http://javax.xml.XMLConstants/property/accessExternalDTD", false);
但是我在日志文件中遇到以下错误:
However I'm getting the following error in the log files:
2014年11月25日09:35:48.802严重[http-nio-8080-exec-14] CIMObject.CIMObjectCollectDataHANA.setRunningXML TransformerConfigurationException setRunningXMLHANA:javax.xml.transform.TransformerConfigurationException:无法设置功能' http://javax.xml.XMLConstants/property/accessExternalDTD ".
有人遇到了相同的错误并能够解决?
Someone experienced the same error and was able to fix it?
推荐答案
看来,问题在于 com/sun/org/apache/xalan/internal/utils/FeatureManager.java <中未定义该功能/code>.
It appears the problem is that such feature is not defined in com/sun/org/apache/xalan/internal/utils/FeatureManager.java
.
如果您使用的是Java 8,则只需执行以下操作即可:
If you are using java 8, then what you need to do is simply to call:
transformerFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING,true);
这是因为在 com/sun/org/apache/xalan/internal/xsltctrax/TransformerFactoryImpl.java
中:
if (value && XalanConstants.IS_JDK8_OR_ABOVE) {
_xmlSecurityPropertyMgr.setValue(
Property.ACCESS_EXTERNAL_DTD,
State.FSP,
XalanConstants.EXTERNAL_ACCESS_DEFAULT_FSP
); // ACCESS_EXTERNAL_DTD is disabled by setting to the default value
}
这篇关于在TransformerFactory中设置功能accessExternalDTD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!