The environment is a client - server application, where the client
reads an UTF-8 encoded XML file (with cyrillic characters e.g.) which
is then send to the server, where it is parsed in 2 different ways -
first using a normal SaxParser then via Castor (which is using the
_same_ parser library)
relevant Libs: xercesImpl 2.9.0, castor 0.9.5
The client-XML file is UTF-8 with BOM (hex: EB BB BF).
The client sends this file via a commons-httpclient POST call to the
server using the correct content-type.
I ensure on the server side, that the file is received correcly, i can
read the cyrrilic characters in the logfile after doing the following
in the servlet:
the following is obviously pseudoCode:
InputStream in = request.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte buffer = new byte;
byte xml = baos.toByteArray();
String s = new String(xml, "UTF8"); --> string is correct, contains
--- until here, everything is fine.
--- Now i have to parse the xml to find a node-attribute and decide
upon the value into which
--- castor classes i have to unmarshal the XML.
--- To be able to call castor, i need a second input stream which
castor will be using.
--- therefore i copy the byte and create a second stream.
--- (the files are really small, therefore i dont expect memory
byte xmlCastor = new byte[xml.length];
System.arraycopy(xml, 0, xmlCastor, 0, xml.length);
ByteArrayInputStream bais = new ByteArrayInputStream(xml);
ByteArrayInputStream baisCastor = new
-- i can verify in the logfile, that these 2 byte arrays contain the
same cyrillic characters.
-- now i call the SaxParser with the first stream, and i receive the
-- then i pass the second stream to castor ... and bummer ...
Caused by: org.xml.sax.SAXException: Parsing Error: Content is not
allowed in prolob.
-- that is because of the byte-order mark, the Parser does not like
-- 2 identical streams (as far as i can tell) called by the same
parser ... one runs into an exception,
-- the second does not
-- I have _exactly one_ Parser in my Tomcat in WEB-INF/Lib, and that
-- Is it somehow possible that Tomcat provides a different version ? I
cannot verify how Castor is
-- choosing his XML parser, but i do it the following way: