HTTP/POST 中的 JMeter 代理和 java 序列化?
我们有一个 applet-servlet 通信,我们希望使用 JMeter 的 HTTP 代理来记录它。 它使用 GET 消息,直到小程序发送包含一些序列化 Java 对象(内置类型)的 HTTP POST 消息,然后我们在小程序中收到此错误:
alt text http://img339.imageshack.us/img339/9238/appletservletjmeterhttp.png
好的,队列中某处存在一些 JVM 版本冲突。但在哪里呢?
不使用JMeter通信运行OK,即:Applet ->雄猫->小服务程序。全部在我的本地机器上。
但通过 JMeter 不起作用:Applet -> JMeter代理->雄猫->小服务程序。也都在我的机器上。
就好像 JMeter 正在修改 POST 消息内容...
我也使用 Apache 代理对其进行了测试,工作正常。
更有趣的是,我只安装了一个版本的 Java,一个 JDK 和一个 JRE。都是 1.6.0_07...
在开始深入挖掘之前我想先问一下;-)
这是直接发送到 Tomcat 的 POST 数据的十六进制转储:
00000348 ac ed 00 05 73 72 00 11 6a 61 76 61 2e 6c 61 6e ....sr.. java.lan
00000358 67 2e 49 6e 74 65 67 65 72 12 e2 a0 a4 f7 81 87 g.Intege r.......
00000368 38 02 00 01 49 00 05 76 61 6c 75 65 78 72 00 10 8...I..v aluexr..
00000378 6a 61 76 61 2e 6c 61 6e 67 2e 4e 75 6d 62 65 72 java.lan g.Number
00000388 86 ac 95 1d 0b 94 e0 8b 02 00 00 78 70 00 00 01 ........ ...xp...
00000398 7b {
这是通过 JMeter 发送时的数据:
00000128 ac ed 00 05 73 72 00 11 6a 61 76 61 2e 6c 61 6e ....sr.. java.lan
00000138 67 2e 49 6e 74 65 67 65 72 12 e2 a0 a4 f7 3f 3f g.Intege r.....??
00000148 38 02 00 01 49 00 05 76 61 6c 75 65 78 72 00 10 8...I..v aluexr..
00000158 6a 61 76 61 2e 6c 61 6e 67 2e 4e 75 6d 62 65 72 java.lan g.Number
00000168 3f ac 3f 1d 0b 3f e0 3f 02 00 00 78 70 00 00 01 ?.?..?.? ...xp...
00000178 7b {
很多第二个转储中的“3f”... 所以这肯定是某种编码问题。 标题中的内容类型设置正确:
POST /ABCOrder/ABCServlet?cmd=getNetworkConnection HTTP/1.1
Connection: keep-alive
Content-Type: application/octet-stream
Host: 109.107.148.164:8443
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
User-Agent: Mozilla/4.0 (Windows Vista 6.0) Java/1.6.0_14
Content-Length: 81
We have an applet-servlet communication that we'd like to record with JMeter's HTTP proxy.
It works with GET messages until the applet sends an HTTP POST message which includes some serialized Java objects (built-in types), then we get this error in the Applet:
alt text http://img339.imageshack.us/img339/9238/appletservletjmeterhttp.png
OK, so there's some JVM version conflict somewhere in the queue. But where?
The communication runs OK without JMeter, that is: Applet -> Tomcat -> Servlet. All on my local machine.
But it doesn't work through JMeter: Applet -> JMeter proxy -> Tomcat -> Servlet. Also all on my machine.
It is as if JMeter was modifying the POST message content...
I tested it with the Apache proxy as well, working fine.
Even funnier thing is that I have only one version of Java installed, one JDK and one JRE. Both 1.6.0_07...
Thought I'd ask before starting digging deeper in the rabbit hole ;-)
Here is the hex dump of the POST data sent directly to Tomcat:
00000348 ac ed 00 05 73 72 00 11 6a 61 76 61 2e 6c 61 6e ....sr.. java.lan
00000358 67 2e 49 6e 74 65 67 65 72 12 e2 a0 a4 f7 81 87 g.Intege r.......
00000368 38 02 00 01 49 00 05 76 61 6c 75 65 78 72 00 10 8...I..v aluexr..
00000378 6a 61 76 61 2e 6c 61 6e 67 2e 4e 75 6d 62 65 72 java.lan g.Number
00000388 86 ac 95 1d 0b 94 e0 8b 02 00 00 78 70 00 00 01 ........ ...xp...
00000398 7b {
And here is the data when sent through JMeter:
00000128 ac ed 00 05 73 72 00 11 6a 61 76 61 2e 6c 61 6e ....sr.. java.lan
00000138 67 2e 49 6e 74 65 67 65 72 12 e2 a0 a4 f7 3f 3f g.Intege r.....??
00000148 38 02 00 01 49 00 05 76 61 6c 75 65 78 72 00 10 8...I..v aluexr..
00000158 6a 61 76 61 2e 6c 61 6e 67 2e 4e 75 6d 62 65 72 java.lan g.Number
00000168 3f ac 3f 1d 0b 3f e0 3f 02 00 00 78 70 00 00 01 ?.?..?.? ...xp...
00000178 7b {
A lot of "3f"s in the second dump...
So this is definitely some kind of an encoding problem.
The content type is set correctly in the header:
POST /ABCOrder/ABCServlet?cmd=getNetworkConnection HTTP/1.1
Connection: keep-alive
Content-Type: application/octet-stream
Host: 109.107.148.164:8443
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
User-Agent: Mozilla/4.0 (Windows Vista 6.0) Java/1.6.0_14
Content-Length: 81
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是解决方案:
JMeter 有一个配置文件 bin/jmeter.properties。
在这里您可以找到一个可以设置二进制内容类型的选项:
现在我不知道为什么默认情况下不包含 application/octet-stream ,但您可以简单地将其添加到列表中,你就完成了。
我是这样发现的:
https://issues.apache.org/bugzilla/show_bug.cgi?id= 44808
对 JMeter 进行了搜索已关闭错误...:-)
Here is the solution:
JMeter has a config file, bin/jmeter.properties.
Here you can find an option where you can set the binary content types:
Now I don't know why application/octet-stream isn't included by default, but you can simply add it to the list, and you are done.
This is how I found it out:
https://issues.apache.org/bugzilla/show_bug.cgi?id=44808
Did a search on JMeter closed bugs... :-)
其他人报告了非常相似的情况:http://markmail.org/message/pl5erin2isehm5q6。不过,我在他们的 bug 跟踪器 中找不到与此问题相关的任何问题。看起来你赢得了在兔子洞里挖得更深的特权:)
Someone else is reporting a very similar: http://markmail.org/message/pl5erin2isehm5q6. I can't find any issue related to this problem in their bug tracker though. It looks like you won the privilege to dig deeper in the rabbit hole :)
接受的答案仅允许记录静态请求。
这是不现实的,因为它不允许请求的任何变化(例如更改搜索的单词,...),因此您将始终对同一组数据进行压力测试。
为了使其成为真正的测试,您需要使用第三方插件。
商业 JMeter 插件允许这样做,请参阅:
为了使您的测试更真实,您将需要改变序列化对象中的内容。
此 Java 序列化插件将允许执行以下操作:
使用 JMeter 代理服务器轻松记录流量,将创建使用自定义采样器的测试计划
使用
使用 JMeter 标准后处理器从响应中轻松提取数据
通过标准 JMeter 查看结果树元素轻松调试请求/响应
免责声明:我在这家公司工作。
The accepted answer only allows recording static requests.
This will not be realistic as it will not allow any variabilisation of requests (for example changing the searched word, ...) so you will always be stress testing the same bunch of data.
To make it a real test, you need to use a third party plugin.
A commercial JMeter plugin allows this, see:
To make your tests realistic, you will need to variabilize content in the serialized objects.
This Java Serialization plugin will allow the following:
Easy recording of traffic with JMeter Proxy Server, a Test Plan using custom Sampler will be created
Easy variabilization of requests (which will appear as XML) through as easy syntax as for example ${searchedWord} where searchedWord can come from a CSV or any user defined variable.
Easy extraction of data from responses using JMeter standard Post Processors
Easy debugging of Request/Responses through standard JMeter View Results Tree element
Disclaimer :I work for this company.