views:

117

answers:

3

Hello,

i'm writing a servlet that receives a xml file, gives it to another class and gives a html file with some comments back to the client. I'm getting the input-xml with something like:

input = request.getInputStream();

but this input is a ServletInputStream and the other class(for the comments) needs a FileInputStream.

If i give the XMLEventReader(in the other class) the ServletInputStream, i get a parsing error:

ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.

And i think this is because of the servletinputstream instead of the fileinputstream.

Greetings i hope somebody is able to help me:)

+3  A: 

I think it's unlikely that the latter problem is due to it being a ServletInputStream. The parser shouldn't care about the source of the data.

I think it's rather more likely that the data in the input stream is incorrect.

Your class which currently requires FileInputStream should be refactored to work with InputStream if at all possible... otherwise you'll have to write the data to an actual file first, which is obviously not ideal.

Jon Skeet
okay, i changed the inputs in "InputStream" but same problemIs there a possibility to convert the ServletInputStream into a String that i can look up if there is a small difference between it and the original xml file?
CaptnLenz
Use `InputStreamReader`. Don't forget to take character encoding into account. Further I think it's high time to get yourself through the [Java IO tutorial](http://java.sun.com/docs/books/tutorial/essential/io/). It explains the essentials you need to know.
BalusC
@CaptnLenz: I suggest you just write the data to disk, and look at it there. Open a `FileOutputStream`, and just read a block at a time from the input stream, writing it to the output stream. Then you can look at the file.
Jon Skeet
A: 

you should read the data from the ServletInputStream, and dump it into a FileOutputStream. this way you can look at the data that is being sent, then test that data separately using FileInputStream with the class you described that needs it. my guess is that the same thing will happen as is happening now since like the previous poster suggested, the data is probably in the wrong format.

aepurniet
If i start the "comment-class" with something like input = FileInputStream("local path of the xml file") everything works, but if i give it the same xml via the servlet(servletinputstream) to this class, i get the parsing error. So the xml-file should be correct.Maybe it help that the parsing error raises on the second node. the first `<?xml version="1.0" encoding='UTF-8' standalone='no'?>` works obviously
CaptnLenz
A: 

Okay, i am now a bit smarter:) The problem is: In the ServletInputStream is at the beginning(and one line at the end) some header information (as content-type, etc..). Is there a smart solution for cutting this information?

greetings

CaptnLenz
A new question should go in a new question, not a new **answer**. This isn't a forum. You should delete this "answer", else it might be downvoted. Your initial question has already been answered. Don't forget to mark the *actual* answer which *actually* helped in solving the problem to accepted by clicking the checkmark on the left hand side. See also http://stackoverflow.com/faq.
BalusC