I've used xpath routes previously and had no problem. I tried doing a split
with xpath on an XHTML document however and the route just hangs. It
doesn't throw an exception or simply fail to find a match for the XPath, it
just hangs.

After 4-5 hours of debugging the issue, I have discovered it is because the
XHTML contains an external DTD declaration (a DOCTYPE) as it should. When
converting the XML content to a DOM it tries to load the external DTD which
never completes, causing the route to hang.

The solution I have found is to add the following class and declare it as a
bean in the Spring configuration and Spring will autowire it into the
XmlConverter, but I would be interested in knowing anything better to avoid
the lockup:

@SuppressWarnings("restriction")
public class NoExternalDtdDocumentBuilderFactory extends
DocumentBuilderFactoryImpl
 {
    public NoExternalDtdDocumentBuilderFactory() throws
ParserConfigurationException
    {
        setValidating(false);
        setNamespaceAware(true);
        setFeature("http://xml.org/sax/features/namespaces";, false);
        setFeature("http://xml.org/sax/features/validation";, false);
        setFeature("
http://apache.org/xml/features/nonvalidating/load-dtd-grammar";, false);
        setFeature("
http://apache.org/xml/features/nonvalidating/load-external-dtd";, false);
    }
}


-- 
Dale King

Reply via email to