Getting StringBody working with Java

715 views
Skip to first unread message

Philip Riecks

unread,
Nov 29, 2021, 10:48:32 AM11/29/21
to Gatling User Group
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 (https://gatling.io/docs/gatling/reference/current/http/request/#full-body) 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,
Philip

Stéphane LANDELLE

unread,
Nov 29, 2021, 10:50:24 AM11/29/21
to gat...@googlegroups.com
That's the same syntax, you don't need new (that's a static method): https://gatling.io/docs/gatling/reference/current/http/request/#stringbody 
--

Stéphane Landelle

Chief Technical Officer

   

slan...@gatling.io
gatling.io
   
facebook twitter linkedin 


--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gatling/ebe0b204-d8ec-417e-85ba-773393518229n%40googlegroups.com.

Philip Riecks

unread,
Nov 29, 2021, 10:59:47 AM11/29/21
to Gatling User Group
Thanks for the quick help 🙏🏻 That solved it for me.

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

Adding

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

to the top of the class solved it for me 😅

Stéphane LANDELLE

unread,
Nov 29, 2021, 1:35:15 PM11/29/21
to gat...@googlegroups.com
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.


--

Stéphane Landelle

Chief Technical Officer

   

slan...@gatling.io
gatling.io
   
facebook twitter linkedin 

Reply all
Reply to author
Forward
0 new messages