Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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:

25-Nov-2014 09:35:48.802 SEVERE [http-nio-8080-exec-14] CIMObject.CIMObjectCollectDataHANA.setRunningXML TransformerConfigurationException setRunningXMLHANA: javax.xml.transform.TransformerConfigurationException: Cannot set the feature 'http://javax.xml.XMLConstants/property/accessExternalDTD' on this TransformerFactory.

Someone experienced the same error and was able to fix it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
567 views
Welcome To Ask or Share your Answers For Others

1 Answer

It appears the problem is that such feature is not defined in com/sun/org/apache/xalan/internal/utils/FeatureManager.java.

If you are using java 8, then what you need to do is simply to call:

transformerFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);

This is because in 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
 }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...