Bug 37716

Summary: Invalid request using Proxy for a multipart/form-data with no filename specified.
Product: JMeter - Now in Github Reporter: Benjamin Francisoud <a_cogito>
Component: MainAssignee: JMeter issues mailing list <issues>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 2.1.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: Cocoon stacktrace
simple multipart form
webrick - ruby on rails - stacktrace
replace sampler.getFileField() with sampler.getFilename()
junit test case for PostWriter

Description Benjamin Francisoud 2005-11-30 14:25:19 UTC
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).
Comment 1 Benjamin Francisoud 2005-11-30 14:26:35 UTC
Created attachment 17084 [details]
Cocoon stacktrace
Comment 2 Benjamin Francisoud 2005-11-30 14:30:42 UTC
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.
Comment 3 Benjamin Francisoud 2005-11-30 14:31:45 UTC
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.
Comment 4 Benjamin Francisoud 2005-11-30 14:37:50 UTC
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
Comment 5 Benjamin Francisoud 2005-11-30 14:38:46 UTC
Created attachment 17088 [details]
replace sampler.getFileField() with sampler.getFilename()
Comment 6 Benjamin Francisoud 2005-11-30 17:37:47 UTC
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.
Comment 7 Sebb 2005-12-01 00:10:45 UTC
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.
Comment 8 Benjamin Francisoud 2005-12-02 10:33:47 UTC
solve with the latest svn sources :)
Comment 9 The ASF infrastructure team 2022-09-24 20:37:36 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/1642