1
votes

I need to sign my request xml and add a token to it before hitting the application. For that I am using a JSR223 preprocessor which gets the data from current sampler, makes the necessary changes and puts the data back to sampler. This approach works fine with a single thread group. When multiple thread groups are used data between the samplers(in different thread groups) gets interchanged and it results in incorrect requests for the thread group. Below is the code in my preprocessor:

import jmeter_plugin.*;
String body = sampler.getXmlData();
log.info(body);
Utils utils=new Utils();
String request=utils.getResponse( body,"url/to/fetch/token");
log.info(request);
sampler.setXmlData(request);

Tried by having a single preprocessors for the entire test plan and also separate pre processors for each thread group. Both approaches did not work.

1
Pre-processors are per thread, and no other thread (even in the same thread group) will ever have access to it... So something does not add up here - no enough information in your question to pinpoint what could cause that. Definitely not just pre-processor usage.Kiril S.
Yes fixed it! It was due to my Utils classPriya

1 Answers

0
votes

Your approach should work fine no matter how many Thread Groups do you have. Pre-Processors are executed before each sampler in its scope and should modify only the current sampler.

Quick checklist:

  1. Make sure you're using Groovy as JSR223 PreProcessor language
  2. Make sure you have Cache compiled script if available box ticked

    Groovy Cache Compiled Script

  3. Remove these log.info lines as they create unnecessary Disk IO overhead
  4. Make sure your Utils class don't use methods which are not Thread Safe
  5. Looking into sampler.getXmlData() it appears you're using JMeter 3.1 or below as SOAP/XML-RPC Request has been removed in JMeter 3.2 and users are encouraged to use HTTP Request sampler instead.
  6. If your "sign" algorithms is not very exotic if might be easier to use WS Security for SOAP JMeter Plugin which can be installed using JMeter Plugins Manager

    JMeter WS Security for SOAP JMeter Plugins Manager