Question

This question already has an answer here:

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:)

Was it helpful?

Solution

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.

OTHER TIPS

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top