Hi All,
I have created maven project and want to use java code in that project, how can i do that.
I have written code for generating JWT token using java, In gatling scala script want to pass the generated token as header.
Please do the needful
Thanks,
Santosh Kulkarni
Hi Kulkarni,
I recently did the same (if I understand your question correctly) by using a ‘feeder’ :
object AccessTokenFeeder {
val gatlingConfFile = ConfigFactory.load("gatling")
val keystoreFile = gatlingConfFile.getString("gatling.http.ssl.keyStore.file");
val keystorePassword = gatlingConfFile.getString("gatling.http.ssl.keyStore.password");
val keystoreType = gatlingConfFile.getString("gatling.http.ssl.keyStore.type");
def apply(): Feeder[String] = {
Iterator.continually(
Map(
("accessToken", new GatlingTokenUtil(keystoreFile, keystoreType, keystorePassword).getAccessToken)
)
)
}
}
and
Hey Robin ,
I want to generate JWT token and use that in header.
Hi Kulkarni,
I recently did the same (if I understand your question correctly) by using a ‘feeder’ :
object AccessTokenFeeder {
val gatlingConfFile = ConfigFactory.load("gatling")
val keystoreFile = gatlingConfFile.getString("gatling.http.ssl.keyStore.file");
val keystorePassword = gatlingConfFile.getString("gatling.http.ssl.keyStore.password");
val keystoreType = gatlingConfFile.getString("gatling.http.ssl.keyStore.type");
def apply(): Feeder[String] = {
Iterator.continually(
Map(
("accessToken", new GatlingTokenUtil(keystoreFile, keystoreType, keystorePassword).getAccessToken)
)
)
}
}
and
Hi,
That’s basically what is stated there. You create a feeder that utilizes a java-class.
In the example GatlingTokenUtil is a java class with a method getAccessToken.
So this (accesToken) is basically the JWT.
The feeder puts this on the session.
To use the generaated JWT (accessToken) in the header you do something like this:
http(…)
.get(…)
.header(“Authorization”, “Bearer ${accessToken}”)
Kind Regards,
How can we do this. Can you post sample code
Just use an exec(session => session) block before the request and call your Java code inside. Then store the value from that Java call in the returned session and it will be available for next execution blocks.
Java - Scala interoperation is something natively supported by Scala (it has nothing to do with Gatling).
El dimarts, 26 juny de 2018 14:07:11 UTC+2, Santosh Kulkarni va escriure: