So I have long query string that gets encoded by gatling during simulation run but encoding is not right.
QueryString
`
NORTHERN TRUST COMPANY"~5 OR “NORTHERN TRUST GLOBAL INVESTMENTS”~5 OR “NORTHERN TRUST CHICAGO OMNIBUS”~5 OR
“NORTHERN TRUST”~5 OR “NORTHERN TRUST CHICAGO”~5 OR “NTC NORTHERN TRUST”~5 OR “NRTHEN TRUST GLOBAL”~5 OR
“COLA CANADA”~5 OR “INVST COCA”~5 OR “NORTHERN TRUST INVESTMENTS”~5 OR “CHICAGO OMNIBUS NORTHERN TRUST”~5 OR
“IRIDIAN ASSET MANAGEMENT”~5 OR “CUPPS CAPITAL”~5 OR “CUPPS CAPITAL MANAGEMENT”~5 OR
“SAN FRANCISCO CITY & COUNTY EMPLOYEES NORTHERN TRUST”~5 OR “NORTHERN TRUST CHICAGO BANK”~5 OR “NRTHRN TST”~5 OR
“9999999 NORTHERN TRUST”~5 OR
“C9999999 NORTHERN TRUST”~5 OR “HOTCHKIS & WILEY”~5 OR “GOODYEAR CANADA”~5
`
Gatling encoding
`
%22NORTHERN%20TRUST%20COMPANY%22~5%20OR%20%22NORTHERN%20TRUST%20GLOBAL%20INVESTMENTS%22~5%20OR%20%22NORTHERN%20TRUST%20CHICAGO%20OMNIBUS%22~5%20OR%20%22NORTHERN%20TRUST%22~5%20OR%20%22NORTHERN%20TRUST%20CHICAGO%22~5%20OR%20%22NTC%20-%20NORTHERN%20TRUST%22~5%20OR%20%22NRTHEN%20TRUST%20GLOBAL%22~5%20OR%20%22COLA%20CANADA%22~5%20OR%20%22INVST%20COCA%22~5%20OR%20%22NORTHERN%20TRUST%20INVESTMENTS%22~5%20OR%20%22CHICAGO%20OMNIBUS%20NORTHERN%20TRUST%22~5%20OR%20%22IRIDIAN%20ASSET%20MANAGEMENT%22~5%20OR%20%22CUPPS%20CAPITAL%22~5%20OR%20%22CUPPS%20CAPITAL%20MANAGEMENT%22~5%20OR%20%22SAN%20FRANCISCO%20CITY%20&%20COUNTY%20EMPLOYEES%20NORTHERN%20TRUST%22~5%20OR%20%22NORTHERN%20TRUST%20CHICAGO%20BANK%22~5%20OR%20%22NRTHRN%20TST%22~5%20OR%20%2299-99999%20NORTHERN%20TRUST%22~5%20OR%20%22C99-99999%20NORTHERN%20TRUST%22~5%20OR%20%22HOTCHKIS%20&%20WILEY%22~5%20OR%20%22GOODYEAR%20CANADA%22%20~5
`
The problem here is that it is not encoding “&” properly. Here is the snippet from above
SAN%20FRANCISCO%20CITY%20**&**%20COUNTY%20EMPLOYEES
Notice the ampersand “&” above. This throws 500 response
Java urlEncoding works as desired
Same snippet using java URLEncoding
SAN+FRANCISCO+CITY+%26+COUNTY+EMPLOYEES
Notice how the spaces are encoded with “+” and “&” as “%26”
Is there a way I can get java encoding enabled at runtime.
The queryString is captured from some Json Response and used in another json response
I have tried the following
`
.get(uri1 + “https…” +URLEncode.encode("${jsonQueryString}", “UTF-8”))
`
but that didn’t work. Is there some other way I can achieve this.
I have got it working with URLEncoder.encode but its a hack and it would be nice if we can address this issue .
For posterity, here is what I did:
`
.exec{session =>
val fullNameString = session(“fullName”).as[String]
val encodedFullName = URLEncoder.encode(fullNameString,“UTF-8”)//fullNameString.replaceAll("&","%26")//
session.set(“encodedFullName”, encodedFullName)
}
.get(uri2 + “”"?&callback=angular.callbacks._3&facetType=json&q=${encodedFullName}""")///is working but needs to be fixed
`
This is an issue on your side.
It’s impossible for Gatling to guess that this & in the query string is part of a parameter value and not a parameter delimiter. Try adding ?q=A & B to whatever url and check what your browser sends.
You have to help Gatling and pass q as a full query parameter with query param. Then, Gatling will know that this & is inside a query param value and has to be encoded.
Oops. That was a stupid mistake. Thanks for pointing me in right direction.
.queryParam is encoding it properly.
Hello,
I am still seeing behavior that indicates the no encoding is occurring on query params. I have a simple simulation at this point and using a feeder and thus the EL feature. If I encode the data in the file with “+” for spaces everything works fine. Here are the details:
val termFeeder = separatedValues("term.txt", '\n').random ... .queryParam("term", "valerie ber") // or .queryParam("term", "${term}")
I thought this should encode the value or after the EL is resolved but I see this in the query string and the http request fails.
&term=valerie ber
I am running Gatling 2.1.7 from sbt 0.13.9 and Scala 2.11.7. Any help appreciated.
Eric
Hello,
Sorry, but I’m positively sure white spaces in query param values are properly urlencoded into %20, except if you’ve explicitly disabled url encoding on the protocol.
Please provide a full reproducer.
Hi Stéphane,
I totally apologize. I inherited this from someone else and it did indeed have http.disableUrlEncoding set. I was focusing on the scenario, feeds and queryParams and totally overlooked the HttpProtocolBuilder.
Thanks, works as advertised, sorry to bother you.
Eric
Hi Stéphane,
I’d propose to add the query parameter encoding subject to the advanced tutorial of Gatling, since a lot of users seem to stumble on the encoding issue and spent a lot of time solving it (including me). Especially, if you start your Gatling project with its HTTP recorder which doesn’t produce scripts with queryParam().
Thanks,
Christof
Hi Stèphane,
I would give it a try.
Could you give me code pointers to the statement “Gatling will encode them for you” in the HTTP protocol chapter?
Obviously, there are different encoding rules applied to the parameters of the get() and queryParam() methods.
Christof