Copying from a chain

Hi,
I have three post requests in which there are around 10-12 parameters.
In all of them only the values of two parameters change and rest all remain the same.
Each chain looks like this -
val chain_x = exec(http(“first”)
.post(“http://www.xyz.com”)
.param(“para1”, val1)
.param(“para2”, val2) . . . . . and so on

Do I need to declare each one three times because it makes the code redundant?
Is there a way to copy a chain into another and then add the different parameters after that?

Hi,

That’s all the point of having a DSL with immutable builders!

Every time you call a DSL method, you actually create a new object that doesn’t share any mutable state with the object of the method.

So, you can have prototypes of your requests, with all the common parameters.

Get it?

Ok. I get the point of immutable builders. Can you show me an example of how to make a custom prototype.
A link from Gatling-wiki with basic info would also do.

I missed the point that you want to change the request name as well, so a static prototype won’t do. You need a method that takes the request name.

You can do something similar at what’s done here: https://github.com/excilys/gatling/wiki/Handling-JSF

def requestWithCommonParams(name: String) =

http(“first”) .post(“http://www.xyz.com”)
.param(“para1”, val1)
.param(“para2”, val2)

exec(requestWithCommonParams(“first”).param(“para3”, val3))
.exec(requestWithCommonParams(“second”).prototype.param(“para4”, val4))

The prototype keyword is generating error. I am using Gatling 2.0.0-M3a. Is it deprecated in it?

Woups, sorry, that’s the problem when you code in an email.

Just remove “.prototype”, that comes from a first tentative, I forgot to remove it.

Yes its working fine but, then how do I change the title inside http("")

Ok, got my error. Its all working fine. Thanks for your help Stephane.

def requestWithCommonParams(name: String) =
http(name) .post(“http://www.xyz.com”)
.param(“para1”, val1)
.param(“para2”, val2)

exec(requestWithCommonParams(“first”).param(“para3”, val3))
.exec(requestWithCommonParams(“second”).prototype.param(“para4”, val4))

Yeah, I figured it out. Thanks again