Created attachment 36938 [details] jmeter file and screen shot 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.
The call to sampler.getArguments().getArgumentsAsMap() is causing the described behaviour. A minimal example for this would be a preprocessor like: sampler.getArguments().getArgumentsAsMap(); vars.put("sign1", "something"); With a http sampler that uses ${sign1} in its parameter map.
Closing as no feedback
As my comment seemed a bit short on details: If you use a http sampler with a variable (${sign1} for example) and you use a script to fill it in a pre processor, than calling "sampler.getArguments().getArgumentsAsMap();" will fill the samplers arguments with the current values of the variables. In the minimal example the value for sign1 is not yet set and therefore JMeter will set "${sign1}" as a placeholder. Setting the variable sign1 with a value after that call, will not replace the already set parameters and thus it will stay on the the string "${sign1}". The OP wanted to see in all parameters of the http sampler, whether a special value exists and has to be filled. He called getArgumentesAsMap to do so. That triggers the behaviour.
You can check whether there is a PreProcessor such as RegEx User Parameters under your Sampler in addition to the Beanshell PreProcessor, and whether the location of other PreProcessors is on the Beanshell PreProcessor, which will affect the assignment of vars.put()
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/5220