Author: fschumacher
Date: Mon Feb 29 19:20:08 2016
New Revision: 1732937

URL: http://svn.apache.org/viewvc?rev=1732937&view=rev
Log:
HTTP Request : Make Method field editable so that additional methods (Webdav) 
can be added easily

Bugzilla Id: 59083

Modified:
    jmeter/trunk/bin/jmeter.properties
    
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java
    
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/sampler/HttpWebdav.java
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/usermanual/component_reference.xml

Modified: jmeter/trunk/bin/jmeter.properties
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/bin/jmeter.properties?rev=1732937&r1=1732936&r2=1732937&view=diff
==============================================================================
--- jmeter/trunk/bin/jmeter.properties (original)
+++ jmeter/trunk/bin/jmeter.properties Mon Feb 29 19:20:08 2016
@@ -1002,6 +1002,9 @@ beanshell.server.file=../extras/startup.
 # default to false
 #httpsampler.embedded_resources_use_md5=false
 
+# List of extra HTTP methods that should be available in select box
+#httpsampler.user_defined_methods=VERSION-CONTROL,REPORT,CHECKOUT,CHECKIN,UNCHECKOUT,MKWORKSPACE,UPDATE,LABEL,MERGE,BASELINE-CONTROL,MKACTIVITY
+
 # The encoding to be used if none is provided (default ISO-8859-1)
 #sampleresult.default.encoding=ISO-8859-1
 

Modified: 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java?rev=1732937&r1=1732936&r2=1732937&view=diff
==============================================================================
--- 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java
 (original)
+++ 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java
 Mon Feb 29 19:20:08 2016
@@ -627,7 +627,7 @@ public class UrlConfigGui extends JPanel
 
         if (notConfigOnly){
             method = new JLabeledChoice(JMeterUtils.getResString("method"), // 
$NON-NLS-1$
-                    HTTPSamplerBase.getValidMethodsAsArray());
+                    HTTPSamplerBase.getValidMethodsAsArray(), true);
             method.addChangeListener(this);
         }
 

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=1732937&r1=1732936&r2=1732937&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
 Mon Feb 29 19:20:08 2016
@@ -490,10 +490,11 @@ public class HTTPHC4Impl extends HTTPHCA
         if (method.equals(HTTPConstants.POST)) {
             String postBody = sendPostData((HttpPost)httpRequest);
             result.setQueryString(postBody);
-        } else if (method.equals(HTTPConstants.PUT) || 
method.equals(HTTPConstants.PATCH)
-                || HttpWebdav.isWebdavMethod(method)
-                || method.equals(HTTPConstants.DELETE)) {
-            String entityBody = sendEntityData(( 
HttpEntityEnclosingRequestBase)httpRequest);
+        } else if (method.equals(HTTPConstants.PUT)
+                || method.equals(HTTPConstants.PATCH)
+                || method.equals(HTTPConstants.DELETE)
+                || HttpWebdav.isWebdavMethod(method)) {
+            String entityBody = 
sendEntityData((HttpEntityEnclosingRequestBase) httpRequest);
             result.setQueryString(entityBody);
         }
     }

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=1732937&r1=1732936&r2=1732937&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
 Mon Feb 29 19:20:08 2016
@@ -226,29 +226,36 @@ public abstract class HTTPSamplerBase ex
     }
 
     public static final String DEFAULT_METHOD = HTTPConstants.GET; // 
$NON-NLS-1$
-    // Supported methods:
-    private static final String [] METHODS = {
-        DEFAULT_METHOD, // i.e. GET
-        HTTPConstants.POST,
-        HTTPConstants.HEAD,
-        HTTPConstants.PUT,
-        HTTPConstants.OPTIONS,
-        HTTPConstants.TRACE,
-        HTTPConstants.DELETE,
-        HTTPConstants.PATCH,
-        HTTPConstants.PROPFIND,
-        HTTPConstants.PROPPATCH,
-        HTTPConstants.MKCOL,
-        HTTPConstants.COPY,
-        HTTPConstants.MOVE,
-        HTTPConstants.LOCK,
-        HTTPConstants.UNLOCK,
-        HTTPConstants.REPORT,
-        HTTPConstants.MKCALENDAR,
-        HTTPConstants.SEARCH
-        };
 
-    private static final List<String> METHODLIST = 
Collections.unmodifiableList(Arrays.asList(METHODS));
+    private static final List<String> METHODLIST;
+    static {
+        List<String> defaultMethods = new ArrayList<>(Arrays.asList(
+            DEFAULT_METHOD, // i.e. GET
+            HTTPConstants.POST,
+            HTTPConstants.HEAD,
+            HTTPConstants.PUT,
+            HTTPConstants.OPTIONS,
+            HTTPConstants.TRACE,
+            HTTPConstants.DELETE,
+            HTTPConstants.PATCH,
+            HTTPConstants.PROPFIND,
+            HTTPConstants.PROPPATCH,
+            HTTPConstants.MKCOL,
+            HTTPConstants.COPY,
+            HTTPConstants.MOVE,
+            HTTPConstants.LOCK,
+            HTTPConstants.UNLOCK,
+            HTTPConstants.REPORT,
+            HTTPConstants.MKCALENDAR,
+            HTTPConstants.SEARCH
+        ));
+        String userDefinedMethods = JMeterUtils.getPropDefault(
+                "httpsampler.user_defined_methods", "");
+        if (StringUtils.isNotBlank(userDefinedMethods)) {
+            
defaultMethods.addAll(Arrays.asList(userDefinedMethods.split("\\s*,\\s*")));
+        }
+        METHODLIST = Collections.unmodifiableList(defaultMethods);
+    }
 
     // @see mergeFileProperties
     // Must be private, as the file list needs special handling

Modified: 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HttpWebdav.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HttpWebdav.java?rev=1732937&r1=1732936&r2=1732937&view=diff
==============================================================================
--- 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HttpWebdav.java
 (original)
+++ 
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HttpWebdav.java
 Mon Feb 29 19:20:08 2016
@@ -19,38 +19,25 @@
 package org.apache.jmeter.protocol.http.sampler;
 
 import java.net.URI;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
 
 import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
-import org.apache.jmeter.protocol.http.util.HTTPConstants;
 
 /**
  * WebDav request
+ *
  * @since 2.12
  */
 public final class HttpWebdav extends HttpEntityEnclosingRequestBase {
-    private static final Set<String> WEBDAV_METHODS =
-            new HashSet<>(Arrays.asList(
-                    HTTPConstants.PROPFIND,
-                    HTTPConstants.PROPPATCH,
-                    HTTPConstants.MKCOL,
-                    HTTPConstants.COPY,
-                    HTTPConstants.MOVE,
-                    HTTPConstants.LOCK,
-                    HTTPConstants.UNLOCK,
-                    HTTPConstants.REPORT,
-                    HTTPConstants.MKCALENDAR,
-                    HTTPConstants.SEARCH
-            ));
-    
-    private String davMethod;
+
+    private final String davMethod;
 
     /**
      * 
-     * @param davMethod method to use (has to be a Webdav method as identified 
by {@link #isWebdavMethod(String)})
-     * @param uri {@link URI} to use
+     * @param davMethod
+     *            method to use (has to be a Webdav method as identified by
+     *            {@link #isWebdavMethod(String)})
+     * @param uri
+     *            {@link URI} to use
      */
     public HttpWebdav(final String davMethod, final URI uri) {
         super();
@@ -64,10 +51,13 @@ public final class HttpWebdav extends Ht
     }
 
     /**
-     * @param method Http Method
+     * @param method
+     *            Http Method
      * @return <code>true</code> if method is a Webdav one
      */
     public static boolean isWebdavMethod(String method) {
-        return WEBDAV_METHODS.contains(method);
+        // A HTTP method can be a token as specified in
+        // https://tools.ietf.org/html/rfc7230#section-3.2.6
+        return method != null && 
method.matches("^(?i)[\\da-z!#$%&'*+\\-.^_`|~]+$");
     }
 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1732937&r1=1732936&r2=1732937&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Mon Feb 29 19:20:08 2016
@@ -127,6 +127,7 @@ Summary
     <li><bug>59036</bug>FormCharSetFinder : Use JSoup instead of deprecated 
HTMLParser</li>
     <li><bug>59034</bug>Parallel downloads connection management is not 
realistic. Contributed by Benoit Wiart (benoit dot wiart at gmail.com) and 
Philippe Mouawad</li>
     <li><bug>59060</bug>HTTP Request GUI : Move File Upload to a new Tab to 
have more space for parameters and prevent incoherent configuration. 
Contributed by Benoit Wiart (benoit dot wiart at gmail.com)</li>
+    <li><bug>59083</bug>HTTP Request : Make Method field editable so that 
additional methods (Webdav) can be added easily</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=1732937&r1=1732936&r2=1732937&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Mon Feb 29 19:20:08 
2016
@@ -232,7 +232,10 @@ https.default.protocol=SSLv3
           <code>JAVA</code> implementation). With <code>HttpClient4</code>, 
the following methods related to WebDav are
           also allowed: <code>COPY</code>, <code>LOCK</code>, 
<code>MKCOL</code>, <code>MOVE</code>,
           <code>PROPFIND</code>, <code>PROPPATCH</code>, <code>UNLOCK</code>, 
<code>REPORT</code>, <code>MKCALENDAR</code>,
-          <code>SEARCH</code>.</property>
+          <code>SEARCH</code>.
+          <p>More methods can be pre-defined for the HttpClient4 by using the 
JMeter property
+            <code>httpsampler.user_defined_methods</code>.</p>
+        </property>
         <property name="Content Encoding" required="No">
         Content encoding to be used (for <code>POST</code>, <code>PUT</code>, 
<code>PATCH</code> and <code>FILE</code>).
         This is the character encoding to be used, and is not related to the 
Content-Encoding HTTP header.


Reply via email to