Gentlemen,
 
The following occurs on Tomcat 6.0.20 or 6.0.35 on 64bit Linux 
$ java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)
 
It happends both with and without apache httpd frontend.
 
I have a very simple servlet doing basically the following:
 
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/xml");
response.setCharacterEncoding("utf-16");
PrintWriter w = response.getWriter();
w.write("<?xml version=\"1.0\" encoding=\""+ response.getCharacterEncoding() 
+"\"?><root></root>");
}
 
The first response after the start of tomcat contains the fe ff BOM
<= Recv data, 8850 bytes (0x2292)
0000: 32 30 30 30 0d 0a fe ff 00 3c 00 3f 00 78 00 6d 2000.....<.?.x.m
0010: 00 6c 00 20 00 76 00 65 00 72 00 73 00 69 00 6f .l. .v.e.r.s.i.o
 
But there is no BOM in an indentical subsequent request
<= Recv data, 8850 bytes (0x2292)
0000: 32 30 30 30 0d 0a 00 3c 00 3f 00 78 00 6d 00 6c 2000...<.?.x.m.l
0010: 00 20 00 76 00 65 00 72 00 73 00 69 00 6f 00 6e . .v.e.r.s.i.o.n
 
The more exact observation of me is that there is no BOM in a majority of 
subsequent identical requests. The BOM comes sometimes.
 
I guess there is some writer, buffer or encoder not recycled properly.
 
May I file a bug for this?
 
Workaround:
BOM seems to be always there if the java.io.OutputStreamWriter is used instead 
of tomcat's response.getWriter():
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/xml");
response.setCharacterEncoding("utf-16");
ServletOutputStream out = response.getOutputStream();
Writer w = null;
try {
w = new OutputStreamWriter(out, response.getCharacterEncoding()); 
w.write("<?xml version=\"1.0\" encoding=\""+ response.getCharacterEncoding() 
+"\"?><root></root>");
} finally {
if (w != null) {
try {
w.close();
} catch (Exception e) {
log("Could not close writer", e);
}
}
}
}
 
Best,

Gazda
___________________________________________________________
SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to