Bug 28715 - User Parameters do not work in HTTP Cookie Manager
Summary: User Parameters do not work in HTTP Cookie Manager
Status: RESOLVED FIXED
Alias: None
Product: JMeter - Now in Github
Classification: Unclassified
Component: HTTP (show other bugs)
Version: 2.0.0
Hardware: PC All
: P3 normal with 1 vote (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-04-30 14:51 UTC by Vibhav Garg
Modified: 2011-10-20 07:03 UTC (History)
0 users



Attachments
simple test plan (10.89 KB, text/plain)
2004-05-18 11:53 UTC, rino
Details
Fix to allow expansion of functions and user parameters in the CookieManager (1.59 KB, patch)
2005-10-10 21:46 UTC, Stephen Cooper
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vibhav Garg 2004-04-30 14:51:37 UTC
In our app we need to assign cookie values using User Parameters. However, 
right now, variable expansion does not work in HTTP Cookie Manager.
Comment 1 Sebb 2004-05-04 12:36:48 UTC
Could you attach a simple test case that shows the problem, please?
Comment 2 rino 2004-05-18 11:53:49 UTC
Created attachment 11589 [details]
simple test plan
Comment 3 rino 2004-05-18 11:56:11 UTC
I'm having the same problem, although I'm using the "User Defined Variables" 
defined in the "Test Plan". In the file I attached, I set a "domain" variable, 
and I try to use it for the cookie domain. Won't work :(
Comment 4 Charles Eakins 2004-05-21 17:30:00 UTC
We are also seeing this bug, with user variables and built in variables like 
${_StringFromFile(file-path)}.  We need to change a value in the cookie to 
about a hundred different combonations.  BTW keep up the good work, I really 
like what I have seen so far, in fact better than loadrunner.
Comment 5 Sebb 2004-05-22 09:02:11 UTC
[Thanks for the sample]

I've had a quick look at the code, and the Cookie Manager stores its values in 
a slightly different way from (most) other test elements - the result is that 
it treats them as fixed strings, and does not try to interpret them as 
functions/variables.
Comment 6 theshaman 2005-01-03 15:27:45 UTC
I just want to say I also face with this limitation (not possible to add
personalized cookies to each user threads, using user variables or other means)
of JMeter. I think it could be a very useful enhancement of JMeter.
Nevertheless congratulations and thanks for your work.
Comment 7 Stephen Cooper 2005-10-10 21:46:25 UTC
Created attachment 16640 [details]
Fix to allow expansion of functions and user parameters in the CookieManager

This patch allows the expansion of UserParameters and Function calls in the
Cookie Manager.  It does so by no longer overriding the setRunningVersion and
recoverRunningVersion methods.
As a result of no longer overriding these, I had to create some way to
accurately reset cookies for each iteration.  So I introduced a variable
"temporaryCookies" which gets populated with the cookie name of any cookie to
remove - any cookie added while isRunningVersion is set to true.
Comment 8 Stephen Cooper 2005-10-10 21:48:39 UTC
Oh yeah - forgot to mention.  The patch I just uploaded is against the following
version:
[coop@cstephen jakarta-jmeter]$ cvs status
src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java
===================================================================
File: CookieManager.java        Status: Locally Modified

   Working revision:    1.40
   Repository revision: 1.40   
/home/cvspublic/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java,v
   Sticky Tag:          v2_1_1 (revision: 1.40)
   Sticky Date:         (none)
   Sticky Options:      (none)
Comment 9 Alf Hogemark 2007-03-18 10:35:25 UTC
I have been briefly looking at this.

The following short patch seems to make it possible to use functions and user
parameters in the CookieManager.

Index: C:/Documents and
Settings/alf/workspace/Jmeter/src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java
===================================================================
--- C:/Documents and
Settings/alf/workspace/Jmeter/src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java
(revision 519613)
+++ C:/Documents and
Settings/alf/workspace/Jmeter/src/protocol/http/org/apache/jmeter/protocol/http/control/CookieManager.java
(working copy)
@@ -290,7 +290,10 @@
         int i=0;
         for (PropertyIterator iter = getCookies().iterator(); iter.hasNext();) {
             Cookie jmcookie = (Cookie) iter.next().getObjectValue();
+            // Set to running version, to allow function evaluation for the
cookie values
+            jmcookie.setRunningVersion(true);
             cookies[i++] = makeCookie(jmcookie);
+            jmcookie.setRunningVersion(false);
         }
         String host = url.getHost();
         String protocol = url.getProtocol();


However, I'm not sure this is the correct way of fixing this.
I have not looked much at the CookieManager code.
Are there threading issues involved ? I.e. can different threads be accessing
the cookies at the same time ? In that case, the different threads can set and
unset the running version.
Or do each thread have it's own instance of the CookieManager and all other
ConfigTestElement ?
If each thread have their own CookieManager, I think the simple patch above is
correct.

Do we want to only allow variable expansion in the static cookies, and not in
the runtime cookies received during sampling ?

Perhaps Stephen Cooper's patch from 2005-10-10 looks better, but the code seems
to have changed a bit since his suggestion.

Could we just call "setRunningVersion(false); setRunningVersion(false);" on each
cookie as the first thing to do in "testIterationStart" ?
Or will we get threading issues here as well ?

And also call "setRunningVersion(false);" on each cookie on "testEnded" ?
Perhaps that is not needed, as it seems like the GUI recreates all the cookies
"static cookies" when you go to the CookieManager GUI. I'm at least unable to
figure out when all the dynamic cookies are deleted, but I never see them in the
GUI.

Or should we add a flag to the Cookie class, so we know which ones are static
and which ones are dynamic, and then loop over all the static ones in
the following methods in CookieManager :
public void recoverRunningVersion() 
public void setRunningVersion

I'm sorry for all the questions, but this bug seems like an "easy" one to fix,
and quite important.

Any comments ?
Comment 10 Sebb 2007-09-01 05:42:15 UTC
Code has been added to Cookie Manager in SVN r571789.

Just in case it causes a problem, one can set the property:

CookieManager.allow_variable_cookies=false 

to disable the fix.
Comment 11 jimmyxu 2011-10-19 09:32:52 UTC
hi 
I am not sure whether I have got correct configuration of Jmeter, but I do see user parameter is not work in cookie manager. I got this problem both Jmeter 2.4 and Jmeter 2.5.1
reproduce step:
1. Create http request to access a website
2. Create a regular expression extractor to get a SessionID value as SessID variable
3. Create a HTTP Cookie Manager to reference SessID(${SessID})

result: $SessID is treated as a string not a variable
        (but this variable works in http sampler.) 

expected: $SessID is treated as a variable
Comment 12 Sebb 2011-10-19 11:31:16 UTC
(In reply to comment #11)
> hi 
> I am not sure whether I have got correct configuration of Jmeter, but I do see
> user parameter is not work in cookie manager. I got this problem both Jmeter
> 2.4 and Jmeter 2.5.1
> reproduce step:
> 1. Create http request to access a website
> 2. Create a regular expression extractor to get a SessionID value as SessID
> variable
> 3. Create a HTTP Cookie Manager to reference SessID(${SessID})
> 
> result: $SessID is treated as a string not a variable
>         (but this variable works in http sampler.) 
> 
> expected: $SessID is treated as a variable

WOrks fine for me; note that the Cookie Manager is a configuration element so only resolves variables at the start of a loop.
Comment 13 jimmyxu 2011-10-20 02:14:08 UTC
(In reply to comment #12)
> (In reply to comment #11)
> > hi 
> > I am not sure whether I have got correct configuration of Jmeter, but I do see
> > user parameter is not work in cookie manager. I got this problem both Jmeter
> > 2.4 and Jmeter 2.5.1
> > reproduce step:
> > 1. Create http request to access a website
> > 2. Create a regular expression extractor to get a SessionID value as SessID
> > variable
> > 3. Create a HTTP Cookie Manager to reference SessID(${SessID})
> > 
> > result: $SessID is treated as a string not a variable
> >         (but this variable works in http sampler.) 
> > 
> > expected: $SessID is treated as a variable
> 
> WOrks fine for me; note that the Cookie Manager is a configuration element so
> only resolves variables at the start of a loop.

Thanks.
I misunderstand user parameter, user parameter works well.
What I want to do is reset cookie value for a http smapler, is there any method can do that in Jmeter?

Jimmy
Comment 14 Sebb 2011-10-20 07:03:15 UTC
Bugzilla is not a support forum.

Please subscribe to the JMeter user list and ask there.
Comment 15 The ASF infrastructure team 2022-09-24 20:37:33 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/1363