jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1769364 - in /jmeter/trunk: src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java xdocs/changes.xml xdocs/usermanual/component_reference.xml
Date Sat, 12 Nov 2016 00:17:59 GMT
Author: pmouawad
Date: Sat Nov 12 00:17:58 2016
New Revision: 1769364

URL: http://svn.apache.org/viewvc?rev=1769364&view=rev
Log:
Bug 60358 - Http Request : Allow sending Body Data for HTTP GET request
Put back the mention of bug delete in r1769202
Update documentation which was wrong for DELETE and update it for GET
Bugzilla Id: 60358

Modified:
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/usermanual/component_reference.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=1769364&r1=1769363&r2=1769364&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
Sat Nov 12 00:17:58 2016
@@ -111,6 +111,7 @@ import org.apache.http.protocol.HTTP;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpCoreContext;
 import org.apache.http.util.CharArrayBuffer;
+import org.apache.jmeter.config.Arguments;
 import org.apache.jmeter.protocol.http.control.AuthManager;
 import org.apache.jmeter.protocol.http.control.CacheManager;
 import org.apache.jmeter.protocol.http.control.CookieManager;
@@ -308,6 +309,22 @@ public class HTTPHC4Impl extends HTTPHCA
     protected HTTPHC4Impl(HTTPSamplerBase testElement) {
         super(testElement);
     }
+    
+    /**
+     * Implementation that allows GET method to have a body
+     */
+    public static final class HttpGetWithEntity extends HttpEntityEnclosingRequestBase {
+
+        public HttpGetWithEntity(final URI uri) {
+            super();
+            setURI(uri);
+        }
+
+        @Override
+        public String getMethod() {
+            return HTTPConstants.GET;
+        }
+    }
 
     public static final class HttpDelete extends HttpEntityEnclosingRequestBase {
 
@@ -341,7 +358,15 @@ public class HTTPHC4Impl extends HTTPHCA
             if (method.equals(HTTPConstants.POST)) {
                 httpRequest = new HttpPost(uri);
             } else if (method.equals(HTTPConstants.GET)) {
-                httpRequest = new HttpGet(uri);
+                // Some servers fail if Content-Length is equal to 0
+                // so to avoid this we use HttpGet when there is no body (Content-Length
will not be set)
+                // otherwise we use HttpGetWithEntity
+                if ( (!hasArguments() && getSendFileAsPostBody()) 
+                        || getSendParameterValuesAsPostBody() ) {
+                    httpRequest = new HttpGetWithEntity(uri);
+                } else {
+                    httpRequest = new HttpGet(uri);
+                }
             } else if (method.equals(HTTPConstants.PUT)) {
                 httpRequest = new HttpPut(uri);
             } else if (method.equals(HTTPConstants.HEAD)) {
@@ -1391,8 +1416,6 @@ public class HTTPHC4Impl extends HTTPHCA
      * @throws IOException cannot really occur for ByteArrayOutputStream methods
      */
     protected String sendEntityData( HttpEntityEnclosingRequestBase entity) throws IOException
{
-        // Buffer to hold the entity body
-        StringBuilder entityBody = new StringBuilder(1000);
         boolean hasEntityBody = false;
 
         final HTTPFileArg[] files = getHTTPFiles();
@@ -1427,8 +1450,9 @@ public class HTTPHC4Impl extends HTTPHCA
             hasEntityBody = true;
 
             // Just append all the parameter values, and use that as the entity body
-            StringBuilder entityBodyContent = new StringBuilder();
-            for (JMeterProperty jMeterProperty : getArguments()) {
+            Arguments arguments = getArguments();
+            StringBuilder entityBodyContent = new StringBuilder(arguments.getArgumentCount()*15);
+            for (JMeterProperty jMeterProperty : arguments) {
                 HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue();
                 // Note: if "Encoded?" is not selected, arg.getEncodedValue is equivalent
to arg.getValue
                 if (charset != null) {
@@ -1445,18 +1469,25 @@ public class HTTPHC4Impl extends HTTPHCA
             // If the request entity is repeatable, we can send it first to
             // our own stream, so we can return it
             final HttpEntity entityEntry = entity.getEntity();
+            // Buffer to hold the entity body
+            StringBuilder entityBody = null;
             if(entityEntry.isRepeatable()) {
+                entityBody = new StringBuilder(1000);
+                // FIXME Charset
                 entityBody.append(IOUtils.toString(new BoundedInputStream(
                         entityEntry.getContent(), MAX_BODY_RETAIN_SIZE)));
                 if (entityEntry.getContentLength() > MAX_BODY_RETAIN_SIZE) {
                     entityBody.append("<actual file content shortened>");
                 }
             }
-            else { // this probably cannot happen
+            else { 
+                entityBody = new StringBuilder(65);
+                // this probably cannot happen
                 entityBody.append("<RequestEntity was not repeatable, cannot view what
was sent>");
             }
+            return entityBody.toString();
         }
-        return entityBody.toString(); // may be the empty string
+        return ""; // may be the empty string
     }
 
     /**

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java?rev=1769364&r1=1769363&r2=1769364&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java
(original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java
Sat Nov 12 00:17:58 2016
@@ -36,12 +36,11 @@ import org.apache.jmeter.samplers.Sample
  */
 public class HTTPSampleResult extends SampleResult {
 
-    private static final long serialVersionUID = 240L;
+    private static final long serialVersionUID = 241L;
 
     /** Set of all HTTP methods, that have no body */
     private static final Set<String> METHODS_WITHOUT_BODY = new HashSet<>(
             Arrays.asList(
-                    HTTPConstants.GET,
                     HTTPConstants.HEAD,
                     HTTPConstants.OPTIONS,
                     HTTPConstants.TRACE));

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1769364&r1=1769363&r2=1769364&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Sat Nov 12 00:17:58 2016
@@ -179,6 +179,7 @@ This allows you to update Think Times fr
     <li><bug>53039</bug>HTTP Request : Be able to handle responses which
size exceeds <code>2147483647</code> bytes (that is 2GB)</li>
     <li><bug>60265</bug>HTTP Request : In Files Upload Tab you cannot resize
columns</li>
     <li><bug>60318</bug>Ignore CSS warnings when parsing with ph-css library.</li>
+    <li><bug>60358</bug>Http Request : Allow sending Body Data for HTTP
GET request</li>
 </ul>
 
 <h3>Other samplers</h3>
@@ -232,6 +233,7 @@ This allows you to update Think Times fr
 <h3>I18N</h3>
 <ul>
     <li><pr>214</pr>Add spanish translation for delayed starting of threads.
Contributed by Asier Lostalé (asier.lostale at openbravo.com).</li>
+    <li><bug>60348</bug>Change chinese translation for <code>Save
as</code>. Contributed by XMeter (support at xmeter.net).</li>
 </ul>
 
 <h3>Report / Dashboard</h3>

Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1769364&r1=1769363&r2=1769364&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Sat Nov 12 00:17:58 2016
@@ -381,7 +381,7 @@ For other methods, if the name of the pa
 then the parameter is ignored. This allows the use of optional parameters defined by variables.
 </p>
 <br/>
-<p>You have the option to switch to Post Body when a request has only unnamed parameters
+<p>You have the option to switch to <code>Body Data</code> tab when a request
has only unnamed parameters
 (or no parameters at all).
 This option is useful in the following cases (amongst others):</p>
 <ul>
@@ -391,10 +391,10 @@ This option is useful in the following c
 <li>SOAP HTTP Request</li>
 </ul>
 <note>
-Note that once you leave the Tree node, you cannot switch back to the parameter tab unless
you clear the Post Body tab of data.
+Note that once you leave the Tree node, you cannot switch back to the parameter tab unless
you clear the <code>Body Data</code> tab from its data.
 </note>
 <p>
-In Post Body mode, each line will be sent with <code>CRLF</code> appended, apart
from the last line.
+In <code>Body Data</code> mode, each line will be sent with <code>CRLF</code>
appended, apart from the last line.
 To send a <code>CRLF</code> after the last line of data, just ensure that there
is an empty line following it.
 (This cannot be seen, except by noting whether the cursor can be placed on the subsequent
line.)
 </p>
@@ -404,20 +404,19 @@ To send a <code>CRLF</code> after the la
 
 <p>
 <b>Method Handling:</b><br></br>
-The <code>POST</code>, <code>PUT</code> and <code>PATCH</code>
request methods work similarly, except that the <code>PUT</code> and <code>PATCH</code>
methods do not support multipart requests
+The <code>GET</code>, <code>DELETE</code>, <code>POST</code>,
<code>PUT</code> and <code>PATCH</code> request methods work similarly,
except that as of 3.1, only <code>POST</code> method supports multipart requests
 or file upload.
-The <code>PUT</code> and <code>PATCH</code> method body must be provided
as one of the following:</p>
+The <code>GET</code>, <code>DELETE</code>, <code>POST</code>,
<code>PUT</code> and <code>PATCH</code> method body must be provided
as one of the following:</p>
 <ul>
 <li>define the body as a file with empty Parameter name field; in which case the MIME
Type is used as the Content-Type</li>
 <li>define the body as parameter value(s) with no name</li>
-<li>use the Post Body tab</li>
+<li>use the <code>Body Data</code> tab</li>
 </ul>
 <p>
 If you define any parameters with a name in either the sampler or HTTP
 defaults then nothing is sent.
-<code>PUT</code> and <code>PATCH</code> require a Content-Type.
+<code>GET</code>, <code>DELETE</code>, <code>PUT</code>
and <code>PATCH</code> require a Content-Type.
 If not using a file, attach a Header Manager to the sampler and define the Content-Type there.
-The <code>GET</code> and <code>DELETE</code> request methods work
similarly to each other.
 </p>
 <p>JMeter scan responses from embedded resources. It uses the property <code>HTTPResponse.parsers</code>,
which is a list of parser ids,
  e.g. <code>htmlParser</code> and <code>wmlParser</code>. For each
id found, JMeter checks two further properties:</p>



Mime
View raw message