Bug 52897

Summary: HTTPSampler : Using PUT method with HTTPClient4 and empty Content Encoding and sending files leads to NullPointerException
Product: JMeter - Now in Github Reporter: Joe McCall <joemcc>
Component: HTTPAssignee: JMeter issues mailing list <issues>
Status: RESOLVED FIXED    
Severity: normal CC: joemcc, p.mouawad
Priority: P2    
Version: 2.6   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: Patched HTTPHC4Impl.java to workaround NullPointerException in content-encoding.
Test plan to reproduce issue

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.
Comment 5 The ASF infrastructure team 2022-09-24 20:37:49 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/2779