tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jochen Gazda" <gaz...@web.de>
Subject Re: Occurence of Byte Order Mark (BOM) in responses varies between identical subsequent requests in Tomcat 6.0.35
Date Wed, 07 Dec 2011 10:08:34 GMT

-----Urspr√ľngliche Nachricht-----
Von: "Pid *" <pid@pidster.com>
Gesendet: Dec 7, 2011 10:26:00 AM
An: "Tomcat Users List" <users@tomcat.apache.org>
Betreff: Re: Occurence of Byte Order Mark (BOM) in responses varies between identical subsequent
requests in Tomcat 6.0.35

>On 7 Dec 2011, at 09:11, Jochen Gazda <gaz_da@web.de> wrote:
>
>> 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>");
>> }
>
>Are you also closing this writer, as below?
>
>
>p
>
>>
>> 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
>>

>Are you also closing this writer, as below?

No. Would it make a difference?

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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message