HTTP Request : Make Method field editable so that additional methods (Webdav) can be added easily

Bugzilla Id: 59083


git-svn-id: https://svn.apache.org/repos/asf/jmeter/trunk@1733521 13f79535-47bb-0310-9956-ffa450edef68

Former-commit-id: 814dd75956
This commit is contained in:
Felix Schumacher 2016-03-03 20:55:33 +00:00
parent 1bbd7be6c6
commit c2cbfee7f1
7 changed files with 63 additions and 56 deletions

View File

@ -987,6 +987,9 @@ beanshell.server.file=../extras/startup.bsh
# 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

View File

@ -627,7 +627,7 @@ public class UrlConfigGui extends JPanel implements ChangeListener {
if (notConfigOnly){
method = new JLabeledChoice(JMeterUtils.getResString("method"), // $NON-NLS-1$
HTTPSamplerBase.getValidMethodsAsArray());
HTTPSamplerBase.getValidMethodsAsArray(), true);
method.addChangeListener(this);
}

View File

@ -487,13 +487,11 @@ public class HTTPHC4Impl extends HTTPHCAbstractImpl {
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);
}
}

View File

@ -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 SampleResult {
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 SampleResult {
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");

View File

@ -226,29 +226,36 @@ public abstract class HTTPSamplerBase extends AbstractSampler
}
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

View File

@ -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 HttpEntityEnclosingRequestBase {
}
/**
* @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!#$%&'*+\\-.^_`|~]+$");
}
}

View File

@ -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.