Type mismatch: found string, io.gatling.core.session.Session required

Hi folks,

I know this is a topic that comes up with some regularity, having Googled for it a bunch, but:

[Error] /path/to/whatever.scala:62: type mismatch;
found : String(“oauth_client_id”)
required: io.gatling.core.session.Session

Everywhere I’ve seen this mentioned, the suggestion is to “import io.gatling.core.Predef._”. I’ve already done that, yet I’m still getting the error.

It’s also showing up in a weird place: line 62, which is where the error above shows up, is here:

class FooSimulation extends Simulation {
var util = new SecretsManagerUtil
val secretMap = util.getOAuthClientAndSecret()
val clientId = secretMap(“oauth_client_id”)
val clientSecret = secretMap(“oauth_client_secret”)

Later on, those variables are to be used like so:

.formParam(“client_id”, “${clientId}”) |~
.formParam(“client_secret”, “${clientSecret}”)

That is, at the point when I retrieve the clientId and clientSecret from the secretMap, they’ve not yet been taken for any purpose in Gatling, so I’m surprised that they need to be a particular Gatling type rather than ordinary String objects.

I’m new to Scala, so I’m sure this is some Scala- or Gatling-DSL-specific thing that is blindingly obvious to more-experienced Scala developers.

Can someone clue me in on what obvious thing I’m missing here?

Many thanks,

It looks like your secretMap custom method expects a Session but you’re passing a String (“oauth_client_id”).

Hi Stéphane,

Yes, exactly. I don’t know why it expects a Session, though. Is it possible that Gatling has overridden the .get() or .getOrElse() methods somewhere?

Rewritten a little for the sake of clarity, the part of the code that secretMap shows up in is this:

class DiningOptionsSimulation extends Simulation {
val util = new SecretsManagerUtil
val oauth_map = JSON.parseFull(util.getOAuthClientAndSecret())
val clientId = oauth_map.get(“oauth_client_id”)
val clientSecret = oauth_map.get(“oauth_client_secret”)

getOAuthClientAndSecret() is just a little convenience method to talk to AWS Secrets Manager:

def getOAuthClientAndSecret() : String = {
val client = SecretsManagerClient.create()

val req = GetSecretValueRequest.builder()

val res = client.getSecretValue(req)
return res.secretString()

So oauth_map is the result of a JSON parse from the standard library; and it’s parsing the output of getOAuthClientAndSecret(), which returns a string.

I can’t figure out how a Session would slip in here. What am I missing?


Impossible to tell without you provide the full sample.

Hi Stéphane,

Sure. See attached.

Thanks very much,

gatling_sample.scala (2.28 KB)

So, your code is wrong and your issue has nothing to do with Gatling.

JSON.parseFull returns a Option[Any] (your JSON can be empty, an array or an object).

oauth_map is a Option[Any], and Option has a parameterless get method that returns the value if defined or throw an Exception otherwise. It doesn’t take a String and oauth_map.get(“oauth_client_id”) doesn’t compile.

You have to fix your JSON parsing.

Thanks, Stéphane; that got me over the hump.

The error did seem to suggest something involving Gatling Session objects. Is that a sort of error that people familiar with Scala would have immediately understood to mean something else?

I appreciate your helping a newbie.

Many thanks,

You’re welcome.

Then, if you’re not familiar with Scala, you can probably code this in Java and then call it from Scala.