If I am not mistaken, you can only use Gatling EL (i.e., “${ticket}”) in functions that accept Expression[...] type of parameters. Also, assigning to a session variable like "${ticket}" = ... is probably seen by Scala as trying to assign a value to a String literal hence the illegal assignment target error you see.
I am not an expert but would the following work in your case?
.exec { session => {
val rawTicketValueEncodedOnce = session("ticket").as[String]
val rawTicketValueEncodedTwice = java.net.URLEncoder.encode(rawTicketValueEncodedOnce, "UTF-8")
session.set("ticket", rawTicketValueEncodedTwice)
}}
Hi gkallergis,
My problem is that I first need to encode the ticket once and use it in the next request, before I encode it once more and use it in the preceding request.
Then I would assume if I can do a “stand alone” exec just to encode twice it would be a good idea.
Alternatively I could encode the ticket the second time within the actual .exec that needs it double-encoded in the lines of this example:
I think the problem with java.net.URLEncoder.encode("""${ticket}""", “UTF-8”)) is the same as I mentioned in my previous comment. The Java method encode() doesn’t know anything about Gatling’s EL. You are effectively encoding the String litteral ${ticket} here. If I undestand correctly, you can’t pass a session variable anywhere unless the method you are calling is expecting a paramter of type Expression[...].
Just to verify I understand correctly, what you want to do is the following:
Fire a request and get a value from it, encode it and store it in the session.
Fire another request including the encoded value from step #1.
Encode the already encoded value and store it in the session.
Fire another request including the twice-encoded value.
As you say in your initial post, steps #1 and #2 are working for you and you already have an encoded value in your session.
For step #3, did the exec block I provided in my previous comment work? If not, did you get any specific errors?
The call you provide in your last post could be altered this way to cover for both step #3 and #4: