Thanks for the input. First of all, I didn't realise that I can't use it in
a beanshell sampler, but I moved the code to a sampler as opposed to a
preprocessor because it wasn't working. And I can't even do something like:

CookieManager manager = sampler.getCookieManager();
vars.putObject("CookieMananger",manager);
int count = manager.getCookiesCount();
vars.put("count", count);

CookieManager is null at the level of the pre-processor (just to make sure,
the pre-processor is a child to the HTTP Sampler).

So, I'm still not sure that I'm not doing the correct thing, but it appears
to not work and I'm not aware of other restrictions.

--Adrian S



On Tue, Jun 10, 2014 at 5:53 PM, Deepak Shetty <[email protected]> wrote:

> I dont think sampler HTTPSampler creates a CookieManager - the framework
> sets it on the sampler so CookieManager manager =
> sampler.getCookieManager(); should be returning it null
>
> If you are trying to manipulate cookies in places other than a pre/post
> processor of an HTTPSampler , then on your first HTTPSampler you can do
> something like (in a pre processor scoped to this sampler)
> CookieManager manager = sampler.getCookieManager();
> vars.putObject("CookieMananger",manager)
>
> Then (CookieManager)vars.getObject("CookieManager") will allow you to get
> it anywhere
>
>
> On Tue, Jun 10, 2014 at 1:56 AM, Adrian Speteanu <[email protected]>
> wrote:
>
> > Hi guys,
> >
> > Need a suggestion with a piece of code that is not compiling in
> beanshell,
> > and I have no idea why it doesn't work. The code is simple and it's in a
> > beanshell sampler at the moment:
> > "
> > import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
> > import org.apache.jmeter.protocol.http.control.CookieManager;
> > import org.apache.jmeter.protocol.http.control.Cookie;
> >
> > HTTPSampler sampler = new HTTPSampler();
> > CookieManager manager = sampler.getCookieManager();
> > Cookie cookie = new Cookie("SessionPersistence", "value",
> "localhost:8080",
> > "/", true, 0);
> > manager.add(cookie);
> > "
> > Fails with
> > "Response message: org.apache.jorphan.util.JMeterException: Error
> invoking
> > bsh method: eval"
> > because of the very last line.
> >
> > Any ideas what to do and why it fails?
> >
> > Thanks,
> > --Adrian S
> >
>

Reply via email to