When using the JMmeter proxy (to record pages) on a multipart/form-data whith an upload file field, if the filename is not specified, an invalid request is send to the server. My actual webapp (with cocoon) and the form are too complex to be put as an attachment, but I'll provide the stacktrace. I recreated the same problem using a simple form with ruby on rails, I'll put the webrick stacktrace too. I think I've spoted the problem in PostWriter.java, I'll provide a patch (as soon as I'll have checkout sources from svn).
Created attachment 17084 [details] Cocoon stacktrace
Created attachment 17086 [details] simple multipart form The simple html page I used in ruby on rails to reproduce the problem with the jmeter proxy.
Created attachment 17087 [details] webrick - ruby on rails - stacktrace The stacktrace I get when using jmeter proxy with the simple form with no filename specified.
I spotted the problem in org.apache.jmeter.protocol.http.sampler.PostWriter.java In sendPostData(), the filename is tested with those lines: String filename = sampler.getFilename(); if ((filename != null) && (filename.trim().length() > 0)) { But in setHeaders(), the filename is not use: String filename = sampler.getFileField(); if ((filename != null) && (filename.trim().length() > 0)) { Where sampler.getFileField() is the "name" attribut of the html input ("upload" in my simple multipart form attachment file), therefore wrong headers a used. See patch-bug-37716.txt
Created attachment 17088 [details] replace sampler.getFileField() with sampler.getFilename()
Created attachment 17089 [details] junit test case for PostWriter Test all public methodes of PostWriter. Place it under: [jmeter-workspace]/test/src/org/apache/jmeter/protocol/http/sampler Done under windows XP and eclipse 3.1. Launch from eclipse: green bar. Launch from ant: green bar.
Thanks very much - it's particularly useful to have the JUnit testcase. I've applied the patch to the 2.1 branch. BTW, PostWriter.CRLF and PostWriterTest.CRLF need to remain private - final arrays are mutable (unless they have zero entries), so it's not completely safe to share them.
solve with the latest svn sources :)
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/1642