store and retrieve item session

Hi,

For a couple of days now I’ve been trying to get this working using this user group, and I’m pretty sure I’m getting closer by the hour. However, no succes yet…I’ll show you my latest state, hopefully somebody can pinpoint the last failure…

This is the response I’m analysing has this structure:

[ { "profileCode": "ABC", "expectedDate": "2016-06-21T00:00:00+02:00", "first": false, "frequency": "M" }, { "profileCode": "ABC", "expectedDate": "2016-06-21T00:00:00+02:00", "first": true, "frequency": "M" } ]

using this code:

`

val selectRepport =
exec(http(“Select repport”)
.get("/api/obligation/2016/${userId}")
.check(status.is(200))
.check(jsonPath(stringToExpression("$[?(@.frequency == “M” && @.profileCode == “ABC” && @.state == “OPEN”)]")).findAll.saveAs(“oblArr”) )
).exec(session => {
println(session)
session
})
.exec( session => {
foreach("${oblArr}", “item”) {
exec(
session => {
val entry = session(“item”).as[Map[String, Any]]
val profileCode = entry(“profileCode”) // retreive value of profileCode (“ABC”)
session.set(“profileCode”, profileCode)
})
}
session
}
).exec(http(“test ${profileCode}”)
.get("/ebridge/api/${profileCode}")
.check(status.is(200))
)

`

At runtime the session is printed including the array of items:

`

Session(…, oblArr → Vector({“expectedDate” : "2016-…

`

The profileCode value however is not found when referenced. So probably I don’t store it on the session properly. I read something about immutability of the session, but haven’t found an alternative yet.

`

15:46:08.669 [ERROR] i.g.h.a.s.HttpRequestAction - ‘httpRequest-3’ failed to execute: No attribute named ‘profileCode’ is defined

`

Anybody…?

I had the same issue with session.set. Try instead of .get("/ebridge/api/${profileCode}") this .get(/ebridge/api/" + _(“profileCode”).as[String])

I believe your suspicion was correct that the problem had to do with session immutability. On the other hand, Gatling DSL allows foreach loop to be in the execution chain by itself (i.e. not within exec call). Hope the changes below work for you:

`

val selectRepport =
exec(http(“Select repport”)
.get("/api/obligation/2016/${userId}")
.check(status.is(200))
.check(jsonPath(stringToExpression("$[?(@.frequency == “M” && @.profileCode == “ABC” && @.state == “OPEN”)]")).findAll.saveAs(“oblArr”) )
)
.exec(session => {
println(session)
session
})
.foreach("${oblArr}", “item”) {
exec(session => {
val entry = session(“item”).as[Map[String, Any]]
val profileCode = entry(“profileCode”) // retreive value of profileCode (“ABC”)
session.set(“profileCode”, profileCode)
})
.exec(http(“test ${profileCode}”)
.get("/ebridge/api/${profileCode}")
.check(status.is(200))
)
}

`