Access the object from the JsonFeeder in the scenario

Hi!

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
.baseURL(“https://localhost:443”)
.acceptHeader(“text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8”)
.doNotTrackHeader(“1”)
.acceptLanguageHeader(“en-US,en;q=0.5”)
.acceptEncodingHeader(“gzip, deflate”)
.userAgentHeader(“Gatling2”)

val scn = scenario(“Handle feedback”)
.feed(feedbacks)
.exec(http(“Post Feedback”)
.post("/api/feedback")
.body(StringBody(HandleFeedback.buildMessage())).asXML
)

setUp(
scn.inject(rampUsers(10) over (60 seconds))
).protocols(httpConf)
}
`

[ { "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?

/Johan

See this other thread by Carlos Torres for a programmatic example: https://groups.google.com/forum/#!topic/gatling/yynWVdOzvBw

It’s working now, thanks for the help.

/Johan