how do i set data into session and use session data in my request

Hi Stephene,

help me please,

i have some lines of code which is useful to store some data into session,

but i am unable to store data into session,

and based on the session data,i request for some other data through url like bellow (in request processing there i am using session data) ,

val dataVo=voMethod.getVos()val compData=new HashMapList[String],List[String]
compData.put(dataVo.get(0),dataVo.get(1))

val dataKey=100

val scn2=scenario("").exec(session => {
import io.gatling.http.cookie._
import java.net.URI
val newSession = (session(“gatling.http.cookies”).asOption[CookieJar].flatMap { cookieJar =>
val cookie = cookieJar.get(URI.create("[")).find(_.getName == compData)

cookie.map(session.set(“Key”+dataKey,com****pData)) ------------------------------------------------------------------------------------------i am getting error here while set data into session

}).getOrElse(session)
newSession
})

val httpProtocol = http
.baseURL(“url”)
.disableFollowRedirect
.acceptHeader(“text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8”)
.doNotTrackHeader(“1”)
.acceptLanguageHeader(“en-US,en;q=0.5”)
.userAgentHeader(“Mozilla/5.0 (Windows NT 6.1; rv:32.0) Gecko/20100101 Firefox/32.0”)
.disableResponseChunksDiscarding
.connection(“keep-alive”)

val scn = scenario(“scenario”)
.exec(http(“GETdata”)
.get(dataKey+“geturl”))

setUp(scn.inject(atOnce(1 user))).protocols(httpProtocol)

Your code won’t work. You can’t do the session.set() inside of the cookie map. Not like that, anyway.

Instead, you need to define a “var newSession = session” and where you do the assignment, do “newSession = newSession.set( … )” and at the end, return newSession.

The reason is that a session is immutable. When you call .set() it is returning a new object. Calling set over and over is creating many new objects, rather than doing what you want, which is adding many things to the one session object.