Author: alf
Date: Sun Oct 14 00:42:36 2007
New Revision: 584502
URL: http://svn.apache.org/viewvc?rev=584502&view=rev
Log:
Parameters used to build a POST body are encoded if specified, when it is
application_x_www_form_urlencoded. This changes the behavior of PostWriter, so
that HttpSampler works similar as HttpSampler2, after the SVN 582954 change to
HttpSampler2.
Fix unit tests for parameter values as body, by telling the sampler to not
encode parameters.
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/PostWriter.java
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/PostWriter.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/PostWriter.java?rev=584502&r1=584501&r2=584502&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/PostWriter.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/PostWriter.java
Sun Oct 14 00:42:36 2007
@@ -262,7 +262,7 @@
PropertyIterator args = sampler.getArguments().iterator();
while (args.hasNext()) {
HTTPArgument arg = (HTTPArgument)
args.next().getObjectValue();
- postBodyBuffer.append(arg.getValue());
+
postBodyBuffer.append(arg.getEncodedValue(contentEncoding));
}
postBody = postBodyBuffer.toString();
}
Modified:
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java?rev=584502&r1=584501&r2=584502&view=diff
==============================================================================
---
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java
(original)
+++
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java
Sun Oct 14 00:42:36 2007
@@ -406,6 +406,8 @@
String contentEncoding = "";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue,
descriptionField, descriptionValue);
+
((HTTPArgument)sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
+
((HTTPArgument)sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
HTTPSampleResult res = executeSampler(sampler);
String expectedPostBody = titleValue + descriptionValue;
checkPostRequestBody(sampler, res, samplerDefaultEncoding,
contentEncoding, expectedPostBody);
@@ -415,6 +417,8 @@
contentEncoding = ISO_8859_1;
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue,
descriptionField, descriptionValue);
+
((HTTPArgument)sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
+
((HTTPArgument)sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
res = executeSampler(sampler);
expectedPostBody = titleValue + descriptionValue;
checkPostRequestBody(sampler, res, samplerDefaultEncoding,
contentEncoding, expectedPostBody);
@@ -426,6 +430,8 @@
descriptionValue = "mydescription\u0153\u20a1\u0115\u00c5";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue,
descriptionField, descriptionValue);
+
((HTTPArgument)sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
+
((HTTPArgument)sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
res = executeSampler(sampler);
expectedPostBody = titleValue + descriptionValue;
checkPostRequestBody(sampler, res, samplerDefaultEncoding,
contentEncoding, expectedPostBody);
@@ -437,19 +443,47 @@
descriptionValue = "mydescription /\\";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue,
descriptionField, descriptionValue);
+
((HTTPArgument)sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
+
((HTTPArgument)sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
res = executeSampler(sampler);
expectedPostBody = titleValue + descriptionValue;
checkPostRequestBody(sampler, res, samplerDefaultEncoding,
contentEncoding, expectedPostBody);
+ // Test sending data as UTF-8, with values that will change when
urlencoded, and where
+ // we tell the sampler to urlencode the parameter value
+ sampler = createHttpSampler(samplerType);
+ contentEncoding = "UTF-8";
+ titleValue = "mytitle/=";
+ descriptionValue = "mydescription /\\";
+ setupUrl(sampler, contentEncoding);
+ setupFormData(sampler, true, titleField, titleValue, descriptionField,
descriptionValue);
+ res = executeSampler(sampler);
+ expectedPostBody = URLEncoder.encode(titleValue + descriptionValue,
contentEncoding);
+ checkPostRequestBody(sampler, res, samplerDefaultEncoding,
contentEncoding, expectedPostBody);
+
// Test sending data as UTF-8, with values that have been urlencoded
sampler = createHttpSampler(samplerType);
contentEncoding = "UTF-8";
titleValue = "mytitle%2F%3D";
descriptionValue = "mydescription+++%2F%5C";
setupUrl(sampler, contentEncoding);
+ setupFormData(sampler, false, titleField, titleValue,
descriptionField, descriptionValue);
+
((HTTPArgument)sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
+
((HTTPArgument)sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
+ res = executeSampler(sampler);
+ expectedPostBody = titleValue + descriptionValue;
+ checkPostRequestBody(sampler, res, samplerDefaultEncoding,
contentEncoding, expectedPostBody);
+
+ // Test sending data as UTF-8, with values that have been urlencoded,
and
+ // where we tell the sampler to urlencode the parameter values
+ sampler = createHttpSampler(samplerType);
+ contentEncoding = "UTF-8";
+ titleValue = "mytitle%2F%3D";
+ descriptionValue = "mydescription+++%2F%5C";
+ setupUrl(sampler, contentEncoding);
setupFormData(sampler, true, titleField, titleValue, descriptionField,
descriptionValue);
res = executeSampler(sampler);
- expectedPostBody = URLDecoder.decode(titleValue, contentEncoding) +
URLDecoder.decode(descriptionValue, contentEncoding);
+ expectedPostBody = titleValue + descriptionValue;
checkPostRequestBody(sampler, res, samplerDefaultEncoding,
contentEncoding, expectedPostBody);
// Test sending data as UTF-8, with values similar to __VIEWSTATE
parameter that .net uses
@@ -459,6 +493,8 @@
descriptionValue = "mydescription";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue,
descriptionField, descriptionValue);
+
((HTTPArgument)sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
+
((HTTPArgument)sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
res = executeSampler(sampler);
expectedPostBody = titleValue + descriptionValue;
checkPostRequestBody(sampler, res, samplerDefaultEncoding,
contentEncoding, expectedPostBody);
@@ -498,6 +534,8 @@
descriptionValue =
"mydescription\u0153\u20a1\u0115\u00c5${description_suffix}";
setupUrl(sampler, contentEncoding);
setupFormData(sampler, false, titleField, titleValue,
descriptionField, descriptionValue);
+
((HTTPArgument)sampler.getArguments().getArgument(0)).setAlwaysEncoded(false);
+
((HTTPArgument)sampler.getArguments().getArgument(1)).setAlwaysEncoded(false);
// Replace the variables in the sampler
replacer.replaceValues(sampler);
res = executeSampler(sampler);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]