Issue when trying to pass parameter from response to header of next service

Facing issue while trying to pass parameter from first request to the header of the next. Could someone please let me know what am I doing wrong here?

Code:

`
package computerdatabase

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

class Test1 extends Simulation {

val httpProtocol = http.baseUrl(“https://tabc.com”)

val httpProtocol_1 = http.baseUrl(“https://services.com”)

val header = Map(
“Content-Type” → “application/soap+xml;charset=UTF-8”,
“Connection” → “alive”,
“User-agent” → “Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0”)

val header_1 = Map(
“Authorization”->"${authToken}",
“actor”->“ISET”,
“log_token”->“LOG”,
“scope”->“read”,
“timestamp”->“123456789”
)

object pl{
val layer7 = scenario(“getauth”).exec(http(“GetAuthToken”)
.post("/oauth/token")
.body(StringBody("""{“client_id” : “123456”,
“client_secret” : “abc123456”,
“grant_type” : “client_credentials”}
“”")).asJSON.check(status.is(200)).check(jsonPath("$.access_token").saveAs(“authToken”)))

val pl1 = exec(http(“dental”)
.post("/dental/search")
.headers(header_1)
.body(StringBody("""<?xml version="1.0" encoding="utf-8"?>

123456

“”")))
}

val auth = scenario(“getauth”).exec(pl.layer7)
val pl1_1 = scenario(“claimsummary”).exec(pl.pl1)

setUp(auth.inject(rampUsers(1) during (1 seconds)).protocols(httpProtocol_1),
pl1_1.inject(nothingFor(10 seconds),
rampUsers(10) during (5 seconds)).protocols(httpProtocol))
}
`

Error:

value asJSON is not a member of io.gatling.http.request.builder.HttpRequestBuilder possible cause: maybe a semicolon is missing beforevalue asJSON’?

“”")).asJSON.check(status.is(200)).check(jsonPath("$.access_token").saveAs(“authToken”)))
^
15:19:49.866 [ERROR] i.g.c.ZincCompiler$ - one error found
15:19:49.867 [ERROR] i.g.c.ZincCompiler$ - Compilation crashed
sbt.internal.inc.CompileFailed: null
at sbt.internal.inc.AnalyzingCompiler.call(AnalyzingCompiler.scala:242)
at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:111)
at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:90)
at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$3(MixedAnalyzingCompiler.scala:82)
`

https://gatling.io/docs/current/migration_guides/2.3-to-3.0/

Thank you Stephane! Could you please take a look at the following issue too, that’s second part of the problem statement where I need to pass auth token to a set of requests which need to run in parallel but auth token need to be executed only once. Appreciate all your help!

https://groups.google.com/forum/#!topic/gatling/PJOXSkUr3sg

Thanks,
Vikram

I noticed that in the new versions of Gatling, there are some errors on over or asJSON. Then, I got that they’ve renamed.

You’re really coming from a very old version, this renaming happened in Gatling 3.0, more than 2 years ago.
See https://gatling.io/docs/current/migration_guides/2.3-to-3.0/

Yes, now I got that. I was following an old course about Gatling and faced some problems like:

  • value over is not a member of io.gatling.core.controller.inject.open.RampBuilder
  • value asJSON is not a member of io.gatling.http.request.builder.HttpRequestBuilder

If you’re looking for up-to-date online training, I recommend you have a look at our official Gatling Academy.