I have this jmeter file which does multiple calls on several endpoints (it's a regression test). For every endpoint there is the same JSR223 PreProcessor-script that generates a JWT. The JWT is created with variables (different per thread) that are set in 'User defined variables' (also one per thread) and imported in the script by using vars.get().
On runtime the script is not renewing the variables per thread (or per loop). If the script runs twice the script from the last thread in run 1 is being used in the first thread from run 2.
I imagine it has to do something with caching but I can't figure out what.
I've tried checking and not checking the checkbox: 'Cache compiled script if available'.
// get values from 'User defined variables'
String sharedSecret = vars.get("sharedSecret");
String uitgifteDatumTijdOffset = vars.get("uitgifteDatumTijdOffset");
String uitgifteDatumTijd = Instant.now().minusMillis(Long.parseLong(uitgifteDatumTijdOffset)).toString();
String kvkNummer = vars.get("kvkNummer");
String ean13Code = vars.get("ean13Code");
String cnCertificaat = "Test met uitgiftedatum: " + uitgifteDatumTijd + " en EAN13-code: " + ean13Code;
// construct your body data - JSON entity in case below
JsonObject jo = new JsonObject();
jo.addProperty("KvKNummer", kvkNummer);
jo.addProperty("EAN13-code", ean13Code);
jo.addProperty("UitgifteDatumTijd", uitgifteDatumTijd);
jo.addProperty("CN-Certificaat", cnCertificaat);
String jsonString = jo.toString();
// perform JWT-signing of body data
byte[] bytesEncoded = Base64.encodeBase64(sharedSecret.getBytes());
String secret = new String(bytesEncoded);
try {
String jwtToken = Jwts.builder()
.setHeaderParam("alg","HS512")
.setHeaderParam("typ","JWT")
.setPayload(jsonString)
.signWith(SignatureAlgorithm.HS512, secret) // base64EncodedSecretKey
.compact();
// put JWT-signed body data into variable
vars.put("jwtToken", "Bearer " + jwtToken);
} catch (Exception ex) {
prev.setSuccessful(false);
log.error(ex.getMessage());
System.err.println(ex.getMessage());
}
I expect this script to use different variables for every thread. But now it's copying the last value.



