jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rundle Timothy" <timothy.run...@volvo.com>
Subject Cookie Expiration Issue
Date Tue, 08 Jun 2004 14:16:55 GMT

  I have a script where a couple is issued with the first HttpSampler
and expired in the second HttpSampler handler, but jMeter continues to
send the cookie with an empty value for a subsequent HttpSamplers.  I
think there is an issue with the addCookieFromHeader method of the
CookieManager.  In the method a cookie is created with the name, value,
pulled from the Set-Cookie Header and domain set to the url host, path
ser to / and the expiration set to 24hrs from now.  Then the rest of the
Set-Cookie header is parsed and if the domain/path/expires values are
set the cookie is updated.  However, I think the check for  the expire
value is incorrect.  The current logic is:

            if (key.equalsIgnoreCase("expires"))
            {
                try
                {
                    String expires = nvp.substring(index + 1);
                    Date date = dateFormat.parse(expires);
                    if (date.getTime() > System.currentTimeMillis())
                        //TODO: why this conditional? If it's expired,
it's
                        // expired!
                    {
                        newCookie.setExpires(date.getTime());
                    }
               }
                catch (ParseException pe)
                {
                    // This means the cookie did not come in the proper
format.
                    // Log an error and don't set an expiration time:
                    log.error("Couldn't parse Cookie expiration time.",
pe);
                }
                catch (Exception e)
                {
                    // DateFormat.parse() has been known to throw
various
                    // unchecked exceptions in the past, and does still
do that
                    // occasionally at the time of this writing (1.4.2
JDKs).
                    // E.g. see
http://developer.java.sun.com/developer/bugParade/bugs/4699765.html
                    //
                    // As a workaround for such issues we will catch all
                    // exceptions and react just as we did for
ParseException
                    // above:
                    log.error(
                        "Couln't parse Cookie expiration time: likely
JDK bug.",
                        e);
                }

  If I am interpreting this correctly, if the expires timestamp is newer
than the current system time update the Expires Field.  But if the
expires timestamp is in the past leave alone with the default value (24
hrs from now).  This means that the cookie will still be considered
valid even though it has been expired.  I believe this can be corrected
by eliminating the conditional and setting the cookie's expiration field
with the timestamp from the header.  This will prevent the cookie from
being added to the Cookie Manager.

            if (key.equalsIgnoreCase("expires"))
            {
                try
                {
                    String expires = nvp.substring(index + 1);
                    Date date = dateFormat.parse(expires);
                    //if (date.getTime() > System.currentTimeMillis())
                       //TODO: why this conditional? If it's expired,
it's
                       // expired!
                    //{
                        newCookie.setExpires(date.getTime());
                    //}
                }
                catch (ParseException pe)
                {
                    // This means the cookie did not come in the proper
format.
                    // Log an error and don't set an expiration time:
                    log.error("Couldn't parse Cookie expiration time.",
pe);
                }
                catch (Exception e)
                {
                    // DateFormat.parse() has been known to throw
various
                    // unchecked exceptions in the past, and does still
do that
                    // occasionally at the time of this writing (1.4.2
JDKs).
                    // E.g. see
http://developer.java.sun.com/developer/bugParade/bugs/4699765.html
                    //
                    // As a workaround for such issues we will catch all
                    // exceptions and react just as we did for
ParseException
                    // above:
                    log.error(
                        "Couln't parse Cookie expiration time: likely
JDK bug.",
                        e);
                }
            }

  I am new to the jMeter code so I might have missed something, but this
change corrects my issue

Timothy
___________________________________________
Timothy G. Rundle Sr.
Java Skills Center
Volvo Information Technology North America
c/o Mack Trucks, Inc.
2100 Mack Boulevard
Allentown, PA 18105 USA

Telephone: +1-610-709-3706
Fax:       +1-610-709-3739
E-mail:    timothy.rundle@volvo.com



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Mime
View raw message