Custom SignatureCalculator - body of Request object passed is blank

Hi,

I’m implementing a custom SignatureCalculator to generate a signature (similar to HMAC).

The problem I’ve encountered is that the request body is always null in the Request object which is passed to the calculateAndAddSignature method.

Has anyone come across this? I noticed that somebody did experience a similar problem over on the Play Framework group but no resolution was given there - so perhaps it’s a bug with AsyncHttpClient as opposed to Gatling? → https://github.com/playframework/playframework/issues/5996

@ Stephane: Do you have any suggestions? Is this a bug? I can raise if so.

Cut-down calculateAndAddSignature function:

@Override
public void calculateAndAddSignature(Request request, RequestBuilderBase<?> requestBuilder) {

System.err.println("Body → " + request.getStringData());

}

Output:

Body → null

Thanks in advance,
Barry

Not a bug. Request has different fields for the different body formats. Depending on your use case, Gatling might not be using StringData but a different field.

Thanks for the swift response Stéphane.

If anyone else runs into this problem in future - here’s what I had to do:

In my request I was using a StringBody. This is a CompositeByteArrayBody (https://github.com/gatling/gatling/blob/a3d2f4b44ac292931599a1b6c4cb72515d7a4e96/gatling-core/src/main/scala/io/gatling/core/CoreDsl.scala#L59)

In order to get the full request body to use in my SignatureCalculator, I had to use getCompositeByteData(), which returns a List<byte[]>. I needed to combine the items in this List to get the full body - like so: