khammond    01/10/07 21:14:24

  Modified:    src/org/apache/jmeter/protocol/http/control
                        CookieManager.java
  Log:
  Fixed timezone bug. The cookie spec states that the cookie is in GMT.
  
  Revision  Changes    Path
  1.14      +60 -5     
jakarta-jmeter/src/org/apache/jmeter/protocol/http/control/CookieManager.java
  
  Index: CookieManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/org/apache/jmeter/protocol/http/control/CookieManager.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- CookieManager.java        2001/10/03 02:22:15     1.13
  +++ CookieManager.java        2001/10/08 04:14:23     1.14
  @@ -73,7 +73,7 @@
    * pass cookies along with a request.
    *
    * @author  <a href="mailto:[EMAIL PROTECTED]";>Sean Dowd</a>
  - * @version $Revision: 1.13 $ $Date: 2001/10/03 02:22:15 $
  + * @version $Revision: 1.14 $ $Date: 2001/10/08 04:14:23 $
    */
   public class CookieManager implements ConfigElement,JMeterComponentModel,Saveable,
                Serializable
  @@ -93,6 +93,14 @@
   
         private static List addableList = new LinkedList();
   
  +     static
  +     {
  +             // The cookie specification requires that the timezone be GMT.
  +             // See 
http://developer.netscape.com/docs/manuals/communicator/jsguide4/cookies.htm
  +             // See http://www.cookiecentral.com/faq/
  +             dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
  +     }
  +
         public CookieManager () {
         }
   
  @@ -187,10 +195,12 @@
                return columnNames[column];
        }
   
  -     public Class getColumnClass(int column)
  -     {
  -             return columnNames[column].getClass();
  -     }
  +     // Incorrect method. Always returns String. I changed CookiePanel code to 
perform
  +     // this lookup.
  +     //public Class getColumnClass(int column)
  +     //{
  +     //      return columnNames[column].getClass();
  +     //}
   
        public Cookie getCookie(int row)
        {
  @@ -250,6 +260,12 @@
         public void add(Cookie c) {
                  cookies.add(c);
         }
  +
  +      /** add an empty cookie */
  +      public void add() {
  +             cookies.add(new Cookie());
  +      }
  +
         /** remove a cookie */
         public void remove(int index) {
                  cookies.remove(index);
  @@ -265,6 +281,34 @@
                 return (Cookie) cookies.get(i);
        }
   
  +     public String convertLongToDateFormatStr(long dateLong)
  +     {
  +             return dateFormat.format(new Date(dateLong));
  +     }
  +
  +     public long convertDateFormatStrToLong(String dateStr)
  +     {
  +             long time = 0;
  +
  +             try
  +             {
  +                     Date date = dateFormat.parse(dateStr); 
  +                     time = date.getTime();
  +             }
  +             catch (ParseException e)
  +             {
  +                     // ERROR!!!
  +                     // Later, display error dialog?  For now, we have
  +                     // to specify a number that can be converted to
  +                     // a Date. So, I chose 0. The Date will appear as
  +                     // the beginning of the Epoch (Jan 1, 1970 00:00:00 GMT)
  +                     time = 0;
  +                     System.out.println("DateFormat.ParseException: " + 
e.getMessage());
  +             }
  +
  +             return time;
  +     }
  +
        public String getCookieHeaderForURL(URL url) {
        if (! url.getProtocol().toUpperCase().trim().equals("HTTP")
                 &&
  @@ -291,6 +335,7 @@
         }
   
         public void addCookieFromHeader(String cookieHeader, URL url) {
  +             //System.out.println("inside addCookieFromHeader: " + cookieHeader + " 
" + url);
                  StringTokenizer st = new StringTokenizer(cookieHeader, ";");
                  String nvp;
   
  @@ -302,6 +347,11 @@
                  String domain = url.getHost();
                  String path = url.getFile();
   
  +             //System.out.println(name);
  +             //System.out.println(value);
  +             //System.out.println(domain);
  +             //System.out.println(path);
  +
                  Cookie newCookie = new Cookie(name, value, domain, path, false,
                                         System.currentTimeMillis() + 1000 * 60 * 60 * 
24);
                  // check the rest of the headers
  @@ -319,6 +369,8 @@
                                                  String expires = 
nvp.substring(index+1);
                                                  Date date = 
dateFormat.parse(expires);
                                                  newCookie.setExpires(date.getTime());
  +                                             //System.out.println("set expires to " 
+ date.getTime());
  +                                             //System.out.println("current time: " 
+ (new Date()).getTime());
                                         } catch (ParseException pe) {}
                                } else if (key.equalsIgnoreCase("domain")) {
                                         newCookie.setDomain(nvp.substring(index+1));
  @@ -337,17 +389,20 @@
                                if (cookie.getPath().equals(newCookie.getPath()) &&
                                                  
cookie.getDomain().equals(newCookie.getDomain()) &&
                                                  
cookie.getName().equals(newCookie.getName())) {
  +                                     //System.out.println("remove cookie #" + i);
                                         removeIndices.addElement(new Integer(i));
                                }
                  }
   
                  for (Enumeration e = removeIndices.elements(); e.hasMoreElements();) 
{
                                index = ((Integer) e.nextElement()).intValue();
  +                             //System.out.println("remove cookie index " + index);
                                cookies.remove(index);
                  }
   
                  if (newCookie.getExpires() >= System.currentTimeMillis())
                  {
  +                     //System.out.println("cookie expiration is future so add it");
                                cookies.add(newCookie);
                  }
         }
  
  
  

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

Reply via email to