logo       

Entity resolving: msg#00029

Subject: Entity resolving
Hi,

I'm not entirely certain this is a xerces problem, but since the top part of my stack trace is xerces classes I thought I'd try here first. Let me know if it's more likely one of the other components that's the problem, and I'll go hassle them :-)

I have a servlet which runs an XSL transformation (stylesheet read from a file) on an XML document held in a string. The document's doctype includes public & system IDs, but the URL in the system ID doesn't exist (yet) so I'm using the Apache XML Commons catalog entity resolver to substitute a local copy of the DTD. At least, that's the theory.

I know the catalog manager is finding its configuration file okay (the log shows messages resolving the URIs it contains to absolute paths) and the resolved path is the location of my DTD. However, when the transform runs, I get an exception that seems to be because it's trying to access the original (http) systemId instead of using the local copy. I don't see any messages from the resolver in the log to suggest that it's even been called upon to resolve the DTD location.

The code I'm using is

URL xslUrl = MyServlet.class.getResource(XSL_STYLESHEET);
InputStream xslIn = MyServlet.class.getResourceAsStream(XSL_STYLESHEET);
DOMResult domOut = new DOMResult();
TransformerFactory factory = TransformerFactory.newInstance();
factory.setURIResolver(new CatalogResolver());
Transformer stylesheet = factory.newTransformer(new StreamSource(xslIn, xslUrl.toExternalForm()));
stylesheet.transform(new StreamSource(new StringReader(xml)), domOut);

the document is

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data PUBLIC "-//FOOBAR/DTD My Data 1.0//EN" "http://internal.host/dtd/data-1.0.dtd";>
<data>
        <point x="0" y="0" size="5"/>
        <point x="10" y="20" size="10"/>
        <point x="20" y="40" size="2"/>
</data>

and the log file contains

Parse catalog: file:/C:/app/build/web/WEB-INF/catalog.xml
Loading catalog: file:/C:/app/build/web/WEB-INF/catalog.xml
Default BASE: file:/C:/app/build/web/WEB-INF/catalog.xml
public: -//FOOBAR/DTD My Data 1.0//EN
        ../dtd/data-1.0.dtd
PUBLIC: -//FOOBAR/DTD My Data 1.0//EN
        file:/C:/app/build/web/dtd/data-1.0.dtd
system: http://internal.host/dtd/data-1.0.dtd
        ../dtd/data-1.0.dtd
SYSTEM: http://internal.host/dtd/data-1.0.dtd
        file:/C:/app/build/web/dtd/data-1.0.dtd
[ERROR] TransformerException:java.io.FileNotFoundException: http://internal.host/dtd/data-1.0.dtd javax.xml.transform.TransformerException: java.io.FileNotFoundException: http://internal.host/dtd/data-1.0.dtd at org.apache.xalan.transformer.TransformerImpl.fatalError(TransformerImpl.java:741) at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:715) at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1129) at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1107)
        at com.foobar.MyServlet.processRequest(MyServlet.java:86)
        at com.foobar.MyServlet.doPost(MyServlet.java:203)
...
Caused by: java.io.FileNotFoundException: http://internal.host/dtd/data-1.0.dtd at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:798) at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
        at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
        at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown 
Source)
        at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown 
Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xml.dtm.ref.DTMManagerDefault.getDTM(DTMManagerDefault.java:495) at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:658)
        ... 20 more
java.io.FileNotFoundException: http://internal.host/dtd/data-1.0.dtd
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:798) at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
        at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
        at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown 
Source)
        at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown 
Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xml.dtm.ref.DTMManagerDefault.getDTM(DTMManagerDefault.java:495) at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:658) at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1129) at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1107)
        at com.foobar.MyServlet.processRequest(MyServlet.java:86)
        at com.foobar.MyServlet.doPost(MyServlet.java:203)

If I use some string manipulation to remove the doctype's public & system IDs before passing the string on to the transform (i.e. leaving just <!DOCTYPE data>) then it works fine.

Any suggestions? Is there something wrong with my code, or is it a xerces/xalan/entityresolver bug?

Thanks for any help,


Andrew.


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe