[jdom-interest] SAXBuilder.build() second try

Joseph Bowbeer jozart at csi.com
Fri Jul 20 05:51:59 PDT 2001


If your problem is that closing the input stream is closing the socket, then
your code isn't going to fix this: BufferedReader.close() closes the
unbuffered stream, putting you right back where you started.

Also, it doesn't look like you're making use of the content-length provided.

The following has always worked for me:

    byte[] buf = new byte[request.getContentLength()];
    new DataInputStream(request.getInputStream()).readFully(buf);
    InputStream in = new ByteArrayInputStream(buf);
    Document doc = new SAXBuilder().build(in);


----- original message -----
From: John Muhlestein jmuhlestein at i-link.net
Date: Thu, 19 Jul 2001 16:32:34 -0600

I have gone through and done what I thought would be a similar wrapper to
what is described in the FAQ for sockets to get my servlet to work and I
still seem to be hanging on the build process.

Here is the code in my servlet that I try to build my document with.
<code>
    BufferedReader br = request.getReader();
    char[] xml = new char[8000];
    br.read(xml);
    br.close();
    CharArrayReader reader = new CharArrayReader(xml);

    SAXBuilder builder = new SAXBuilder(true);
    Document doc = builder.build(reader);
</code>

If I view the value of the array "xml" it contains my entire document that I
am POSTing to the servlet.  I am including the .java file that represents
the class I use to send data to the servlet.

I would think passing xml to a servlet would be pretty common and I'm just
missing something simple.  Just for the record again, I am using jdom-b7
from cvs 3 days ago and Tomcat 3.2 as my servlet container with my
application built into it's own context.

thanks again,

John




More information about the jdom-interest mailing list