append to session Map

Hi,

How to I achieve this in Gatling (with reference to the code below):

1/Append to a session Map as we go through chain of execs
2/Use a session Map value in http call body or header.

for e.g. :
I’d like to use PERSON_INFO_MAP(“payloadMDM”) in the subsequent subsequent http .body,
and subsequently 'wd like to capture the response (.check(bodyString.saveAs(“soapReply”))), and append to the same session map like say append (“soapReplyXML”, "soapReply)
to PERSON_INFO_MAP, which can be used as payload in some subsequent api call.

Thank you
shree

//part of .exec(session=>{ function

var payload=Payloads.requestMDM//a XML String
val PERSON_INFO_MAP = Map(
(“firstName”, firstName.trim()),
(“lastName”, lastName.trim()),
(“middleName”, middleName.trim()),
(“company”, company),
(“state”, state),
(“city”, city),
(“addressLine”, addressLine.trim()),
(“zip”, zip.trim()),
(“email”, email.trim()),
(“username”, username.trim()),
(“phoneNo1”, “858-215-5555”),
(“phoneNo2”, “858-215-5553”),
(“acName”, acName),
(“country”, “US”),
(“payloadMDM”,payload)
);

session.set(“PERSON_INFO_MAP”,PERSON_INFO_MAP);

})
.exec(
http(“my_call”)
.post(“http://ffgprf.bosptc.abcs.net:80/ora/default/abcsService/1.0”)
.header(“Content-Type”," text/xml; charset=UTF-8")
.header(“SOAPAction”,“syncAccount”)
.body(StringBody("""${session(“PERSON_INFO_MAP”).asMap[String, String]}""")) //------->>>>>>This throws ERROR !!!
.check(status.is(200))
.check(bodyString.saveAs(“soapReply”))
//------>>would like to append this response as key to the PERSON_INFO_MAP
//—>> to be used as input to subsequent api call. This resets the session. I loose PERSON_INFO_MAP !!!

)

I’ve never added a map to the session, but you can certainly add individual attributes.

The it would lookk something like this:

SringBody("${payloadMDM}")

HTH

Stefan

Thank you Stefan. Let me generalize the problem. I’m new to Scala and Gatling, so I may be missing things.
The scenario consists of multiple execs like below.
In each of .execs I do some processing, and generate key, value pairs which can be needed by any of the subsequent execs.

In any .exec only the latest session.set value is available to the subsequent execs (see illustration below)

1/So what is the best practice here to persist multiple attributes in a session ?

To solve this problem I was trying to use maps.
But in subsequent http() DSL, I was not able to get the key value by SringBody("${PERSON_INFO_MAP(“payloadMDM”)}")
2/I see support for Lists bout not Maps

.exec(session=>{


session.set(“key1”,“value1”)
session.set(“key2”,value2")

})
.exec(session=>{

//This throws error- key not found

val myKey= session(“key1”).as[String]

//This works
val myKey= session(“key2”).as[String]

})

.exec(
http(“api_call”)


)

.exec(session=>{

})

.exec(
http(“api_call”)

Thank you
shree

set returns a new session. Functional style. No side effects.

You’re misunderstanding how Gatling EL works.
As stated in the documentation, Gatling EL is very simple and just a convenient way to build simple dynamic things instead of writing functions. This is absolutely not a full fledged dynamic language.

So, real scala code cannot be embedded into Gatling EL like you did.
Moreover, Gatling EL and functions cannot be mixed as EL strings are implicitly compiled into functions and that compilation is not triggered inside function.

Now, back to your problem:

StringBody(session => session(“PERSON_INFO_MAP”).asMap[String, String])

Thank you for the clarifications.