1

I am using JMeter for load testing, I am creating 1000 threads each sending an http request as follows:

{"email" : "test${__threadNum}@test.com"}

that's working fine, now I need to add a more complicated scenario. I need to pass email encrypted with my custom encryption method.

something like:  {"email" : MyCustomClass.encypt("test${__threadNum}@test.com")}

Is there a way to call custom java classes from JMeter.

mmohab
  • 2,303
  • 4
  • 27
  • 43

2 Answers2

2

The best solution I found is to edit the file BeanShellFunction.bshrc and add java methods there,

String encryptSession(String email) {
    // TODO encrypt session!
    return new String(email);
}

and then add this to the http request body:

${__BeanShell(encryptSession("test${__threadNum}@test.com"))}}
mmohab
  • 2,303
  • 4
  • 27
  • 43
1

You can use a JSR 223 sampler or preprocessor and use Groovy as underlying language. To do so add groovy-all.jar in jmeter/lib folder.

If you want to use your already existing jar, put it in jmeter/lib also.

UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116
  • what is the syntax to call java methods in jmeter. I expect something like this in the request body {"email" : MyCustomClass.encypt("test${__threadNum}@test.com")} but not sure about the syntax – mmohab May 20 '13 at 19:25
  • See http://stackoverflow.com/questions/13680350/how-to-set-cookie-in-jmeter-that-is-usually-set-via-javascript for an example – UBIK LOAD PACK May 20 '13 at 20:03
  • The sampler (groovy or beanshell) puts the var using vars.put (''test'', the var) then use it with ${thevar} – UBIK LOAD PACK May 20 '13 at 20:05