Access the object from the JsonFeeder in the scenario


I have a Json file with feedbacks that I want to use in my scenario. But I have several types of feedback and therefore I have a method called buildMessage where I want to build the request body. But how can I send the json object from the feeder to the buildMessage method?

class FeedbackSimulation extends Simulation {
val feedbacks = jsonFile(“feedbacks.json”).circular

val httpConf = http
.acceptEncodingHeader(“gzip, deflate”)

val scn = scenario(“Handle feedback”)
.exec(http(“Post Feedback”)

scn.inject(rampUsers(10) over (60 seconds))

[ { "type": "gnss", "lat": "61.902885", "lng": "6.714318" }, { "type": "gnss", "lat": "61.902885", "lng": "6.714318" } ]

The “type”, “lat” and “lng” will be stored in the Session, so obviously, buildMessage as to take a Session input parameter.
But if you’re not used to Scala and Gatling, a first step would probably to use our templating engine instead of trying to crash bodies manually.

The messages are completely different based on the type so I think it isn’t very practical with the templating engine unless I write complete messages in my JSON. How would I write to be able to pass the Session on to my buildMessage method. I guess I write “session: Session” as input parameter in the method, but how would I write in the scenario?


See this other thread by Carlos Torres for a programmatic example:!topic/gatling/yynWVdOzvBw

It’s working now, thanks for the help.