[jdom-interest] Re: can jdom be used inside a servlet?
jozart at csi.com
Tue Dec 12 02:14:41 PST 2000
> Can jdom be used inside a servlet?
This is an infrequent but recurring question.
You might be encountering the problem I describe below:
Many XML parsers *close* the input stream when they read eof (-1).
This is true of Xerces, which is JDOM's default parser. It is also true
Unfortunately, closing a SocketInputStream closes the underlying
SocketImpl, setting its file descriptor to null. Since your servlet
cannot write to a socket with a null file descriptor, your servlet will
not be able to respond.
One workaround is to read everything into a buffer before handing-off to
the JDOM builder.
byte buf = new byte[length];
InputStream in = new ByteArrayInputStream(buf);
Another workaround is to protect your socket's input stream with an
InputStream wrapper that doesn't close the underlying stream (override
the 'close' method). Or you can switch to a servlet container that
doesn't give your servlet direct access to the socket input stream (what
servlet container are you using?).
----- original message -----
From: "Yibing Li" <yli at mgfairfax.rr.com>
To: <jdom-interest at jdom.org>
Date: Wed, 6 Dec 2000 18:43:01 -0500
Subject: [jdom-interest] can jdom be used inside a servlet?
We are trying to use jdom in our xml API project to
receive a xml document and send back the response as
a xml document. This can be easily done by using a simple
servlet. But our developer find once jdom builder is instantiated, the
program stops there. Is this related to something special in the
threading model of xml parser?
More information about the jdom-interest