Setting headers generated by an outside library

Hi people,

I’m quite new to scala and gatling and I’m trying to create a test scenario for the team I’m working with.

I’m currently facing this apparently simple procedure :

  • Get a user/projectId from a csvFeed (done, quite simple)
  • Call a Java library that generates an identifier for this user/project (done with an exec block)

.exec { session => val user = session.get("myUser").as[String] val identifier = RegistrationHelper.remoteRegister(user, user, session.get("projectId").as[String]) session.set("userId", identifier) }

  • Later in the scenario (in a loop), call another Java library that generates some headers I need to pass to a GET (this is where I’m stuck) :

userId

I know this code cannot work because myHeaders variable cannot be accessed on the next exec call but this is to illustrate my need.

I’ve been struggling with that for days, I managed to avoid the trouble in other cases but here I don’t think I can.

Help me Gatling Community. You’re my only hope.

Thanks,

PG

The second code that google removed and that I’m trying to get help with :

`

.during(duration) { exec { session => val identifier = session.get("userId").as[LogicalIdentifier] val myHeaders = SecurityHeaderGenerator.getRegisteredHeaders(identifier).asScala.toMap } .exec(http("get binary file").get(serviceUrl).headers(myHeaders)) }

`

Store myHeaders in the session in the first block: http://gatling.io/docs/2.1.7/session/session_api.html#setting-attributes.
Fetch them back in the second one.

Hi,

Many thanks for your quick answer.

That was indeed my first idea but I don’t know how to get it back for the moment.
The headers method only accept the Map I want to inject and not an expression to evaluate.

Regards,

PG

Oh right, indeed.

Then, what you’re actually trying to do is a SignatureCalculator.