John D
John D

Reputation: 1

jsessionid cookie set in jmeter request not recognised

I would like to execute some jmeter thread group requests in parallel using the same session. To do this, I have created a setUp thread group which authenticates and writes the JSESSIONID cookie (as well as other data) to a CSV file. This file is then to be used by the subsequent thread groups to allow them to use these already authenticated sessions. To do this, I am basically following the solution outlined here: http://theworkaholic.blogspot.co.uk/2013/03/sharing-session-ids-across-threads.html.

The setUp thread group is authenticating and generating the CSV file as expected. However, I cannot get the requests in the subsequent thread groups to use the sessions provided. I can add the JSESSIONID cookie (either by using a BeanShell PreProcessor or using a HTTP Cookie Manager, both give the same results) but this does not seem to be recognised. The request being sent is the following:

POST https://test.mydomain.com:8443/prv/p/getUploadedfiles.action

POST data:
start=0&limit=10&sort=createdDate&dir=DESC&days=6

Cookie Data:
$Version=1; JSESSIONID="D0720DD3B06B5752DF6AC83A1B245EDA"; $Path="/"; 
$Domain="test.mydomain.com"

Request Headers:
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 49
Host: test.mydomain.com:8443
User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_121)

This request has a return status of 302 to re-direct to the login page. This compares to the same request executed successfully in the setUp thread group:

POST https://test.mydomain.com:8443/prv/p/getUploadedfiles.action

POST data:
start=0&limit=10&sort=createdDate&dir=DESC&days=6

Cookie Data:
JSESSIONID=D0720DD3B06B5752DF6AC83A1B245EDA

Request Headers:
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 49
Host: test.mydomain.com:8443
User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_121)

The only difference between the requests seem to be the $Version, $Path and $Domain explicitly set on the cookie data. [Interestingly, the 'Cookie Data' in the solution from the link above seems to be correct, by which I mean does not contain the $Version, $Path or $Domain in the request output] BeanShell PreProcessor code is:

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

Cookie cookie = new Cookie("JSESSIONID", vars.get("jsessionid"), "test.mydomain.com", "/", true, -1);
CookieManager manager = sampler.getCookieManager();
manager.add(cookie);
log.info("Cookie added: " + vars.get("jsessionid"));

Does anyone know why the JSESSIONID cookie is not being recognised?

Upvotes: 0

Views: 3627

Answers (3)

Maxwell Cheng
Maxwell Cheng

Reputation: 1190

open jmeter.properties Look for CookieManager.save.cookies and set it to true You should have a HTTP Cookie Manager in the same thread group Hope this help

Upvotes: 0

John D
John D

Reputation: 1

I solved this by removing the BeanShell PreProcessor and using a HTTP Cookie Manager to add the cookie, and setting the 'Cookie Policy' to "standard" (previously was set to "compatibility").

Upvotes: 0

Dmitri T
Dmitri T

Reputation: 168197

Cookies scope is limited to current Thread Group only. The same applies to JMeter Variables. If you need to pass objects between different Thread Groups you will have to do it via bsh.shared namespace or by converting JMeter Variables into JMeter Properties which are global for the whole JVM. See Knit One Pearl Two: How to Use Variables in Different Thread Groups article for example JMeter Variable to JMeter Property conversion.

Upvotes: 0

Related Questions