[jdom-interest] Strange behaviour of applet when accessing the DTD

Bernd Eggink Bernd.Eggink at rrz.uni-hamburg.de
Wed Oct 8 02:09:23 PDT 2003


On Tue, Oct 07, 2003 at 11:59:52PM +0200, Per Norrman wrote:
> It's not about validation or not. The DTD is still read,
> even if validation is turned off; for instance, entities
> may have to be resolved.

You're right. I tested it again, and indeed the effect is independent
on validation. 

> My first guess would be that the browser has a problem
> because localhost is not really the same as 127.0.0.1.

No, the setting for localhost is correct.

> Try making the SYSTEM id relative, i.e.
>      <!DOCTYPE dialog SYSTEM "dialog.dtd" [
>          ...
>      ]>

_That_ doesn't work at all ("can't resolve relative URI without a base
URL").

> Even if this is not the cause of your problem, it is strange
> to have a URI in the source file refer to 'localhost'.

Why?

> Otherwise, what's in the DTD? What is the root cause of the
> exception?

It's all about "access denied":

org.jdom.input.JDOMParseException: Error on line 2: access denied (java.net.SocketPermission 127.0.0.1:80 connect,resolve)
    at org.jdom.input.SAXBuilder.build(SAXBuilder.java:381)
    at org.jdom.input.SAXBuilder.build(SAXBuilder.java:764)
    at Tst.init(Tst.java:18)
    at sun.applet.AppletPanel.run(AppletPanel.java:353)
    at java.lang.Thread.run(Thread.java:534)
Caused by: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:80 connect,resolve)
    at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:658)
    at org.apache.crimson.parser.Parser2.parse(Parser2.java:333)
    at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
    at org.jdom.input.SAXBuilder.build(SAXBuilder.java:370)
    ... 4 more

and so on.

I boilt the whole thing down to a short test case:

/////////////// applet

import java.io.*;
import javax.swing.*;
import java.net.*;
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;

public class Tst extends JApplet
{
    public void init()
    {
        try
        {
            Reader      reader = new InputStreamReader(new URL("http://localhost/eggink/dia.xml").openStream());
            Document    document = new SAXBuilder(true).build(reader);
            
            reader.close();
            JTextArea   text = new JTextArea(new XMLOutputter().outputString(document));
            getContentPane().add(new JScrollPane(text));
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
}

//////////////// dia.xml 

<?xml version="1.0" encoding="ISO8859-1" standalone="no" ?>
<!DOCTYPE dialog SYSTEM "http://localhost/eggink/tst.dtd" >
<dialog>
    <menu>
        <item>
            <goto/>
        </item>
    </menu>
</dialog>

/////////////// tst.dtd

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!ELEMENT dialog (menu)* >
<!ELEMENT menu (item)* >
<!ELEMENT item  (#PCDATA | goto)* >
<!ELEMENT goto EMPTY>
<!ATTLIST goto
    menu        CDATA   #IMPLIED
>

////////////////

Here again is what happens:

1. First time the applet starts, I get access errors (see above).
2. After pressing the reload button it runs properly.
3. If I replace 'localhost' by the complete address of my system, I
   _always_ get access errors, even when reloading.

This is weird. And it must be a JDOM issue: I wrote a version of the
test applet which uses DOM instead of JDOM, and that one works
perfectly! Needless to say that I wouldn't like the idea of going
back to DOM...

Regards,
Bernd

-- 
Bernd Eggink
Regionales Rechenzentrum der Uni Hamburg
Bernd.Eggink at rrz.uni-hamburg.de
http://www.rrz.uni-hamburg.de/RRZ/B.Eggink/



More information about the jdom-interest mailing list