javaxmljvmcxml

Can I validate dtd reading xml in Java


Hello I have an XML which has this DTD:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2.014/cXML.dtd">

In Java(IBM) I use this to parse the xml:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
DocumentBuilder builder = factory.newDocumentBuilder();     
InputSource is = new InputSource(new StringReader(xml));
domdoc = builder.parse(is);

But when this agent is executed then I will receive an error at the code builder.parse(is). This is the log:

29-03-2017 13:56:00   HTTP JVM: java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key connect_not_allowed
29-03-2017 13:56:00   HTTP JVM:     at java.util.ResourceBundle.getObject(ResourceBundle.java:502)
29-03-2017 13:56:00   HTTP JVM:     at java.util.ResourceBundle.getString(ResourceBundle.java:516)
29-03-2017 13:56:00   HTTP JVM:     at lotus.notes.JavaString.getFormattedString(Unknown Source)
29-03-2017 13:56:00   HTTP JVM:     at lotus.notes.AgentSecurityManager.checkConnect(Unknown Source)
29-03-2017 13:56:00   HTTP JVM:     at sun.net.www.http.HttpClient.openServer(HttpClient.java:549)
29-03-2017 13:56:00   HTTP JVM:     at sun.net.www.http.HttpClient.<init>(HttpClient.java:227)
29-03-2017 13:56:00   HTTP JVM:     at sun.net.www.http.HttpClient.New(HttpClient.java:313)
29-03-2017 13:56:00   HTTP JVM:     at sun.net.www.http.HttpClient.New(HttpClient.java:332)
29-03-2017 13:56:00   HTTP JVM:     at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.ja     
29-03-2017 13:56:00   HTTP JVM:     at  sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:936)
29-03-2017 13:56:00   HTTP JVM:     at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:854)
29-03-2017 13:56:00   HTTP JVM:     at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1208)
29-03-2017 13:56:00   HTTP JVM:     at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
29-03-2017 13:56:00   HTTP JVM:     at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
29-03-2017 13:56:00   HTTP JVM:     at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown Source)
29-03-2017 13:56:00   HTTP JVM:     at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
29-03-2017 13:56:00   HTTP JVM:     at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source)
29-03-2017 13:56:00   HTTP JVM:     at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
29-03-2017 13:56:00   HTTP JVM:     at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
29-03-2017 13:56:00   HTTP JVM:     at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
29-03-2017 13:56:00   HTTP JVM:     at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
29-03-2017 13:56:00   HTTP JVM:     at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
29-03-2017 13:56:00   HTTP JVM:     at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
29-03-2017 13:56:00   HTTP JVM:     at JavaAgent.NotesMain(Unknown Source)
29-03-2017 13:56:00   HTTP JVM:     at lotus.domino.AgentBase.runNotes(Unknown Source)
29-03-2017 13:56:00   HTTP JVM:     at lotus.domino.NotesThread.run(Unknown Source)

etc.

But when I add this line:

factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);

then it works...

Question: Can I validate xml with the dtd schema in Java and if yes, how?

dtd: http://xml.cXML.org/schemas/cXML/1.2.014/cXML.dtd


Solution

  • Agent needs to be set on Allow restricted operations (server side):

    enter image description here