== 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?
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"); }
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> ---
That's certainly odd. How about this: System.out.println("current stack:"); new Throwable("Stack Trace").printStackTrace();
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)
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.
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.
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.
(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?
*** Bug 56374 has been marked as a duplicate of this bug. ***