JMeter, Proxies, and Cookies

Using Vaadin 6.7.4; previously I could use JMeter with this. Since deploying the new version (from 6.7.1) we’ve run into a problem.

The application works correctly minus JMeter.

JMeter uses a proxy to sit between the browser and the app and record the HTTP traffic. However when going through the proxy the app reports an error, “Cookies Disabled. This application requires cookies to function.”

I’ve got a cookie manager in JMeter.

Have there been any changes in Vaadin that might have caused this error to crop up? Any suggestions for fixing it?

Hi!

Don’t know if this helps but I got and solved the same problem (“Cookies Disabled. This application requires cookies to function.”) when trying to use JMeter, but in my case the problem was unrelated to the Vaadin version in use.

My problem was that I started recording my test case in the middle of a Vaadin session.

What I ERRONEOUSLY did:

  1. Start application server
  2. Start JMeter Proxy server
  3. Start browser and load my web app
  4. Change the browser proxy settings
  5. Record my test case

I guess that this made JMeter’s cookie manager miss some vital cookies. I am no expert in JMeter testing, but the erroneous behavior was reproducible.

When I reloaded the site of my web app AFTER changing the Firefox proxy settings, I got a consistent and working JMeter test script.

There is another way of managing JMeter cookies using Beanshell scripting including sharing cookies between thread groups. See following code snippet for example:

// code to get all cookies from HTTP Cookie Manager

import org.apache.jmeter.protocol.http.control.CookieManager;

CookieManager manager = ctx.getCurrentSampler().getProperty("HTTPSampler.cookie_manager").getObjectValue();

props.put("cookiecount",String.valueOf(manager.getCookieCount()));

for (int i=0;i<manager.getCookieCount();i++)
{  
   props.put("cookie_name"+i,manager.get(i).getName());
   props.put("cookie_value"+i,manager.get(i).getValue());
   props.put("cookie_domain"+i,manager.get(i).getDomain());
   props.put("cookie_path"+i,manager.get(i).getPath());
   props.put("cookie_expires"+i,String.valueOf(manager.get(i).getExpires()));                
   props.put("cookie_secure"+i,String.valueOf(manager.get(i).getSecure()));
}

The code above retrieves all the cookies avaiable in HTTP Cookie Manager. Wherever needed it’s possible to construct cookies from properties as below:

[code]
// reconstruct cookies from JMeter Properties
CookieManager manager = ctx.getCurrentSampler().getProperty(“HTTPSampler.cookie_manager”).getObjectValue();

int count = Integer.parseInt(props.getProperty(“cookiecount”));

for (int i=0;i<count;i++)
{
Cookie cookie = new Cookie(props.getProperty(“cookie_name”+i),props.getProperty(“cookie_value”+i),
props.getProperty(“cookie_domain”+i),props.getProperty(“cookie_path”+i),
Boolean.parseBoolean(props.getProperty(“cookie_secure”+i)),
Long.parseLong(props.getProperty(“cookie_expires”+i)));
manager.add(cookie);
}

JMeterProperty cookieprop = ctx.getCurrentSampler().getProperty(“HTTPSampler.cookie_manager”);

cookieprop.setObjectValue(manager);

ctx.getCurrentSampler().setProperty(cookieprop);
[/code]See
How to use BeanShell: JMeter’s favorite built-in component
guide for more information on extending JMeter via Beanshell Scripting and kind of Beanshell cookbook with examples of interacting with JMeter API.