Question

I have a utility class that converts an Object into an xml String and then builds a pdf out of it.

The class was working fine but I recently started to use continuous deployment on Tomcat (i.e. app.war is now deployed as app##00010.war and a new version of the app is uploaded twice a day) and since then I am having some massive issues with the DocumentBuilder.

My utility class has to load several files from the class path (DTD, fop conf, xsl styesheet, etc.). I use the full path [path start]/Tomcat 7.0/webapps/app##0010/[path to file] to load the files but I get a FileNotFoundException [path start]\Tomcat 7.0\webapps\ app (The system cannot find the file specified).

Hence the DocumentBuilder seems to be ignoring the full path I am giving him.

Here is the method I use to converts the xml String into an xml file:

    public static Document stringToXml(String xmlSource) throws SAXException,ParserConfigurationException,
        MalformedURLException,IOException{
    DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder=factory.newDocumentBuilder();

    return builder.parse(new InputSource(new StringReader(xmlSource)));
}

And the xmlSource is something like "<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE doc SYSTEM "file:///[path start]/Tomcat 7.0/webapps/app##0010/ [...] /pdf.dtd">"

Any idea of how to solve this issue?

Was it helpful?

Solution

Ok I fixed it using a custom entity resolver as shown in this post: Parsing an XML file with a DTD schema on a relative path

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top