Session EL does not get recognised inside header

I am trying to separate the chain and keep it in a re-usable variable


package computerdatabase

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import io.gatling.jsonpath._

class Test1 extends Simulation {

//Global Users
val userMap = scala.collection.concurrent.TrieMapString, String
val rnd = new scala.util.Random
val httpConf = http
.baseURL(“”) // Here is the root for all relative URLs
.acceptHeader(“application/json”) // Here are the common headers
.acceptEncodingHeader(“gzip, deflate”)
.userAgentHeader(“Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0”)

val headers_1 = scala.collection.mutable.Map(“Content-Type” → “application/json”)

val chain1 = exec(
http(“chain request “)
.headers((headers_1 += “pList” → “${pList}”).toMap)

val scn = scenario(“Simple request”)
http(“If request “)
jsonPath("$.data[*]").ofType[Map[String, Any]].findAll.saveAs(“pList”)))



This compiles fine but during runtime gives me following error


16:35:25.156 [INFO ] i.g.h.c.HttpProtocol - Start warm up

16:35:25.681 [INFO ] i.g.h.c.HttpProtocol - Warm up done

16:35:25.731 [ERROR] i.g.h.a.HttpRequestAction - No attribute named ‘pList’ is defined

16:35:25.732 [ERROR] i.g.h.a.HttpRequestAction - No attribute named ‘pList’ is defined


It does not gives any line number but I am sure its the following line which has a problem.

.headers((headers_1 += “pList” → “${pList}”).toMap)

When I use chain1 inline in the exec , it works fine.

You’re shooting yourself in the foot with your mutable Map.

Gatling DSL elements are BUILDERs, so resolution happens in 2 phases:

  1. scenario is built
  2. scenario is run
    What happens here is that when you’re building the scenario, you’re sharing the same mutable Map for gatling1 and chain request. So, you end up adding the “pList” → “${pList}” header to the first request too! And of course the value doesn’t exist as this request is the one supposed to save it.

Lesson: forget about mutability!