Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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.

share|improve this question
    
any feedback on this ? if answer is ok you should accept it so that it helps others – UBIK LOAD PACK May 22 '13 at 11:28
    
actually I want to include my jar, and then call a method from that jar, so far I am not successful. – mmohab May 22 '13 at 12:20
    
where did you put your jar ? are you sure it is fine ? if yes look into jmeter.log and show error – UBIK LOAD PACK May 22 '13 at 12:44
    
i put it in the lib/ext folder – mmohab May 22 '13 at 13:05
    
you must put it in lib not lib/ext – UBIK LOAD PACK May 22 '13 at 13:36

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.

share|improve this answer
    
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 stackoverflow.com/questions/13680350/… 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
up vote 0 down vote accepted

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"))}}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.