remm        02/03/08 19:35:23

  Modified:    coyote/src/java/org/apache/coyote/tomcat4
                        CoyoteProcessor.java CoyoteRequest.java
  Log:
  - Port the locales parsing (which is as unoptimized as before, but is now run
    only when requested).
  - Miscanellous fixes.
  - Only one tester failure when using Coyote (there are a few others which appear to 
be tester bugs),
    on the WrappedForward05 (which is a servlet -> JSP -> servlet with a filter
    doing req/resp wrapping). I have no idea at this point why it fails, but it looks 
like
    the bytes output by the last servlet would be swallowed silently somewhere.
  - There are some connection handling problems with IE/Webfolders
    doing some PROPFINDs requests; otherwise, WebDAV and uploading appear to
    be working fine.
  
  Revision  Changes    Path
  1.10      +51 -4     
jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteProcessor.java
  
  Index: CoyoteProcessor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteProcessor.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- CoyoteProcessor.java      8 Mar 2002 23:50:31 -0000       1.9
  +++ CoyoteProcessor.java      9 Mar 2002 03:35:23 -0000       1.10
  @@ -1,6 +1,6 @@
  -/* * $Header: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteProcessor.java,v
 1.9 2002/03/08 23:50:31 remm Exp $
  - * $Revision: 1.9 $
  - * $Date: 2002/03/08 23:50:31 $
  +/* * $Header: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteProcessor.java,v
 1.10 2002/03/09 03:35:23 remm Exp $
  + * $Revision: 1.10 $
  + * $Date: 2002/03/09 03:35:23 $
    *
    * ====================================================================
    *
  @@ -112,7 +112,7 @@
    *
    * @author Craig R. McClanahan
    * @author Remy Maucherat
  - * @version $Revision: 1.9 $ $Date: 2002/03/08 23:50:31 $
  + * @version $Revision: 1.10 $ $Date: 2002/03/09 03:35:23 $
    */
   
   final class CoyoteProcessor
  @@ -305,6 +305,10 @@
               // Calling the container
               connector.getContainer().invoke(request, response);
               response.finishResponse();
  +        } catch (IOException e) {
  +            ;
  +        } catch (Throwable t) {
  +            log(sm.getString("coyoteProcessor.service"), t);
           } finally {
               // Recycle the wrapper request and response
               request.recycle();
  @@ -372,7 +376,16 @@
           request.setSecure(connector.getSecure());
           req.scheme().setString(connector.getScheme());
   
  +        request.setAuthorization
  +            (req.getHeader(Constants.AUTHORIZATION_HEADER));
  +
  +        if (proxyPort != 0)
  +            request.setServerPort(proxyPort);
  +        else
  +            request.setServerPort(serverPort);
  +
           parseHost();
  +        parseSessionId();
           parseCookies();
   
       }
  @@ -423,6 +436,38 @@
   
   
       /**
  +     * Parse session id in URL.
  +     */
  +    protected void parseSessionId() {
  +
  +        String uri = request.getRequestURI();
  +
  +        int semicolon = uri.indexOf(match);
  +        if (semicolon >= 0) {
  +            String rest = uri.substring(semicolon + match.length());
  +            int semicolon2 = rest.indexOf(';');
  +            if (semicolon2 >= 0) {
  +                request.setRequestedSessionId(rest.substring(0, semicolon2));
  +                rest = rest.substring(semicolon2);
  +            } else {
  +                request.setRequestedSessionId(rest);
  +                rest = "";
  +            }
  +            request.setRequestedSessionURL(true);
  +            uri = uri.substring(0, semicolon) + rest;
  +            if (debug >= 1)
  +                log(" Requested URL session id is " +
  +                    ((HttpServletRequest) request.getRequest())
  +                    .getRequestedSessionId());
  +        } else {
  +            request.setRequestedSessionId(null);
  +            request.setRequestedSessionURL(false);
  +        }
  +
  +    }
  +
  +
  +    /**
        * Parse cookies.
        * Note: Using Coyote native cookie parser to parse cookies would be faster
        * but a conversion to Catalina own cookies would then be needed, which 
  @@ -507,6 +552,8 @@
               input = socket.getInputStream();
               output = socket.getOutputStream();
               processor.process(input, output);
  +        } catch (IOException e) {
  +            ;
           } catch (Throwable t) {
               log(sm.getString("coyoteProcessor.process"), t);
           }
  
  
  
  1.7       +148 -26   
jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteRequest.java
  
  Index: CoyoteRequest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteRequest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CoyoteRequest.java        8 Mar 2002 23:50:31 -0000       1.6
  +++ CoyoteRequest.java        9 Mar 2002 03:35:23 -0000       1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteRequest.java,v
 1.6 2002/03/08 23:50:31 remm Exp $
  - * $Revision: 1.6 $
  - * $Date: 2002/03/08 23:50:31 $
  + * $Header: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteRequest.java,v
 1.7 2002/03/09 03:35:23 remm Exp $
  + * $Revision: 1.7 $
  + * $Date: 2002/03/09 03:35:23 $
    *
    * ====================================================================
    *
  @@ -83,6 +83,7 @@
   import java.util.Iterator;
   import java.util.Locale;
   import java.util.Map;
  +import java.util.TreeMap;
   
   import javax.servlet.RequestDispatcher;
   import javax.servlet.ServletContext;
  @@ -113,6 +114,7 @@
   import org.apache.catalina.util.ParameterMap;
   import org.apache.catalina.util.RequestUtil;
   import org.apache.catalina.util.StringManager;
  +import org.apache.catalina.util.StringParser;
   
   
   /**
  @@ -120,7 +122,7 @@
    *
    * @author Remy Maucherat
    * @author Craig R. McClanahan
  - * @version $Revision: 1.6 $ $Date: 2002/03/08 23:50:31 $
  + * @version $Revision: 1.7 $ $Date: 2002/03/09 03:35:23 $
    */
   
   public class CoyoteRequest
  @@ -275,12 +277,6 @@
   
   
       /**
  -     * Query string.
  -     */
  -    protected String queryString = null;
  -
  -
  -    /**
        * User principal.
        */
       protected Principal userPrincipal = null;
  @@ -299,12 +295,6 @@
   
   
       /**
  -     * Authorization parsed flag.
  -     */
  -    protected boolean authorizationParsed = false;
  -
  -
  -    /**
        * Secure flag.
        */
       protected boolean secure = false;
  @@ -353,6 +343,18 @@
       protected Socket socket = null;
   
   
  +    /**
  +     * Parse locales.
  +     */
  +    protected boolean localesParsed = false;
  +
  +
  +    /**
  +     * The string parser we will use for parsing request lines.
  +     */
  +    private StringParser parser = new StringParser();
  +
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -373,12 +375,14 @@
           contextPath = "";
           pathInfo = null;
           servletPath = null;
  -        queryString = null;
           reader = null;
  +        inputStream.recycle();
           userPrincipal = null;
           sessionParsed = false;
  +        authorization = null;
           requestParametersParsed = false;
  -        authorizationParsed = false;
  +        locales.clear();
  +        localesParsed = false;
           secure = false;
   
           attributes.clear();
  @@ -409,12 +413,6 @@
        */
       public String getAuthorization() {
   
  -        if (!authorizationParsed) {
  -            setAuthorization(coyoteRequest.getHeader
  -                             (Constants.AUTHORIZATION_HEADER));
  -            authorizationParsed = true;
  -        }
  -
           return (this.authorization);
   
       }
  @@ -828,6 +826,9 @@
        */
       public Locale getLocale() {
   
  +        if (!localesParsed)
  +            parseLocales();
  +
           if (locales.size() > 0) {
               return ((Locale) locales.get(0));
           } else {
  @@ -845,6 +846,9 @@
        */
       public Enumeration getLocales() {
   
  +        if (!localesParsed)
  +            parseLocales();
  +
           if (locales.size() > 0)
               return (new Enumerator(locales));
           ArrayList results = new ArrayList();
  @@ -955,6 +959,10 @@
           usingReader = true;
           if (reader == null) {
               String encoding = getCharacterEncoding();
  +            if (encoding == null) {
  +                encoding = 
  +                    org.apache.coyote.Constants.DEFAULT_CHARACTER_ENCODING;
  +            }
               InputStreamReader r = new InputStreamReader(inputStream, encoding);
               reader = new BufferedReader(r);
           }
  @@ -1498,7 +1506,7 @@
        * Return the query string associated with this request.
        */
       public String getQueryString() {
  -        return (queryString);
  +        return (coyoteRequest.queryString().toString());
       }
   
   
  @@ -1521,7 +1529,7 @@
        * Return the session identifier included in this request, if any.
        */
       public String getRequestedSessionId() {
  -        return null;
  +        return (requestedSessionId);
       }
   
   
  @@ -1850,6 +1858,120 @@
               offset += inputLen;
           } while ((len - offset) > 0);
           return len;
  +
  +    }
  +
  +
  +    /**
  +     * Parse request locales.
  +     */
  +    protected void parseLocales() {
  +
  +        localesParsed = true;
  +
  +        Enumeration values = getHeaders("accept-language");
  +
  +        while (values.hasMoreElements()) {
  +            String value = values.nextElement().toString();
  +            parseLocalesHeader(value);
  +        }
  +
  +    }
  +
  +
  +    /**
  +     * Parse accept-language header value.
  +     */
  +    protected void parseLocalesHeader(String value) {
  +
  +        // Store the accumulated languages that have been requested in
  +        // a local collection, sorted by the quality value (so we can
  +        // add Locales in descending order).  The values will be ArrayLists
  +        // containing the corresponding Locales to be added
  +        TreeMap locales = new TreeMap();
  +
  +        // Preprocess the value to remove all whitespace
  +        int white = value.indexOf(' ');
  +        if (white < 0)
  +            white = value.indexOf('\t');
  +        if (white >= 0) {
  +            StringBuffer sb = new StringBuffer();
  +            int len = value.length();
  +            for (int i = 0; i < len; i++) {
  +                char ch = value.charAt(i);
  +                if ((ch != ' ') && (ch != '\t'))
  +                    sb.append(ch);
  +            }
  +            value = sb.toString();
  +        }
  +
  +        // Process each comma-delimited language specification
  +        parser.setString(value);        // ASSERT: parser is available to us
  +        int length = parser.getLength();
  +        while (true) {
  +
  +            // Extract the next comma-delimited entry
  +            int start = parser.getIndex();
  +            if (start >= length)
  +                break;
  +            int end = parser.findChar(',');
  +            String entry = parser.extract(start, end).trim();
  +            parser.advance();   // For the following entry
  +
  +            // Extract the quality factor for this entry
  +            double quality = 1.0;
  +            int semi = entry.indexOf(";q=");
  +            if (semi >= 0) {
  +                try {
  +                    quality = Double.parseDouble(entry.substring(semi + 3));
  +                } catch (NumberFormatException e) {
  +                    quality = 0.0;
  +                }
  +                entry = entry.substring(0, semi);
  +            }
  +
  +            // Skip entries we are not going to keep track of
  +            if (quality < 0.00005)
  +                continue;       // Zero (or effectively zero) quality factors
  +            if ("*".equals(entry))
  +                continue;       // FIXME - "*" entries are not handled
  +
  +            // Extract the language and country for this entry
  +            String language = null;
  +            String country = null;
  +            int dash = entry.indexOf('-');
  +            if (dash < 0) {
  +                language = entry;
  +                country = "";
  +            } else {
  +                language = entry.substring(0, dash);
  +                country = entry.substring(dash + 1);
  +            }
  +
  +            // Add a new Locale to the list of Locales for this quality level
  +            Locale locale = new Locale(language, country);
  +            Double key = new Double(-quality);  // Reverse the order
  +            ArrayList values = (ArrayList) locales.get(key);
  +            if (values == null) {
  +                values = new ArrayList();
  +                locales.put(key, values);
  +            }
  +            values.add(locale);
  +
  +        }
  +
  +        // Process the quality values in highest->lowest order (due to
  +        // negating the Double value when creating the key)
  +        Iterator keys = locales.keySet().iterator();
  +        while (keys.hasNext()) {
  +            Double key = (Double) keys.next();
  +            ArrayList list = (ArrayList) locales.get(key);
  +            Iterator values = list.iterator();
  +            while (values.hasNext()) {
  +                Locale locale = (Locale) values.next();
  +                addLocale(locale);
  +            }
  +        }
   
       }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to