Struggling to access session variable in http check transform

Hi all.

I need to access a session variable in a http transform function called 'check_scope()'.  But the print statement in my check_scope function 
shows that the "${scopeContains}" is not being retrieved from the session

Below is the code and console output.  Other things I've tried:  injecting session into he outer exec, referencing session in the transform call, doing exec with session
to print the session value inside the check_scope function which doesn't print anything oddly.

Any pointers to try, or ideally a code pattern I can look at are appreciated.  Thanks!

**HTTP post that returns 'scope' value to be checked**
      .basicAuth(AuthConfig.WEB_CLIENT_ID, AuthConfig.WEB_CLIENT_SECRET)
      .formParam("grant_type", "authorization_code")
      .formParam("code", "${code}")
      .formParam("redirect_uri", GlobalVars.getEnv)

 **.check(jsonPath("$.scope").ofType[String].transform(check_scope(_, "${scopeContains}")).saveAs("scope"))**

**check_scope Function:**

private def check_scope(scope: String, scopeContains: String) : String = {

  println("CHECK_SCOPE scope:  " + scope + ", scopeContains:  '" + scopeContains + "'")




Console output:

Please try:

.check(jsonPath("$.scope").ofType[String]**.transform((scope, session) => check_scope(scope, session("scopeContains").as[String])**.saveAs("scope"))


Hi Vu,

Thanks - I tried a variation of what you proposed but nothing printed out, not even CHECK_SCOPE_ENTERING. Here’s the snippet for what I did. I also found something else interesting: “scopeContains” has a value in session before the http call, and doesn’t after: I have code for that below as well.

Thanks again for looking at this.

===> Call to check_scope2

.check(jsonPath("$.scope").ofType[String].transform((scope, session) => check_scope2(scope, session)).saveAs("scope"))

Hi Bruce

Looks like there’s a mixing of Gatling DSL and Scala codes in your functions. Please update and try again:

private def check_scope2(scope: String, session: Session) : String = {


    if (session.contains("scopeContains")) {
        println(s"check_scope session:scopeContains:  ${session("scopeContains").as[String]}")



And the “after http call” doesn’t look right. You can use the “before http call” format:

  .doIf(session => session.contains("scopeContains")) {
    exec(session => {

println(“oauth/token called”)

You’re right, we use scala as our test language with the gatling framewor,

Thanks - made those changes. Getting a run-time error, I’ll post here in case it’s helpful

Simulation simulations.fvt.permissions.PermissionsValidation started…
13:21:30.438 [ERROR] i.g.c.a.b.SessionHookBuilder$$anon$1 - ‘hook-190’ crashed w
ith ‘java.util.NoSuchElementException: key not found: user_id’, forwarding to th
e next one