[英]JMeter: Generate value for custom Header with a java class
i try to test the performance for our api which has a request-limiter (100requets in 100sec otherwise the ip is blocked). 我尝试测试我们的具有请求限制器的api的性能(100秒内发生100次重击,否则IP被阻止)。 You can avoid this with a custom header.
您可以使用自定义标题避免这种情况。 The value for this header is generate by a java class.
此标头的值由Java类生成。
With jruby i can use "require" and "import" too use the class. 使用jruby,我也可以使用“ require”和“ import”使用类。
How can i do this for JMeter? 我如何为JMeter做到这一点?
Additional infos: the header value is dynamic -> for each request it has to be generated. 其他信息:标头值是动态的->对于必须生成的每个请求。 To call HttpPwd.genPwd() two *.jar files are needed
要调用HttpPwd.genPwd(),需要两个* .jar文件
This is how to proceed : 这是如何进行:
Put the 2 Jars in jmeter/lib folder 将2个罐子放在jmeter / lib文件夹中
Put groovy-all.jar in jmeter/lib 将groovy-all.jar放入jmeter / lib
Use a JSR223 Preprocessor + Groovy 使用JSR223预处理器+ Groovy
Put in the Preprocessor the following code: 将以下代码放入预处理器中:
import xxxxxx;
进口xxxxxx; // where xxxx is the full name of the HttpPwd class
//其中xxxx是HttpPwd类的全名
vars.put("header", HttpPwd.genPwd());
vars.put(“ header”,HttpPwd.genPwd());
HeaderName (I don't know what it is) : ${header}
HeaderName(我不知道它是什么):$ {header}
In your JMeter project navigate to Thread Group
> HTTP Request
. 在您的JMeter项目中,导航到
Thread Group
> HTTP Request
。 You can set your request parameters there. 您可以在那里设置请求参数。
Here is the way of implementing this via JMeter __Beanshell function 这是通过JMeter __Beanshell函数实现此方法的方法
Assuming that you're having following logic for generating custom header: 假设您具有以下用于生成自定义标头的逻辑:
package custom.header;
public class HttpPwd {
public static String getPwd() {
return String.valueOf(System.currentTimeMillis());
}
}
Which is accessible from some jar called "customheader.jar" 可从一个名为“ customheader.jar”的罐子中进行访问
And you want to add a header named "MyHeader" to your request 并且您想在请求中添加一个名为“ MyHeader”的标头
You should see something like: 您应该看到类似以下内容:
GET http://www.google.com/?q=test
[no cookies]
Request Headers:
Connection: keep-alive
MyHeader: 1382360571781
Host: www.google.com
User-Agent: Apache-HttpClient/4.2.3 (java 1.5)
Mention MyHeader presense and value 提及MyHeader的存在和价值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.