Hi, I’m using Gatling 2.2.2, and I’m trying to do something just slightly unusual with a Gatling session. I hope this is an easy one for you.
I have a security library that augments JWT, that creates an arbitrary list of HTTP headers that I need to augment my HTTP requests. Since it is a “rolling JWT” authentication scheme, I need to generate these headers dynamically as the test is running. I have discovered and confirmed that I can use the exec method to dynamically call this library. (I also ensure that caching is being performed, so don’t worry, the cost of invoking this library has been suitably minimized.)
I have also confirmed that the Gatling session’s Map is wonderfully type agnostic, defined as a Map[String, Any]. The rub comes when I want to actually read that list of headers back out of the map to use in my scenario. The version of exec that declares the session as an accessible argument is expected to return a Session as its result, whereas the version of exec that actually allows me to inject an HTTP request into the scenario does not have direct access to the Session.
I even looked at trying to extend StringBody or its cousins to support a Map[String, String], but I quickly got lost, and I’m not certain if the EL would allow me to correctly extract and retype the Map[String, String] to use in my .headers method.
So, my question is simply this: what’s the best and recommended practice for extracting this session variable to use when creating my HTTP request? Example code below. Thanks in advance.