Author: pmouawad
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
Modified:
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java?rev=1300387&r1=1300386&r2=1300387&view=diff
==============================================================================
---
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
(original)
+++
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
Tue Mar 13 22:34:59 2012
@@ -34,6 +34,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.commons.lang.StringUtils;
import org.apache.http.Header;
import org.apache.http.HttpConnection;
import org.apache.http.HttpConnectionMetrics;
@@ -1037,7 +1038,7 @@ public class HTTPHC4Impl extends HTTPHCA
if(haveContentEncoding) {
putParams.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET,contentEncoding);
}
-
+ String charset = getCharsetWithDefault(putParams);
// Just append all the parameter values, and use that as the post
body
StringBuilder putBodyContent = new StringBuilder();
PropertyIterator args = getArguments().iterator();
@@ -1056,7 +1057,7 @@ public class HTTPHC4Impl extends HTTPHCA
contentTypeValue =
put.getFirstHeader(HEADER_CONTENT_TYPE).getValue();
}
StringEntity requestEntity = new
StringEntity(putBodyContent.toString(), contentTypeValue,
- (String)
putParams.getParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET));
+ (String) charset);
put.setEntity(requestEntity);
}
// Check if we have any content to send for body
@@ -1067,9 +1068,11 @@ public class HTTPHC4Impl extends HTTPHCA
ByteArrayOutputStream bos = new ByteArrayOutputStream();
put.getEntity().writeTo(bos);
bos.flush();
+ String charset = getCharsetWithDefault(putParams);
+
// We get the posted bytes using the charset that was used to
create them
- putBody.append(new String(bos.toByteArray(),
- (String)
putParams.getParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET)));
+ // if none was set, platform encoding will be used
+ putBody.append(new String(bos.toByteArray(), charset));
bos.close();
}
else {
@@ -1090,6 +1093,19 @@ public class HTTPHC4Impl extends HTTPHCA
return null;
}
+ /**
+ * If contentEncoding is not set by user, then Platform encoding will be
used to convert to String
+ * @param putParams {@link HttpParams}
+ * @return String charset
+ */
+ protected String getCharsetWithDefault(HttpParams putParams) {
+ String charset =(String)
putParams.getParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET);
+ if(StringUtils.isEmpty(charset)) {
+ charset = Charset.defaultCharset().name();
+ }
+ return charset;
+ }
+
private void saveConnectionCookies(HttpResponse method, URL u,
CookieManager cookieManager) {
if (cookieManager != null) {
Header[] hdrs = method.getHeaders(HEADER_SET_COOKIE);
Modified: jmeter/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1300387&r1=1300386&r2=1300387&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Tue Mar 13 22:34:59 2012
@@ -76,6 +76,7 @@ When doing replacement of User Defined V
<li>Bug 52871 - Multiple Certificates not working with HTTP Client 4</li>
<li>Bug 52885 - Proxy : Recording issues with HTTPS, cookies starting with
secure are partly truncated</li>
<li>Bug 52886 - Proxy : Recording issues with HTTPS when spoofing is on,
secure cookies are not always changed</li>
+<li>Bug 52897 - HTTPSampler : Using PUT method with HTTPClient4 and empty
Content Encoding and sending files leads to NullPointerException</li>
</ul>
<h3>Other Samplers</h3>