In Gatling 2.3, I had a signature calculator that looked like this:
class OemEncryptedKeySignatureCalculator extends SignatureCalculator {
override def calculateAndAddSignature(request: Request, requestBuilder: RequestBuilderBase[_]): Unit = {
val headers = request.getHeaders
val oemSecret = headers.get(“oemSecret”)
val oemStr = headers.get(“oemStr”)
val oemModel = headers.get(“oemModel”)
val now: Long = Instant.now().getEpochSecond() + numDevices * 100 + 10000
val oemEncryptedKeyRaw = “%d %s %s %s”.format(now, oemSecret, oemStr, oemModel)
val oemEncryptedKey = encryptString(oemEncryptedKeyRaw)
val newBody = putInfoJson.format(oemStr, oemModel, oemEncryptedKey)
requestBuilder.setBody(newBody)
headers.remove(“oemSecret”)
headers.remove(“oemStr”)
headers.remove(“oemModel”)
}
}
I was able to set the body of the request to a new value. FYI, as a hack, I was passing in values through headers. Maybe there was a better way of doing that, but that is not my question.
I was not able to figure out how to set the body in a signature calculator in Gatling 3. Here is what I have so far:
class OemEncryptedKeySignatureCalculator extends SignatureCalculator {
def sign(request: Request): Unit = {
val headers = request.getHeaders
val oemSecret = headers.get(“oemSecret”)
val oemStr = headers.get(“oemStr”)
val oemModel = headers.get(“oemModel”)
val now: Long = Instant.now().getEpochSecond() + numDevices * 100 + 10000
val oemEncryptedKeyRaw = “%d %s %s %s”.format(now, oemSecret, oemStr, oemModel)
val oemEncryptedKey = encryptString(oemEncryptedKeyRaw)
val newBody = putInfoJson.format(oemStr, oemModel, oemEncryptedKey)
// request.setBody(newBody) // This does not work
headers.remove(“oemSecret”)
headers.remove(“oemStr”)
headers.remove(“oemModel”)
}
}
I need to dynamically create the body of my request. Can someone help me figure out how to do this in Gatling 3?
Ron