I am developing a web service with RESTEasy consuming xml files. These files are sent as an InputStream via HTTP. I wrote my custom MessageBodyReader for reading the incoming xml files which looks like:
@Override
public Document readFrom(
final Class<Document> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType,
final MultivaluedMap<String, String> httpHeaders, final InputStream entityStream
) throws IOException {
try {
DocParser parser = new DocParser();
return parser.parseStream(entityStream);
} catch (Exception e) {
throw new WebApplicationException("Document could not be deserialized.", e);
}
}
Please do not advise me to use the DocumentBuilder's parsing method as the xml is a namespaced one and there is an own implementation for parsing those files! The method
DocParser#parseStream(InputStream)
internally creates an unmarshaller from the JAXBContext and returns the unmarshalled object tree. Now I am also aware of the fact that there can be a BOM in front of the xml file which would cause the above exception BUT after looping through the document via this code
FileInputStream fis = new FileInputStream("c:/temp/myXmlFile.xml");
BufferedReader r = new BufferedReader(new InputStreamReader(fis,
"UTF8"));
for (String s = ""; (s = r.readLine()) != null;) {
System.out.println(s);
}
I didn't see any characters in front of
<?xml ... ?>
tag. Should InputStreams sent via HTTP be handled in some special way? Why am I getting this exception? How can I process the xml without getting the exception? Thank you!
No comments:
Post a Comment