Enock Prince
Enock Prince

Reputation: 141

Calling JSR223 Pre processor for each request

I am using JSR223 Pre processor to generate UUID in http header. The value will be updated in a log file with timestamp for tracking purpose.

I have added the pre processor in each call, so every time it generates an unique value and updates the log file. Please have a look on below code.

import org.apache.jmeter.services.FileServer;
import java.sql.Timestamp;
import java.util.UUID;

String uuid = UUID.randomUUID().toString();
vars.put("p_x_transaction_id",uuid);
uid= vars.get("p_x_transaction_id");

String Logfile=vars.get("p_logfile");
f = new FileOutputStream(Logfile,true);
p = new PrintStream(f); 
this.interpreter.setOut(p); 

Timestamp timestamp = new Timestamp(System.currentTimeMillis());
p.println(timestamp + " - " + uid);

Is it possible put above code in JSR223 sampler and call the method in header directly?

I have tried but it generates unique value for each iteration only.

Please throw some lights on this.

Upvotes: 1

Views: 1541

Answers (1)

Dmitri T
Dmitri T

Reputation: 167992

There is no need to copy and paste the JSR223 PreProcessor and add it to each call, the JSR223 PreProcessor obeys JMeter Scoping Rules so if you put it at the same level as all your Samplers - it will be applied to all the Samplers

enter image description here

As you can see I have only one instance of the JSR223 PreProcessor and it has been executed 3 times (before each Sampler in its scope)

Upvotes: 2

Related Questions