Bug 52897 - HTTPSampler : Using PUT method with HTTPClient4 and empty Content Encoding and sending files leads to NullPointerException
HTTPSampler : Using PUT method with HTTPClient4 and empty Content Encoding an...
Status: RESOLVED FIXED
Product: JMeter
Classification: Unclassified
Component: HTTP
2.6
All All
: P2 normal (vote)
: ---
Assigned To: JMeter issues mailing list
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2012-03-13 14:19 UTC by Joe McCall
Modified: 2012-03-13 22:37 UTC (History)
2 users (show)



Attachments
Patched HTTPHC4Impl.java to workaround NullPointerException in content-encoding. (1.03 KB, application/octet-stream)
2012-03-13 14:19 UTC, Joe McCall
Details
Test plan to reproduce issue (5.87 KB, application/xml)
2012-03-13 22:35 UTC, Philippe Mouawad
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Joe McCall 2012-03-13 14:19:34 UTC
Created attachment 28459 [details]
Patched HTTPHC4Impl.java to workaround NullPointerException in content-encoding.

My service accepts an HTTP PUT request with file contents as the body and returns a 201: created when the file upload is successful. Here is how I test it with cURL:

curl -u testuser:testpass "http://localhost:8080/photo" -T photo.jpg -H "content-type:image/jpeg"

According to the documentation I should be able to do this by specifying a file path with no name and no other parameters. It seems like the content encoding is retrieved in this situation, but not set (even if it's available), resulting in a NullPointerException: 

java.lang.NullPointerException: charsetName at java.lang.String.<init>(Unknown Source) at java.lang.String.<init>(Unknown Source) at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sendPutData(HTTPHC4Impl.java:1067) at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:274) at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:62) at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1054) at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1043) at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:416) at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:271) at java.lang.Thread.run(Unknown Source)

I checked out the code and did some digging. To work around this I specified the content-encoding if it's available (copy/pasted from where truncated parameter bodies are handled) and set the encoding in my test. Attached is a patch of what I did.

I'm not sure if this is a fix or a workaround though. The real issue *might* be that it's always expecting a content encoding for all HTTP PUT (and POST as far as I can see) requests. I leave that for you to decide.

Thanks for your consideration,

Joe
Comment 1 Philippe Mouawad 2012-03-13 22:05:32 UTC
Hello,
Can you attach your test plan please ?

Thanks
Regards
Philippe
Comment 2 Philippe Mouawad 2012-03-13 22:35:28 UTC
Created attachment 28463 [details]
Test plan to reproduce issue
Comment 3 Philippe Mouawad 2012-03-13 22:36:22 UTC
Date: Tue Mar 13 22:34:59 2012
New Revision: 1300387

URL: http://svn.apache.org/viewvc?rev=1300387&view=rev
Log:
Bug 52897 - HTTPSampler : Using PUT method with HTTPClient4 and empty Content Encoding and sending files leads to NullPointerException

Modified:
   jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
   jmeter/trunk/xdocs/changes.xml
Comment 4 Philippe Mouawad 2012-03-13 22:37:06 UTC
Thanks for report and patch although it was not fully applied.