[jdom-interest] SAXBuilder.build() weirdness
jozart at csi.com
Wed Jul 18 22:38:39 PDT 2001
John Muhlestein writes:
> If I pass the xml document (via POST) to a servlet which calls the program
> it dies at the SAXBuilder.build(BufferedReader) call. The interesting
> is that the method just hangs.
Did you see "Why does passing a document through a socket sometimes hang the
parser?" in the FAQ?
To paraphrase, many if not most XML parsers close the input stream when they
see EOF. In many socket implementations, this will effectively close the
socket, with the result that your service won't be able to open an output
stream and send back a response. (It just hangs..)
To work around this particular problem, protect your socket's input stream
with an InputStream wrapper that doesn't close the underlying stream
(override the close method), or read everything into a buffer before handing
off to the JDOM builder:
byte buf = new byte[length]; // from content-length
InputStream in = new ByteArrayInputStream(buf);
What servlet engine are you using? I think some servlet engines already
shield the socket from operations on the input stream.
More information about the jdom-interest