You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2007/10/08 22:29:37 UTC

svn commit: r582954 - in /jakarta/jmeter/trunk: src/protocol/http/org/apache/jmeter/protocol/http/sampler/ xdocs/ xdocs/usermanual/

Author: sebb
Date: Mon Oct  8 13:29:35 2007
New Revision: 582954

URL: http://svn.apache.org/viewvc?rev=582954&view=rev
Log:
HTTP Parameters without names are ignored (except for POST requests with no file)
Parameters used to build a POST body are encoded if specified.

Modified:
    jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
    jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
    jakarta/jmeter/trunk/xdocs/changes.xml
    jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml

Modified: jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java?rev=582954&r1=582953&r2=582954&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java (original)
+++ jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java Mon Oct  8 13:29:35 2007
@@ -274,7 +274,11 @@
             // 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 @@
                 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 @@
                 // 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 @@
                         // 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
@@ -406,17 +430,6 @@
 //                    StringRequestEntity requestEntity = new StringRequestEntity(getQueryString(contentEncoding), post.getRequestHeader(HEADER_CONTENT_TYPE).getValue(), contentCharSet);
 //                    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

Modified: jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java?rev=582954&r1=582953&r2=582954&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java (original)
+++ jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java Mon Oct  8 13:29:35 2007
@@ -774,12 +774,16 @@
                 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 {

Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=582954&r1=582953&r2=582954&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Mon Oct  8 13:29:35 2007
@@ -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>

Modified: jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=582954&r1=582953&r2=582954&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml Mon Oct  8 13:29:35 2007
@@ -192,6 +192,7 @@
         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
@@ -224,6 +225,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.



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org