vars.put did not work after invoke jmeter beanshell preprocessor related api
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.3k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 5
Description
**wayne.wu** ([Bug 64039](https://bz.apache.org/bugzilla//show_bug.cgi?id=64039&redirect=false)):
my test need to use jmeter beanshell preprocessor module, because i need to calculuate sha1 encryption for api sign variable in http request.
following is beanshell preprocessor source code
=============
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Collection;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.testelement.property.CollectionProperty;
import org.apache.commons.codec.digest.DigestUtils;
Date date = new Date();
long time = (date.getTime());
String s = String.valueOf(time);
vars.put("timestamp1",s);
Arguments args = sampler.getArguments();
log.info(String.valueOf(args.getArgumentCount()));
Map reqMap = args.getArgumentsAsMap();
reqMap.put("sign_key","123");
reqMap.put("client_id","456");
ArrayList arrlist=new ArrayList();
for(String key:reqMap.keySet()){
log.info( "key: "+ key + " and value: "+ reqMap.get(key));
if(key.equals("sign") || key.equals("access_token"))
{
continue;
}
arrlist.add(key);
}
Collections.sort(arrlist);
String sign="";
for(int i=0;i<arrlist.size();i++)
{
String key=(String)arrlist.get(i);
sign+=key;
sign+=(String)reqMap.get(key);
}
log.info(sign);
String final_sign=DigestUtils.sha1Hex(sign);
log.info(final_sign);
vars.put("sign1",final_sign);
=============
in jmeter http request paramter form, there was a parameter named 'sign', with value of ${sign1}, my purpose is to change this value by calculated value from var.pug("sign1" , final_sign)
but it didn't work, i found everytime, in beanshell preprocessor, invoke jemter related api will make final statement "vars.put("sign1",final_sign)" fail to put value.
Created attachment [jmeter_caocao.zip](https://apache.github.io/jmeter-bugzilla-attachments/39/64039/36938/jmeter_caocao.zip): jmeter file and screen shot
Severity: normal
OS: All
Contributor guide
Research direction
Start with the attached jmeter_caocao.zip test plan and reproduce the Beanshell preprocessor case around the JMeter API calls. Trace why vars.put("sign1", final_sign) does not affect the HTTP request parameter, and consider the issue done when the calculated sign1 value is used reliably in the request.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100