Search code examples
jmeter

How to run java code and pass output of java code as jmeter variables


To run API two mandatory headers needs to passed with the body. Developers have written a piece of java code by executing we get timestamp and signature this data should be passed as header for API. Please find below snapshot when executed on Eclipse

enter image description here

Please help how to capture java code output and pass this values as parameter.


Solution

  • Well, you could run it as a normal Java program using OS Process Sampler and extract the timestamp and the signature from the response with Regular Expression Extractor


    However the better would be most probably packaging this "piece of java code" into a .jar file (including all dependencies if any) and dropping it into JMeter Classpath. Once done you should be able to call "generateSignature()` function from the JSR223 PreProcessor using Groovy language. It might be a good idea to return some data structure like Map from it instead of printing the values into STDOUT.