Search code examples
jmeterbeanshell

Jmeter beanshell Encounter ";"


I am trying to execute beanshell script in jmeter for a URL parameter value. I have the following:

${__BeanShell(vars.get("query").replaceAll(" ","%20"))}

The jmeter console outputs this:

Caused by: bsh.ParseException: In file: inline evaluation of: ``vars.get("query").replaceAll(" ";'' Encountered ";" at line 1, column 33.

I can't figure out what the problem is as the character there is a , not a ;.


Solution

  • You're doing something ridiculous. Encoding an URL is not only about escaping spaces, looking into URLEncoder documentation you will need to handle:

    • All non-Latin non-alphanumeric characters
    • All characters apart from ., -, *, and _

    Which might be very tricky.

    So you basically have 2 options:

    Performance-wise in cases of high loads Groovy is preferred option, check out Apache Groovy - Why and How You Should Use It article for more details.