Accessing session values when calling regular methods

Hello, I have a scenario that executes the following to get some values:

val getToken = feed(Properties.userCredentials)
.exec(
http(“GetToken”)
.post(…)
.header(“Content-Type”, “application/x-www-form-urlencoded”)
.header(…)
.queryParam(…)

.check(headerRegex(“tuidsession”, “(.*)”).exists.saveAs(“sessionKey”))

.check(headerRegex(“userid”, “(.*)”).exists.saveAs(“userId”)))

.exec(Pause.reqPause)

The values I’m interested in “userId” and “sessionKey”, and I know that they are being returned correctly.

In a subsequent call, I need to make the value of “userId” and “sessionKey” available to a method call to build a string prior to executing a Gatling API:

val uploadSDl = exec(
http(“UploadSD”)
.post(…)
.header(…)
.header(“sdsignature”, CryptoUtils.sign(“POST /users/” + session(“userId”).as[String] + “/tuid/” + Properties.tuid + “/upload”, session(“sessionKey”).as[String]))

.header(“Content-Type”, “multipart/form-data; boundary=---------------------------1234567890”)
.formUpload(“video”, Properties.smallFlvFileName))

.exec(Pause.reqPause)

However, I don’t seem to be able to access the values in the session:

session(“userId”).as[String]

and

session(“sessionKey”).as[String]

both give me the error: “not found value session”

I’ve also tried the underscore approach, to no avail.

How do I get at those values?

thanks
Wayne

Hi Wayne,

The problem is that you’re using the session the fetch the userId and sessionKey, but you’re not telling where it’s coming from.
Simple add session => before your call to CryptoUtils.sign :

.header(“sdsignature”, session => CryptoUtils.sign(“POST /users/” + session(“userId”).as[String] + “/tuid/” + Properties.tuid + “/upload”, session(“sessionKey”).as[String]))

Cheers,

Pierre

Thanks, Pierre - that is indeed what I needed!

cheers
Wayne

Thank you so much for answering this!

-Ryan