HTTP Parameters without names are ignored (except for POST requests with no file)

Parameters used to build a POST body are encoded if specified.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/jmeter/trunk@582954 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2007-10-08 20:29:35 +00:00
parent 04fa2c6463
commit a42e17b9de
4 changed files with 46 additions and 16 deletions

View File

@ -274,7 +274,11 @@ public class HTTPSampler2 extends HTTPSamplerBase {
// Add any parameters
PropertyIterator args = getArguments().iterator();
while (args.hasNext()) {
HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
String parameterName = arg.getName();
if (parameterName.length()==0){
continue; // Skip parameters with a blank name (allows use of optional variables in parameter lists)
}
parts[partNo++] = new StringPart(arg.getName(), arg.getValue(), contentEncoding);
}
@ -347,7 +351,7 @@ public class HTTPSampler2 extends HTTPSamplerBase {
post.setRequestEntity(fileRequestEntity);
// We just add placeholder text for file content
postedBody.append("<actual file content, not shown here>"); // $NON-NLS-1$
postedBody.append("<actual file content, not shown here>");
}
else {
// In an application/x-www-form-urlencoded request, we only support
@ -360,14 +364,31 @@ public class HTTPSampler2 extends HTTPSamplerBase {
// If a content encoding is specified, we set it as http parameter, so that
// the post body will be encoded in the specified content encoding
final String contentEncoding = getContentEncoding();
boolean haveContentEncoding = false;
if(contentEncoding != null && contentEncoding.trim().length() > 0) {
post.getParams().setContentCharset(contentEncoding);
haveContentEncoding = true;
}
// If none of the arguments have a name specified, we
// just send all the values as the post body
if(!getSendParameterValuesAsPostBody()) {
// It is a normal post request, with parameter names and values
if(getSendParameterValuesAsPostBody()) {
// Just append all the non-empty parameter values, and use that as the post body
StringBuffer postBody = new StringBuffer();
PropertyIterator args = getArguments().iterator();
while (args.hasNext()) {
HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
String value;
if (haveContentEncoding){
value = arg.getEncodedValue(contentEncoding);
} else {
value = arg.getEncodedValue();
}
postBody.append(value);
}
StringRequestEntity requestEntity = new StringRequestEntity(postBody.toString(), post.getRequestHeader(HEADER_CONTENT_TYPE).getValue(), post.getRequestCharSet());
post.setRequestEntity(requestEntity);
} else { // It is a normal post request, with parameter names and values
PropertyIterator args = getArguments().iterator();
while (args.hasNext()) {
HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
@ -375,6 +396,9 @@ public class HTTPSampler2 extends HTTPSamplerBase {
// so if the argument is already encoded, we have to decode
// it before adding it to the post request
String parameterName = arg.getName();
if (parameterName.length()==0){
continue; // Skip parameters with a blank name (allows use of optional variables in parameter lists)
}
String parameterValue = arg.getValue();
if(!arg.isAlwaysEncoded()) {
// The value is already encoded by the user
@ -407,17 +431,6 @@ public class HTTPSampler2 extends HTTPSamplerBase {
// post.setRequestEntity(requestEntity);
*/
}
else {
// Just append all the parameter values, and use that as the post body
StringBuffer postBody = new StringBuffer();
PropertyIterator args = getArguments().iterator();
while (args.hasNext()) {
HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
postBody.append(arg.getValue());
}
StringRequestEntity requestEntity = new StringRequestEntity(postBody.toString(), post.getRequestHeader(HEADER_CONTENT_TYPE).getValue(), post.getRequestCharSet());
post.setRequestEntity(requestEntity);
}
// If the request entity is repeatable, we can send it first to
// our own stream, so we can return it

View File

@ -774,12 +774,16 @@ public abstract class HTTPSamplerBase extends AbstractSampler implements TestLis
log.warn("Unexpected argument type: "+objectValue.getClass().getName());
item = new HTTPArgument((Argument) objectValue);
}
final String encodedName = item.getEncodedName();
if (encodedName.length() == 0) {
continue; // Skip parameters with a blank name (allows use of optional variables in parameter lists)
}
if (!first) {
buf.append(QRY_SEP);
} else {
first = false;
}
buf.append(item.getEncodedName());
buf.append(encodedName);
if (item.getMetaData() == null) {
buf.append(ARG_VAL_SEP);
} else {

View File

@ -33,6 +33,7 @@
<ul>
<li>Bug 43430 - Count of active threads is incorrect for remote samples</li>
<li>Throughput Controller was not working for "all thread" counts</li>
<li>If a POST body is built from parameter values only, these are now encoded if the checkbox is set.</li>
</ul>
<h4>Improvements</h4>
@ -50,6 +51,7 @@
<li>JDBC Sampler now allows INOUT and OUT parameters for Called procedures</li>
<li>JDBC Sampler now allows per-thread connections</li>
<li>Cookie Manager not longer clears cookies defined in the GUI</li>
<li>HTTP Parameters without names are ignored (except for POST requests with no file)</li>
</ul>
<h4>Non-functional Improvements</h4>

View File

@ -192,6 +192,7 @@ resource requires query string parameters, add them below in the
appended to the URL, if POST, then it will be sent separately). Also, if you are
sending a file using a multipart form, the query string will be created using the
multipart form specifications.
<b>See below for some further information on parameter handling.</b>
<p>
Additionally, you can specify whether each paramter should be URL encoded. If you are not sure what this
means, it is probably best to select it. If your values contain characters such as &amp;amp; or spaces, or
@ -225,6 +226,16 @@ rather than www.example.co.uk, it will not get the correct cookies.
This is generally only a problem for manually created test plans,
as a test plan created using a recorder would continue from the redirected URL.
</p>
<p>
Parameter Handling:<br></br>
For the POST method, if there is no file to send, and the name(s) of the parameter(s) are omitted,
then the body is created by concatenating all the value(s) of the parameters.
The values are encoded if the encoding flag is set (versions of JMeter after 2.3).
<br></br>
For other methods, if the name of the parameter is missing,
then the parameter is ignored. This allows the use of optional parameters defined by variables.
(versions of JMeter after 2.3)
</p>
<p>Upto and including JMeter 2.1.1, only responses with the content-type "text/html" were scanned for
embedded resources. Other content-types were assumed to be something other than HTML.
JMeter 2.1.2 introduces the a new property <b>HTTPResponse.parsers</b>, which is a list of parser ids,