I’m having exception org.xml.sax.SAXNotRecognizedException Property 'http://javax.xml.XMLConstants/property/accessExternalDTD' is not recognized.
In my project I’ve apache camel-jaxb lib version 4.6.0 which is setting some of the properties in SchemaFactory which is not recognized by xerces,
factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, protocols);
private static SchemaFactory createSchemaFactory(String protocols) throws SAXException {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
if (protocols == null || "false".equals(protocols) || "none".equals(protocols)) {
protocols = "";
LOG.debug("Configuring SchemaFactory to not allow access to external DTD/Schema");
} else {
LOG.debug("Configuring SchemaFactory to allow access to external DTD/Schema using protocols: {}", protocols);
}
factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, protocols);
factory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, protocols);
return factory;
}
I cannot control the above code as it’s from camel-jaxb.
I’ve tried some solutions like setting system properties as following:
-Djavax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema=com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory
-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
But not worked for me.
I cannot exclude xerces from my project as a third party library is using it.
How can I solve this problem?