You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by se...@apache.org on 2012/08/23 04:00:35 UTC

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

Author: sebb
Date: Thu Aug 23 02:00:34 2012
New Revision: 1376344

URL: http://svn.apache.org/viewvc?rev=1376344&view=rev
Log:
Add PATCH verb to HTTP sampler
Bugzilla Id: 53675

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/HTTPSamplerBase.java
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/HTTPConstantsInterface.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=1376344&r1=1376343&r2=1376344&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 Thu Aug 23 02:00:34 2012
@@ -55,9 +55,11 @@ import org.apache.http.client.HttpClient
 import org.apache.http.client.HttpRequestRetryHandler;
 import org.apache.http.client.entity.UrlEncodedFormEntity;
 import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpHead;
 import org.apache.http.client.methods.HttpOptions;
+import org.apache.http.client.methods.HttpPatch;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.client.methods.HttpPut;
 import org.apache.http.client.methods.HttpRequestBase;
@@ -241,6 +243,8 @@ public class HTTPHC4Impl extends HTTPHCA
                 httpRequest = new HttpDelete(uri);
             } else if (method.equals(HTTPConstants.GET)) {
                 httpRequest = new HttpGet(uri);
+            } else if (method.equals(HTTPConstants.PATCH)) {
+                httpRequest = new HttpPatch(uri);
             } else {
                 throw new IllegalArgumentException("Unexpected method: "+method);
             }
@@ -272,8 +276,8 @@ public class HTTPHC4Impl extends HTTPHCA
             if (method.equals(HTTPConstants.POST)) {
                 String postBody = sendPostData((HttpPost)httpRequest);
                 res.setQueryString(postBody);
-            } else if (method.equals(HTTPConstants.PUT)) {
-                String putBody = sendPutData((HttpPut)httpRequest);
+            } else if (method.equals(HTTPConstants.PUT) || method.equals(HTTPConstants.PATCH)) {
+                String putBody = sendPutData(( HttpEntityEnclosingRequestBase)httpRequest);
                 res.setQueryString(putBody);
             }
             HttpResponse httpResponse = httpClient.execute(httpRequest, localContext); // perform the sample
@@ -1001,7 +1005,7 @@ public class HTTPHC4Impl extends HTTPHCA
     // e.g. post checks for multipart form/files, and if not, invokes sendData(HttpEntityEnclosingRequestBase)
 
     // TODO - implementation not fully tested
-    private String sendPutData(HttpPut put) throws IOException {
+    private String sendPutData( HttpEntityEnclosingRequestBase put) throws IOException {
         // Buffer to hold the put body, except file content
         StringBuilder putBody = new StringBuilder(1000);
         boolean hasPutBody = false;

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java?rev=1376344&r1=1376343&r2=1376344&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java Thu Aug 23 02:00:34 2012
@@ -199,6 +199,7 @@ public abstract class HTTPSamplerBase ex
         HTTPConstants.OPTIONS,
         HTTPConstants.TRACE,
         HTTPConstants.DELETE,
+        HTTPConstants.PATCH,
         };
 
     private static final List<String> METHODLIST = Collections.unmodifiableList(Arrays.asList(METHODS));

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/HTTPConstantsInterface.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/HTTPConstantsInterface.java?rev=1376344&r1=1376343&r2=1376344&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/HTTPConstantsInterface.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/HTTPConstantsInterface.java Thu Aug 23 02:00:34 2012
@@ -38,6 +38,7 @@ public interface HTTPConstantsInterface 
     public static final String OPTIONS = "OPTIONS"; // $NON-NLS-1$
     public static final String TRACE = "TRACE"; // $NON-NLS-1$
     public static final String DELETE = "DELETE"; // $NON-NLS-1$
+    public static final String PATCH = "PATCH"; // $NON-NLS-1$
     public static final String CONNECT = "CONNECT"; // $NON-NLS-1$
     public static final String HEADER_AUTHORIZATION = "Authorization"; // $NON-NLS-1$
     public static final String HEADER_COOKIE = "Cookie"; // $NON-NLS-1$

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1376344&r1=1376343&r2=1376344&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Thu Aug 23 02:00:34 2012
@@ -126,6 +126,7 @@ Shortcut for Function Helper Dialog is n
 
 <h3>HTTP Samplers</h3>
 <ul>
+<li><bugzilla>53675</bugzilla> - Add PATCH verb to HTTP sampler</li>
 </ul>
 
 <h3>Other samplers</h3>

Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1376344&r1=1376343&r2=1376344&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Thu Aug 23 02:00:34 2012
@@ -217,9 +217,9 @@ https.default.protocol=SSLv3
         If not specified (and not defined by HTTP Request Defaults), the default depends on the value of the JMeter property
         <code>jmeter.httpsampler</code>, failing that, the Java implementation is used.</property>
         <property name="Protocol" required="No">HTTP, HTTPS or FILE. Default: HTTP</property>
-        <property name="Method" required="Yes">GET, POST, HEAD, TRACE, OPTIONS, PUT, DELETE</property>
+        <property name="Method" required="Yes">GET, POST, HEAD, TRACE, OPTIONS, PUT, DELETE, PATCH (HC4 only)</property>
         <property name="Content Encoding" required="No">
-        Content encoding to be used (for POST, PUT and FILE). 
+        Content encoding to be used (for POST, PUT, PATCH and FILE). 
         This the the character encoding to be used, and is not related to the Content-Encoding HTTP header.
         </property>
 		<property name="Redirect Automatically" required="No">
@@ -279,7 +279,7 @@ In this case, the server, port and proto
         does not send a file, if filled in, JMeter automatically sends the request as
         a multipart form request.
         <p>
-        If it is a POST or PUT request and there is a single file whose 'name' attribute (below) is omitted, 
+        If it is a POST or PUT or PATCH request and there is a single file whose 'name' attribute (below) is omitted, 
         then the file is sent as the entire body
         of the request, i.e. no wrappers are added. This allows arbitrary bodies to be sent. This functionality is present for POST requests
         after version 2.2, and also for PUT requests after version 2.3.
@@ -364,14 +364,18 @@ To send a CRLF after the last line of da
 
 <p>
 <b>Method Handling:</b><br></br>
-The POST and PUT request methods work similarly, except that the PUT method does not support multipart requests.
-The PUT method body must be provided as one of the following:
+The POST, PUT and PATCH request methods work similarly, except that the PUT and PATCH methods do not support multipart requests
+or file upload.
+The PUT and PATCH method body must be provided as one of the following:
 <ul>
-<li>define the body as a file</li>
+<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>
 </ul>
 If you define any parameters with a name in either the sampler or Http
 defaults then nothing is sent.
+PUT and PATCH require a Content-Type. 
+If not using a file, attach a Header Manager to the sampler and define the Content-Type there.
 The GET and DELETE request methods work similarly to each other.
 </p>
 <p>Upto and including JMeter 2.1.1, only responses with the content-type "text/html" were scanned for