remm        2004/04/14 15:20:47

  Modified:    catalina/src/share/org/apache/coyote/tomcat5
                        CoyoteAdapter.java CoyoteRequest.java
  Log:
  - Optimization: delay parsing of the cookies. Since most request will contain a 
session
    cookie, and a lot of servlets won't call getCookies, it is useful to save some 
object
    allocations.
  - This seem to work for me (sessions still work, and the cookies example works as 
well),
    but this is regression friendly.
  
  Revision  Changes    Path
  1.23      +2 -35     
jakarta-tomcat-catalina/catalina/src/share/org/apache/coyote/tomcat5/CoyoteAdapter.java
  
  Index: CoyoteAdapter.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/coyote/tomcat5/CoyoteAdapter.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- CoyoteAdapter.java        6 Apr 2004 00:55:07 -0000       1.22
  +++ CoyoteAdapter.java        14 Apr 2004 22:20:47 -0000      1.23
  @@ -288,8 +288,6 @@
               return false;
           }
   
  -        // Parse cookies
  -        parseCookies(req, request);
           return true;
       }
   
  @@ -348,22 +346,12 @@
               request.setRequestedSessionURL(false);
           }
   
  -    }
  -
  -
  -    /**
  -     * Parse cookies.
  -     */
  -    protected void parseCookies(Request req, CoyoteRequest request) {
  -
  +        // Parse session id from cookies
           Cookies serverCookies = req.getCookies();
           int count = serverCookies.getCookieCount();
           if (count <= 0)
               return;
   
  -        Cookie[] cookies = new Cookie[count];
  -
  -        int idx=0;
           for (int i = 0; i < count; i++) {
               ServerCookie scookie = serverCookies.getCookie(i);
               if (scookie.getName().equals(Globals.SESSION_COOKIE_NAME)) {
  @@ -386,28 +374,7 @@
                       }
                   }
               }
  -            try {
  -                Cookie cookie = new Cookie(scookie.getName().toString(),
  -                                           scookie.getValue().toString());
  -                cookie.setPath(scookie.getPath().toString());
  -                cookie.setVersion(scookie.getVersion());
  -                String domain = scookie.getDomain().toString();
  -                if (domain != null) {
  -                    cookie.setDomain(scookie.getDomain().toString());
  -                }
  -                cookies[idx++] = cookie;
  -            } catch(IllegalArgumentException e) {
  -                log.info("Bad Cookie: Name: " + scookie.getName() 
  -                         + " Value: " + scookie.getValue());
  -            }
           }
  -        if( idx < count ) {
  -            Cookie [] ncookies = new Cookie[idx];
  -            System.arraycopy(cookies, 0, ncookies, 0, idx);
  -            cookies = ncookies;
  -        }
  -
  -        request.setCookies(cookies);
   
       }
   
  
  
  
  1.35      +53 -1     
jakarta-tomcat-catalina/catalina/src/share/org/apache/coyote/tomcat5/CoyoteRequest.java
  
  Index: CoyoteRequest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/coyote/tomcat5/CoyoteRequest.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- CoyoteRequest.java        14 Apr 2004 00:14:22 -0000      1.34
  +++ CoyoteRequest.java        14 Apr 2004 22:20:47 -0000      1.35
  @@ -50,8 +50,10 @@
   
   import org.apache.tomcat.util.buf.B2CConverter;
   import org.apache.tomcat.util.buf.MessageBytes;
  +import org.apache.tomcat.util.http.Cookies;
   import org.apache.tomcat.util.http.FastHttpDateFormat;
   import org.apache.tomcat.util.http.Parameters;
  +import org.apache.tomcat.util.http.ServerCookie;
   import org.apache.tomcat.util.http.mapper.MappingData;
   
   import org.apache.coyote.ActionCode;
  @@ -246,6 +248,12 @@
   
   
       /**
  +     * Cookies parsed flag.
  +     */
  +    protected boolean cookiesParsed = false;
  +
  +
  +    /**
        * Secure flag.
        */
       protected boolean secure = false;
  @@ -378,6 +386,7 @@
           subject = null;
           sessionParsed = false;
           requestParametersParsed = false;
  +        cookiesParsed = false;
           locales.clear();
           localesParsed = false;
           secure = false;
  @@ -1835,6 +1844,9 @@
        */
       public Cookie[] getCookies() {
   
  +        if (!cookiesParsed)
  +            parseCookies();
  +
           return cookies;
   
       }
  @@ -2296,6 +2308,46 @@
           if (isSecure()) {
               cookie.setSecure(true);
           }
  +    }
  +
  +    /**
  +     * Parse cookies.
  +     */
  +    protected void parseCookies() {
  +
  +        cookiesParsed = true;
  +
  +        Cookies serverCookies = coyoteRequest.getCookies();
  +        int count = serverCookies.getCookieCount();
  +        if (count <= 0)
  +            return;
  +
  +        cookies = new Cookie[count];
  +
  +        int idx=0;
  +        for (int i = 0; i < count; i++) {
  +            ServerCookie scookie = serverCookies.getCookie(i);
  +            try {
  +                Cookie cookie = new Cookie(scookie.getName().toString(),
  +                                           scookie.getValue().toString());
  +                cookie.setPath(scookie.getPath().toString());
  +                cookie.setVersion(scookie.getVersion());
  +                String domain = scookie.getDomain().toString();
  +                if (domain != null) {
  +                    cookie.setDomain(scookie.getDomain().toString());
  +                }
  +                cookies[idx++] = cookie;
  +            } catch(IllegalArgumentException e) {
  +                log.info("Bad Cookie: Name: " + scookie.getName() 
  +                         + " Value: " + scookie.getValue());
  +            }
  +        }
  +        if( idx < count ) {
  +            Cookie [] ncookies = new Cookie[idx];
  +            System.arraycopy(cookies, 0, ncookies, 0, idx);
  +            cookies = ncookies;
  +        }
  +
       }
   
       /**
  
  
  

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

Reply via email to