tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael-O <1983-01...@gmx.net>
Subject Aw: Re: ErrorReportValve's char encoding ignored
Date Wed, 15 May 2013 15:13:32 GMT
Hi Christopher,

> Von: "Christopher Schultz" <chris@christopherschultz.net>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
> 
> Micheal,
> 
> On 5/15/13 3:46 AM, Michael-O wrote:
> > I have modified the ErrorReportValve's messages outside of the 
> > one-byte range and the output got mangled. The response does not 
> > contain a char encoding anymore.
> 
> Can you be more specific? What exactly did you modify, and how did you
> modify it? What are the exact HTTP response headers that you get?

My modified valve is available here [1]. I did modify message layout and structure. The logic
of the valve remained the same. Important are lines 219 to 233 which are the same as in the
original ErrorReportValve.

Responded headers are:
Cache-Control	private
Content-Length	992
Content-Type	text/html
Date	Wed, 15 May 2013 14:53:15 GMT
Expires	Thu, 01 Jan 1970 01:00:00 CET
Server	Apache-Coyote/1.1

Content encoding is missing.
 
> > I know that the error valve does this:
> > 
> > response.setContentType("text/html"); 
> > response.setCharacterEncoding("utf-8");
> > 
> > but the setCharEnc method is completely ignored. Because the var 
> > usingWriter is already set to true. This happens in the 
> > ApplicationDispatcher#doForward line 393/394 when a servlet
> > performs a forward.
> 
> Looking at Tomcat 6.0.x/trunk line 393 is part of the cleanup code,
> and the response PrintWriter is immediately closed. That does not
> appear to have changed since 6.0.35. At this point, the request should
> be /over/.
> 
> What else is going on? Is any content being generated before the
> ErrorReportValve gets invoked? If the response has already been
> committed, then Tomcat can't re-write the response headers.

Nothing else is generated, this is my doGet:

protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

 HttpSession session = request.getSession(false);

  if (session == null) {
    response.sendError(HttpServletResponse.SC_FORBIDDEN, "Keine Session vorhanden");
    return;
  }
  ..
}

In my testcase, the session is null, thus the ErrorReportValve is triggered.
When I have debugged the issue, I saw that the response was not committed yet.
 
> > Though a response.getReporter() is used but this one is completely 
> > unaware of the char encoding.
> > 
> > I am on Tomcat 6.0.35.
> 
> Where is response.getReporter being called?

That is called in my valve in line 227, which has the same counterpart in the original valve.
The ReporterPrintWriter has beeen created exactly for the case that where the original writer
is not available anymore. It has already been cleaned up as you have mentioned before.

The setCharEnc is simply not propagated to the new one. The double-byte char \u2013 is displayed
as a question mark in Firefox. Fiddler shows a 3F which simply means that the writer did not
know how to map char to bytes.

Michael

[1] http://mo-tomcat-ext.sourceforge.net/xref/net/sf/michaelo/tomcat/extras/valves/EnhancedErrorReportValve.html

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


Mime
View raw message