mmohab
mmohab

Reputation: 2383

how to create and call a custom function in jmeter

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.

Upvotes: 1

Views: 9991

Answers (2)

mmohab
mmohab

Reputation: 2383

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"))}}

Upvotes: 2

UBIK LOAD PACK
UBIK LOAD PACK

Reputation: 34566

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.

Upvotes: 1

Related Questions