vars.put 赋值失败,在调用beanshell preprocessor相关api之后
我的测试需要根据当前http请求参数计算sha1签名,用到了beanshell preprocessorfollowing is beanshell preprocessor source codeimport 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);在jmeter GET请求 form中有一个变量 'sign', with value of ${sign1}, 我的意图是用最后的代码把var.put("sign1" , final_sign),把计算好的final_sign,赋值给form里面的那个变量的值.
但是,有问题,我发现,每次调用jemter 相关的api,最后的"vars.put("sign1",final_sign)" 会失效导致最后出去的http请求还是 http....sign={sign1}... 没有被替换掉
来学习 vars.put("sign1",final_sign);没问题啊,sign1是什么类型?需要转换吗? 发送前检查变量的值 不是很懂 ,来学习下 不清楚,学习,顶一下吧
页:
[1]