Author: markt Date: Thu Aug 15 20:51:38 2013 New Revision: 1514485 URL: http://svn.apache.org/r1514485 Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=55399 Have the message in the response line use the locale set for the response.
Modified: tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java tomcat/trunk/java/org/apache/coyote/http11/AbstractOutputBuffer.java tomcat/trunk/java/org/apache/coyote/spdy/SpdyProcessor.java tomcat/trunk/java/org/apache/tomcat/util/http/HttpMessages.java Modified: tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java?rev=1514485&r1=1514484&r2=1514485&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java (original) +++ tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java Thu Aug 15 20:51:38 2013 @@ -947,7 +947,8 @@ public abstract class AbstractAjpProcess message = response.getMessage(); } if (message == null){ - message = HttpMessages.getMessage(response.getStatus()); + message = HttpMessages.getInstance( + response.getLocale()).getMessage(response.getStatus()); } if (message == null) { // mod_jk + httpd 2.x fails with a null status message - bug 45026 Modified: tomcat/trunk/java/org/apache/coyote/http11/AbstractOutputBuffer.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/AbstractOutputBuffer.java?rev=1514485&r1=1514484&r2=1514485&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/AbstractOutputBuffer.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/AbstractOutputBuffer.java Thu Aug 15 20:51:38 2013 @@ -133,7 +133,7 @@ public abstract class AbstractOutputBuff finished = false; // Cause loading of HttpMessages - HttpMessages.getMessage(200); + HttpMessages.getInstance(response.getLocale()).getMessage(200); } @@ -427,7 +427,8 @@ public abstract class AbstractOutputBuff message = response.getMessage(); } if (message == null) { - write(HttpMessages.getMessage(status)); + write(HttpMessages.getInstance( + response.getLocale()).getMessage(status)); } else { write(message); } Modified: tomcat/trunk/java/org/apache/coyote/spdy/SpdyProcessor.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/spdy/SpdyProcessor.java?rev=1514485&r1=1514484&r2=1514485&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/spdy/SpdyProcessor.java (original) +++ tomcat/trunk/java/org/apache/coyote/spdy/SpdyProcessor.java Thu Aug 15 20:51:38 2013 @@ -440,7 +440,8 @@ public class SpdyProcessor extends Abstr message = response.getMessage(); } if (message == null) { - message = HttpMessages.getMessage(response.getStatus()); + message = HttpMessages.getInstance( + response.getLocale()).getMessage(response.getStatus()); } if (message == null) { // mod_jk + httpd 2.x fails with a null status message - bug Modified: tomcat/trunk/java/org/apache/tomcat/util/http/HttpMessages.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/HttpMessages.java?rev=1514485&r1=1514484&r2=1514485&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/http/HttpMessages.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/http/HttpMessages.java Thu Aug 15 20:51:38 2013 @@ -16,6 +16,10 @@ */ package org.apache.tomcat.util.http; +import java.util.Locale; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + import org.apache.tomcat.util.res.StringManager; /** @@ -28,14 +32,24 @@ import org.apache.tomcat.util.res.String * @author cos...@eng.sun.com */ public class HttpMessages { + + private static final Map<Locale,HttpMessages> instances = + new ConcurrentHashMap<>(); + + private static final HttpMessages DEFAULT = getInstance(Locale.getDefault()); + // XXX move message resources in this package - private static final StringManager sm = - StringManager.getManager("org.apache.tomcat.util.http.res"); + private final StringManager sm; + + private String st_200 = null; + private String st_302 = null; + private String st_400 = null; + private String st_404 = null; + + private HttpMessages(StringManager sm) { + this.sm = sm; + } - private static String st_200=null; - private static String st_302=null; - private static String st_400=null; - private static String st_404=null; /** Get the status string associated with a status code. * No I18N - return the messages defined in the HTTP spec. @@ -45,36 +59,53 @@ public class HttpMessages { * Common messages are cached. * */ - public static String getMessage( int status ) { + public String getMessage(int status) { // method from Response. // Does HTTP requires/allow international messages or // are pre-defined? The user doesn't see them most of the time switch( status ) { case 200: - if( st_200==null ) { - st_200=sm.getString( "sc.200"); + if(st_200 == null ) { + st_200 = sm.getString("sc.200"); } return st_200; case 302: - if( st_302==null ) { - st_302=sm.getString( "sc.302"); + if(st_302 == null ) { + st_302 = sm.getString("sc.302"); } return st_302; case 400: - if( st_400==null ) { - st_400=sm.getString( "sc.400"); + if(st_400 == null ) { + st_400 = sm.getString("sc.400"); } return st_400; case 404: - if( st_404==null ) { - st_404=sm.getString( "sc.404"); + if(st_404 == null ) { + st_404 = sm.getString("sc.404"); } return st_404; } return sm.getString("sc."+ status); } + + public static HttpMessages getInstance(Locale locale) { + HttpMessages result = instances.get(locale); + if (result == null) { + StringManager sm = StringManager.getManager( + "org.apache.tomcat.util.http.res", locale); + if (Locale.getDefault().equals(sm.getLocale())) { + result = DEFAULT; + } else { + result = new HttpMessages(sm); + } + instances.put(locale, result); + } + return result; + } + + /** * Filter the specified message string for characters that are sensitive * in HTML. This avoids potential attacks caused by including JavaScript --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org