Search code examples
javaregexjmeterbeanshell

Error in Beanshell Sampler JMeter for parsing RegularExpressionExtractor


Setting below sample result in jar file

mySampleResult.setResponseData("ReturnCode" + returnCode + "EndReturnCode" ,null);

copy the jar file in lib/ext of JMeter.

Create a project where Regular expression extractor is attached to java request which calls runtest in jar file

Response string is below

ReturnCodeThu Feb 16 08:01:56 GMT 2017,Thu Feb 16 09:09:27 GMT 2017,0:1:7:31,98.74105EndReturnCode

Regular Expression Extractor

Reference Name: returnValue
Regular Expression: ReturnCode(.*?)EndReturnCode

Beanshell Code

 ${returnValue}

Error in Beanshell

Response message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval  In file: inline evaluation of: ``  try {     Thu Feb 16 08:01:56 GMT 2017,Thu Feb 16 09:09:27 GMT 2017,0:1:7:31,9 . . . '' Encountered "16" at line 4, column 13.

Please let me know that why I am getting this error.


Solution

  • Your ${returnValue}statement is syntaxically incorrect, you need at least to surround it with quotation marks like "${returnValue}" so Beanshell interpreter would treat it as a Java String

    Going forward, just putting this statement inside the Beanshell Sampler doesn't make any sense, you should add some further processing, i.e:

    • return "${returnValue}"; - will set Beanshell Sampler result to this value
    • SampleResult.setResponseData("${returnValue}".getBytes()); - the same as above but using SampleResult shorthand
    • print("${returnValue}"); - output the value to STDOUT
    • log.info("${returnValue}"); - output the value to jmeter.log file

    See How to Use BeanShell: JMeter's Favorite Built-in Component for more information on using Beanshell in JMeter scripts