Bug 55399 - Request English but Response Spanish Language (Default Locale)
Request English but Response Spanish Language (Default Locale)
Status: RESOLVED FIXED
Product: Tomcat 7
Classification: Unclassified
Component: Catalina
unspecified
All All
: P2 normal (vote)
: ---
Assigned To: Tomcat Developers Mailing List
:
: 56374 (view as bug list)
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2013-08-10 17:50 UTC by Guillermo Grandes
Modified: 2014-04-10 09:08 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Guillermo Grandes 2013-08-10 17:50:55 UTC
== Server: Windows, Language: es_ES
== Client: Linux, Language: en_US

== Request:

POST /xxxxxx HTTP/1.1
Host: x.x.x.x:8080
Accept: */*
Accept-Language: en
Content-Length: 0
Content-Type: application/x-www-form-urlencoded

== Response:

HTTP/1.1 400 Petición incorrecta
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=ISO-8859-1
Content-Length: 1030
Date: Sat, 10 Aug 2013 17:25:17 GMT
Connection: close

...cut...

---

HTTP Response "Petición incorrecta" must be in English. Right?

I tried to do response.setLocale() workarround in the Servlet but neither works:

---
protected void doPost(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
// ...
	response.setLocale(Locale.ENGLISH); // Locale.US neither
// ...
	response.sendError(HttpServletResponse.SC_BAD_REQUEST, "BAD REQUEST");
}
---

HttpServletResponse.setLocale() don't honors?
Comment 1 Christopher Schultz 2013-08-11 01:01:58 UTC
What version of Tomcat?

Can you echo these items back to the client and post the output:

protected void doPost(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
//  ...
    ServletWriter out = response.getWriter();
    out.println("request locale=" + request.getLocale());
    out.println("server locale=" + Locale.getDefault());
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, "BAD REQUEST");
}
Comment 2 Guillermo Grandes 2013-08-11 21:35:11 UTC
Tested on tomcat-7.0.42

ServletWriter.println() don't work as expect (response.sendError clear the response buffer), but changing ServletWriter to System.out output is:

protected void doPost(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
	// ...
	System.out.println("request locale=" + request.getLocale());
	System.out.println("server locale=" + Locale.getDefault());
	response.sendError(HttpServletResponse.SC_BAD_REQUEST, "BAD REQUEST");
}

--- Eclipse console ---
request locale=en
server locale=es_ES
---

# Request:
curl -i -H "Accept-Language: en" -d "" "http://x.x.x.x:8080/LocaleTest"
---
HTTP/1.1 400 Petición incorrecta
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=ISO-8859-1
Content-Length: 1010
Date: Sun, 11 Aug 2013 21:29:02 GMT
Connection: close

<html><head><title>Apache Tomcat/7.0.42 - Informe de Error</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>Estado HTTP 400 - BAD REQUEST</h1><HR size="1" noshade="noshade"><p><b>type</b> Informe de estado</p><p><b>mensaje</b> <u>BAD REQUEST</u></p><p><b>descripción</b> <u>El requerimiento enviado por el cliente era sintácticamente incorrecto.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.42</h3></body></html>
---
Comment 3 Christopher Schultz 2013-08-11 23:25:02 UTC
That's certainly odd. How about this:

	System.out.println("current stack:");
        new Throwable("Stack Trace").printStackTrace();
Comment 4 Guillermo Grandes 2013-08-13 00:14:50 UTC
java.lang.Throwable: Stack Trace
	at org.test.servlet.LocaleTest.doPost(LocaleTest.java:138)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1686)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
	at java.lang.Thread.run(Thread.java:662)
Comment 5 Mark Thomas 2013-08-15 13:51:00 UTC
This report doesn't surprise me at all.

The manager application had a similar issue.

I'll look at using a similar approach as used for the manager application for the error pages.
Comment 6 Mark Thomas 2013-08-15 19:22:47 UTC
The error pages were simple to fix but fixing the HTTP response status line is going to be more invasive. That part may end up being Tomcat 8 only because of the internal changes required.
Comment 7 Mark Thomas 2013-08-15 21:14:55 UTC
This has been fixed in trunk and 7.0.x and will be included in 7.0.43 onwards.

Error pages now use the Accept-Language header.

All responses use the Locale set on the response.

I considered parsing the Accept-Language header on every request and using that to set the locale on every response but decided not to on performance grounds (no hard numbers on this so if someone shows the performance impact is negligible then it could get added). Users that want this can easily write a filter to do so.
Comment 8 Guillermo Grandes 2013-08-16 22:27:26 UTC
(In reply to Mark Thomas from comment #6)
> The error pages were simple to fix but fixing the HTTP response status line
> is going to be more invasive. That part may end up being Tomcat 8 only
> because of the internal changes required.

In that case, perhaps the logical would respond in English (ubiquitous) by default, and set locale when requested... right?
Comment 9 Konstantin Kolinko 2014-04-10 09:08:20 UTC
*** Bug 56374 has been marked as a duplicate of this bug. ***