SignatureCalculator API - Help

Hi,

I am new to Gatling and Scala. My team is looking into using Gatling for our performance testing. I have been looking at the Signature Calculator API and see how I can use to register user and create a token but what I am reading here: http://gatling.io/docs/2.0.0/http/http_request.html#http-headers is a bit confusing to me. Do I need create a trait for Signature Calculator in my project and then call it somewhere in the simulation? Or how do I go about it? Can someone help me understand how this work? Some examples will be highly appreciated.

This is what I have attempted so far as I read Gatling documents: (Right now I do not understand how to use Request and RequestBuilder).

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.http.protocol.HttpProtocolBuilder
import org.asynchttpclient.{Request, RequestBuilderBase, SignatureCalculator}

class OpenSomethingSignatureCalculator extends SignatureCalculator {
  // Default Headers
  val defaultHeaders = Map("Content-Type" -> "application/json", "Authorization" -> "Basic")
  // Http Client Config
  val httpConf: HttpProtocolBuilder = http
    .baseURL("https://mywebsite.bz") // Here is the root for all relative URLs
    .headers(defaultHeaders)
    .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") // Here are the common headers
    .acceptEncodingHeader("gzip, deflate")
    .acceptLanguageHeader("en-US,en;q=0.5")
    .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")

  override def calculateAndAddSignature(request: Request, requestBuilder: RequestBuilderBase[_]): Unit = {
  }
}

This is the SignatureCalculator API:

public interface SignatureCalculator {
  void calculateAndAddSignature(Request request,
                                RequestBuilderBase<?> requestBuilder);
}

These are the three ways to set this API:

.signatureCalculator(calculator: SignatureCalculator)

// use this signature if you want to directly pass a function instead of a SignatureCalculator
.signatureCalculator(calculator: (Request, RequestBuilderBase[_]) => Unit)

// use this signature if you need information from the session to compute the signature (e.g. user specific authentication keys)
// does not work with an anonymous function as in the second signature
.signatureCalculator(calculator: Expression[SignatureCalculator])

This is where I am stuck - I am not sure how to set this up to my code. Any help (possibly with an example) will be highly appreciated.




Run into the same road block here as well. Can anybody help??

Thanks,
Javier

I wish there could be any example available for SignatureCalculator :frowning:

I’m still not clear about it’s use case.

Have you got any answer for this yet from active forum member?