Avoid duplicate queryParam and header in exec


I have a long ChainBuilder where several exec statements use the same queryParam and header.

              .exec(http("Statement 1")
                    .header("id", "#{id}")
                    .header("Content-Type", "application/xml")
                    .queryParam("key", "value")
                    .queryParam("key", "#{value}")
                    .queryParam("key", "#{value}")
                    .queryParam("key", "#{value}")
// ...
// It repeats several times, up to ten times.

I wonder if there is any way to reuse or build the exec statements to avoid the queryParam and header repetition for each exec statement?

Hi @dariush,

As (nearly) anything is immutable in Gatling DSL, you can easily make your own function.

public HttpBuilder withCommonParam(HttpBuilder httpBuilder) {
  return httpBuilder
    .header(“Content-Type”, “application/xml”)
    .queryParam(“key”, “value”)
    .queryParam(“key”, “#{value}”)
    .queryParam(“key”, “#{value}”)
    .queryParam(“key”, “#{value}”);

// call site
.exec(withCommonParams(http("Statement 1").post("https://blabla").header("id", "#{id}"));



Hi @sbrevet !
Thanks for the quick reply. Do you mean HttpRequestActionBuilder? I can’t find the HttpBuilder in my version of Gatling (Java) 3.9.5


Hi @sbrevet
I try a hybrid solution, I created a method and then use it with queryParamMap, this removes a substantial amout of code from the simulation.


public static Map<String, Object> method() {
    return Map.of(
           "key", "#{value}",               
           "key", "#{value}",

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.