You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by na...@locus.apache.org on 2000/07/09 04:21:21 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util RequestUtil.java

nacho       00/07/08 19:21:21

  Modified:    src/share/org/apache/tomcat/util RequestUtil.java
  Log:
  BUGFIX:
  
  Hashtable has no guarantees about the order in which elements
  are enumerated, and the Locale processing was reliting on that
  order from jdk 1.3.0 this order is not the same. In fact when the
  browser send  2 language codes in the "Accept-Language"
  Header jdk_1.3.0 inverts the order of the locale.
  
  Revision  Changes    Path
  1.15      +60 -59    jakarta-tomcat/src/share/org/apache/tomcat/util/RequestUtil.java
  
  Index: RequestUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/RequestUtil.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- RequestUtil.java	2000/06/23 02:16:30	1.14
  +++ RequestUtil.java	2000/07/09 02:21:21	1.15
  @@ -389,43 +389,46 @@
       }
   
       public static Locale getLocale(Request req) {
  -	String acceptLanguage = req.getHeader("Accept-Language");
  -	if( acceptLanguage == null ) return Locale.getDefault();
  +    	String acceptLanguage = req.getHeader("Accept-Language");
  +	    if( acceptLanguage == null ) return Locale.getDefault();
   
           Hashtable languages = new Hashtable();
  -	processAcceptLanguage(acceptLanguage, languages);
  -	if (languages.size() == 0)
  -	    return Locale.getDefault();
  -	Vector l = new Vector();
  -	extractLocales( languages, l);
  -	return (Locale)l.elementAt(0);
  +        Vector quality=new Vector();
  +        processAcceptLanguage(acceptLanguage, languages,quality);
  +
  +        if (languages.size() == 0) return Locale.getDefault();
  +
  +        Vector l = new Vector();
  +        extractLocales( languages,quality, l);
  +
  +        return (Locale)l.elementAt(0);
       }
  -    
  +
       public static Enumeration getLocales(HttpServletRequest req) {
  -	String acceptLanguage = req.getHeader("Accept-Language");
  -	// Short circuit with an empty enumeration if null header
  +	    String acceptLanguage = req.getHeader("Accept-Language");
  +    	// Short circuit with an empty enumeration if null header
           if (acceptLanguage == null) {
  -            Vector def = new Vector();
  -            def.addElement(Locale.getDefault());
  -            return def.elements();
  +            Vector v = new Vector();
  +            v.addElement(Locale.getDefault());
  +            return v.elements();
           }
   
           Hashtable languages = new Hashtable();
  -	processAcceptLanguage(acceptLanguage, languages );
  +        Vector quality=new Vector();
  +    	processAcceptLanguage(acceptLanguage, languages , quality);
   
           if (languages.size() == 0) {
               Vector v = new Vector();
  -
  -            v.addElement(org.apache.tomcat.core.Constants.LOCALE_DEFAULT);
  -            languages.put("1.0", v);
  +            v.addElement(Locale.getDefault());
  +            return v.elements();
           }
  -	Vector l = new Vector();
  -	extractLocales( languages, l);
  -	return l.elements();
  +    	Vector l = new Vector();
  +    	extractLocales( languages, quality , l);
  +    	return l.elements();
       }
   
       public static void processAcceptLanguage( String acceptLanguage,
  -					      Hashtable languages )
  +					      Hashtable languages, Vector q)
       {
           StringTokenizer languageTokenizer =
               new StringTokenizer(acceptLanguage, ",");
  @@ -438,59 +441,57 @@
               Double qValue = new Double(1);
   
               if (qValueIndex > -1 &&
  -                qValueIndex < qIndex &&
  -                qIndex < equalIndex) {
  -	        String qValueStr = language.substring(qValueIndex + 1);
  -
  +                    qValueIndex < qIndex &&
  +                    qIndex < equalIndex) {
  +    	        String qValueStr = language.substring(qValueIndex + 1);
                   language = language.substring(0, qValueIndex);
                   qValueStr = qValueStr.trim().toLowerCase();
                   qValueIndex = qValueStr.indexOf('=');
                   qValue = new Double(0);
  -
                   if (qValueStr.startsWith("q") &&
                       qValueIndex > -1) {
                       qValueStr = qValueStr.substring(qValueIndex + 1);
  -
                       try {
                           qValue = new Double(qValueStr.trim());
                       } catch (NumberFormatException nfe) {
                       }
                   }
               }
  -	    
  -	    // XXX
  -	    // may need to handle "*" at some point in time
  -
  -	    if (! language.equals("*")) {
  -	        String key = qValue.toString();
  -		Vector v = (Vector)((languages.containsKey(key)) ?
  -		    languages.get(key) : new Vector());
  -
  -		v.addElement(language);
  -		languages.put(key, v);
  -	    }
  +
  +            // XXX
  +            // may need to handle "*" at some point in time
  +
  +            if (! language.equals("*")) {
  +                String key = qValue.toString();
  +                Vector v;
  +                if (languages.containsKey(key)) {
  +                    v = (Vector)languages.get(key) ;
  +                } else {
  +                    v= new Vector();
  +                    q.addElement(qValue);
  +                }
  +                v.addElement(language);
  +                languages.put(key, v);
  +            }
           }
       }
   
  -    public static void extractLocales(Hashtable languages, Vector l)
  +    public static void extractLocales(Hashtable languages, Vector q,Vector l)
       {
  -        Enumeration e = languages.keys();
  -
  +        // XXX We will need to order by q value Vector in the Future ?
  +        Enumeration e = q.elements();
           while (e.hasMoreElements()) {
  -            String key = (String)e.nextElement();
  -            Vector v = (Vector)languages.get(key);
  +            Vector v =
  +                (Vector)languages.get(((Double)e.nextElement()).toString());
               Enumeration le = v.elements();
  -
               while (le.hasMoreElements()) {
  -	        String language = (String)le.nextElement();
  -		String country = "";
  -		int countryIndex = language.indexOf("-");
  -
  -		if (countryIndex > -1) {
  -		    country = language.substring(countryIndex + 1).trim();
  -		    language = language.substring(0, countryIndex).trim();
  -		}
  -
  +    	        String language = (String)le.nextElement();
  +	        	String country = "";
  +        		int countryIndex = language.indexOf("-");
  +                if (countryIndex > -1) {
  +                    country = language.substring(countryIndex + 1).trim();
  +                    language = language.substring(0, countryIndex).trim();
  +                }
                   l.addElement(new Locale(language, country));
               }
           }
  @@ -505,7 +506,7 @@
       // which was created for each HeaderField ).
       // This also avoid passing HttpHeaders - which was required to access
       // HttpHeaderFiled to access HttpDate to access the parsing code.
  -    
  +
       // we force our locale here as all http dates are in english
       private final static Locale loc = Locale.US;
   
  @@ -520,13 +521,13 @@
   
       // format for C asctime() date string -- "Sun Nov  6 08:49:37 1994"
       private final static String asctimePattern ="EEE MMM d HH:mm:ss yyyyy";
  -    
  +
       private final static SimpleDateFormat rfc1123Format =
   	new SimpleDateFormat(rfc1123Pattern, loc);
  -    
  +
       private final static SimpleDateFormat rfc1036Format =
   	new SimpleDateFormat(rfc1036Pattern, loc);
  -    
  +
       private final static SimpleDateFormat asctimeFormat =
   	new SimpleDateFormat(asctimePattern, loc);
   
  
  
  

Re: mod_jserv to be updated before 3.2 release ?

Posted by Jon Stevens <jo...@latchkey.com>.
on 7/9/2000 1:21 PM, "yhs@mimic.onesourcecorp.com"
<yh...@mimic.onesourcecorp.com> wrote:

> fixed some issues with load balancing and uneven distribution of servers
> as a result of those that are marked as down. thanks to Christos Zoulas (JSS).

_maybe_ with tomcat, but i doubt it.

> Fixed Bug Id: mod_jserv/6108 JservSessionId is not found in Query -> Load
> balancing fails when cookies are not used Thanks to Jerome Waibel. (JLR)

has nothing to do with tomcat.

> Fixed Bug Id: mod_jserv/6087 encoding should be ISO-8859-1 instead of
> ISO8859_1 Thanks to tim.landscheidt@gmx.de. (JSS)

has nothing to do with tomcat.

> Fixed Bug Id: mod_jserv/6099 Problem
> with serialization of sessions on class reload Thanks to Babak Kunze.
> (JSS)

has nothing to do with tomcat.

> Fixed possible problem with SessionID-uniqness on servers with heavy
> load (HZ)

tomcat uses a different method.

> fixed potential buffer overflow in jserv_balance. thanks to JSS for the
> find (JLR) 

this is already in tomcat.

-jon


mod_jserv to be updated before 3.2 release ?

Posted by yh...@mimic.onesourcecorp.com.
Hi guys,
just wondering if the updates and bug fixes to mod_jserv in the latest
version of Apache JServ are going to be rolled into tomcat ? 
These are the bug fixes i grabbed from the changelogs :

fixed some issues with load balancing and uneven distribution of servers
as a result of those that are marked as down. thanks to Christos Zoulas (JSS). 

Fixed Bug Id: mod_jserv/6108 JservSessionId is not found in Query -> Load
balancing fails when cookies are not used Thanks to Jerome Waibel. (JLR) 

Fixed Bug Id: mod_jserv/6087 encoding should be ISO-8859-1 instead of
ISO8859_1 Thanks to tim.landscheidt@gmx.de. (JSS)  

Fixed Bug Id: mod_jserv/6099 Problem
with serialization of sessions on class reload Thanks to Babak Kunze.
(JSS)
     
Fixed possible problem with SessionID-uniqness on servers with heavy
load (HZ)

fixed potential buffer overflow in jserv_balance. thanks to JSS for the
find (JLR) 

Thanks.
-Ys-
yhs@mimic.onesourcecorp.com