Getting StringBody working with Java

Hi everyone,

I’m trying to convert an existing Gatling test written in Scala to Java. I’m struggling with passing the StringBody to the body of the HTTP request.

The documentation provides code examples for Java ( but I’m not sure if they’re correct as there’s no “new” operator to instantiate the StringBody object.

Even with adding the “new” operator, none of the provided examples compile:

new StringBody(session → “{“test”: 42}”)
new StringBody("{“test”: 42}")

I’m usin Gatling 3.7.2 with the Maven Plugin 4.0.1

Kind regards,

That’s the same syntax, you don’t need new (that’s a static method):

Thanks for the quick help :pray:t2: That solved it for me.

My IDE was somehow always trying to insert the new operator and did not suggest adding the static import.


import static io.gatling.javaapi.core.CoreDsl.StringBody;

to the top of the class solved it for me :sweat_smile:

Actually, you have everything you need from the wildcard imports you can see in our documentation.
I guess your IDE “optimized” your imports and you lost them.

Please let us know how the migration works for you.