Friday, July 31, 2009

JMeter - Tests recording and sending binary files (multipart/mixed requests)

Few weeks ago I wanted to test uploading a binary file to HTTP server using JMeter. It is a very good tool, but there are some issues. Theoretically there are three ways of doing this in JMeter.

1. Creating a single request file from scratch

The hardest approach is to create a full HTTP request, containing all the headers and content of the binary file and use that file in a definition of a test case.

2. Recording a test case

JMeter allows recording traffic between a server and a client. Unfortunately for some reason a recorded http request was corrupted. There was a problem with some characters, so the server wasn't able to parse even a header of the request. I thought that the problem is in a wrong encoding. I changed it to "UTF-8" in "HTTP Request Defaults" and it started to work. The file appeared on the server. After that, I wanted to check if it works with other encoding types, it worked the same with all of them. Than I removed completely the encoding setting and it still worked. Then I removed JMeter and installed (unpacked) it again and tried without setting the encoding - it worked. It seems that setting the encoding solves the problem, but I have no idea why it still worked although I removed it. Unfortunately I didn't have time to investigate it deeper.

3. Creating a test case manually using a JMeter UI

In the JMeter UI there is a dialog which allows defining a test case. Tester is able to add a http request header paramters and attach files which will be send as a content of the http request. The problem is that there is no way to set a content type as multipart/mixed, what was required in my case.

JMeter as a proxy - binary files corrupted

During investigation I noticed that when JMeter is set as a proxy, uploaded files are somehow corrupted. It might be related to previously mentioned encoding settings. For those who want to do performance tests I think that it doesn't matter that much.

I need to mention that I didn't spend too much time to investigate the problem and I used JMeter with GUI. If someone knows better solutions, comments will be appreciated.

Besides described issues, JMeter is a really useful tool.