Author: fschumacher
Date: Thu Mar 3 20:55:33 2016
New Revision: 1733521
URL: http://svn.apache.org/viewvc?rev=1733521&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/HTTPSampleResult.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/usermanual/component_reference.xml
Modified: jmeter/trunk/bin/jmeter.properties
URL:
http://svn.apache.org/viewvc/jmeter/trunk/bin/jmeter.properties?rev=1733521&r1=1733520&r2=1733521&view=diff
==============================================================================
--- jmeter/trunk/bin/jmeter.properties (original)
+++ jmeter/trunk/bin/jmeter.properties Thu Mar 3 20:55:33 2016
@@ -987,6 +987,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=1733521&r1=1733520&r2=1733521&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
Thu Mar 3 20:55:33 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=1733521&r1=1733520&r2=1733521&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 Mar 3 20:55:33 2016
@@ -487,13 +487,11 @@ public class HTTPHC4Impl extends HTTPHCA
protected void handleMethod(String method, HTTPSampleResult result,
HttpRequestBase httpRequest, HttpContext localContext) throws
IOException {
// Handle the various methods
- if (method.equals(HTTPConstants.POST)) {
+ if (httpRequest instanceof HttpPost) {
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 (httpRequest instanceof HttpEntityEnclosingRequestBase)
{
+ String entityBody =
sendEntityData((HttpEntityEnclosingRequestBase) httpRequest);
result.setQueryString(entityBody);
}
}
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=1733521&r1=1733520&r2=1733521&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
Thu Mar 3 20:55:33 2016
@@ -22,7 +22,10 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.apache.jmeter.protocol.http.util.HTTPConstants;
import org.apache.jmeter.samplers.SampleResult;
@@ -35,6 +38,12 @@ public class HTTPSampleResult extends Sa
private static final long serialVersionUID = 240L;
+ /** 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.DELETE,
+ HTTPConstants.TRACE));
+
private String cookies = ""; // never null
private String method;
@@ -138,10 +147,7 @@ public class HTTPSampleResult extends Sa
sb.append(u.toString());
sb.append("\n");
// Include request body if it is a post or put or patch
- if (HTTPConstants.POST.equals(method) ||
HTTPConstants.PUT.equals(method)
- || HTTPConstants.PATCH.equals(method)
- || HttpWebdav.isWebdavMethod(method)
- || HTTPConstants.DELETE.equals(method)) {
+ if (!METHODS_WITHOUT_BODY.contains(method)) {
sb.append("\n"+method+" data:\n");
sb.append(queryString);
sb.append("\n");
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=1733521&r1=1733520&r2=1733521&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 Mar 3 20:55:33 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=1733521&r1=1733520&r2=1733521&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
Thu Mar 3 20:55:33 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/usermanual/component_reference.xml
URL:
http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1733521&r1=1733520&r2=1733521&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Thu Mar 3
20:55:33 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.