You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2006/04/29 20:54:35 UTC
svn commit: r398219 - in
/jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler:
HTTPSampler2.java HTTPSamplerBase.java
Author: sebb
Date: Sat Apr 29 11:54:34 2006
New Revision: 398219
URL: http://svn.apache.org/viewcvs?rev=398219&view=rev
Log:
Add support for HEAD and PUT methods
PUT may need further work
Modified:
jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
Modified: jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java?rev=398219&r1=398218&r2=398219&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java Sat Apr 29 11:54:34 2006
@@ -45,8 +45,10 @@
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.HeadMethod;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.jmeter.JMeter;
@@ -160,6 +162,8 @@
/**
* Constructor for the HTTPSampler2 object.
+ *
+ * Consider using HTTPSamplerFactory.newInstance() instead
*/
public HTTPSampler2() {
}
@@ -534,6 +538,10 @@
if (method.equals(POST)) {
httpMethod = new PostMethod(urlStr);
+ } else if (method.equals(PUT)){
+ httpMethod = new PutMethod(urlStr);
+ } else if (method.equals(HEAD)){
+ httpMethod = new HeadMethod(urlStr);
} else {
httpMethod = new GetMethod(urlStr);
}
@@ -544,7 +552,7 @@
} else {
res.setMonitor(false);
}
- res.setSampleLabel(urlStr);
+ res.setSampleLabel(urlStr); // May be replaced later
res.setHTTPMethod(method);
res.sampleStart(); // Count the retries as well in the time
HttpClient client = null;
@@ -561,28 +569,32 @@
// Request sent. Now get the response:
InputStream instream = httpMethod.getResponseBodyAsStream();
- if (ENCODING_GZIP.equals(httpMethod.getResponseHeader(TRANSFER_ENCODING))) {
- instream = new GZIPInputStream(instream);
- }
-
- //int contentLength = httpMethod.getResponseContentLength();Not visible ...
- //TODO size ouststream according to actual content length
- ByteArrayOutputStream outstream = new ByteArrayOutputStream(4*1024);
- //contentLength > 0 ? contentLength : DEFAULT_INITIAL_BUFFER_SIZE);
- byte[] buffer = new byte[4096];
- int len;
- boolean first = true;// first response
- while ((len = instream.read(buffer)) > 0) {
- if (first) { // save the latency
- res.latencyEnd();
- first = false;
+ if (instream != null) {// will be null for HEAD
+
+ if (ENCODING_GZIP.equals(httpMethod.getResponseHeader(TRANSFER_ENCODING))) {
+ instream = new GZIPInputStream(instream);
+ }
+
+ //int contentLength = httpMethod.getResponseContentLength();Not visible ...
+ //TODO size ouststream according to actual content length
+ ByteArrayOutputStream outstream = new ByteArrayOutputStream(4*1024);
+ //contentLength > 0 ? contentLength : DEFAULT_INITIAL_BUFFER_SIZE);
+ byte[] buffer = new byte[4096];
+ int len;
+ boolean first = true;// first response
+ while ((len = instream.read(buffer)) > 0) {
+ if (first) { // save the latency
+ res.latencyEnd();
+ first = false;
+ }
+ outstream.write(buffer, 0, len);
}
- outstream.write(buffer, 0, len);
+
+ res.setResponseData(outstream.toByteArray());
+ outstream.close();
+
}
- outstream.close();
- byte[] responseData = outstream.toByteArray();
-
res.sampleEnd();
// Done with the sampling proper.
@@ -591,8 +603,6 @@
res.setSampleLabel(httpMethod.getURI().toString());
// Pick up Actual path (after redirects)
- res.setResponseData(responseData);
-
res.setResponseCode(Integer.toString(statusCode));
res.setSuccessful(isSuccessCode(statusCode));
Modified: jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java?rev=398219&r1=398218&r2=398219&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java Sat Apr 29 11:54:34 2006
@@ -20,7 +20,10 @@
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.Iterator;
+import java.util.List;
import org.apache.jmeter.config.Argument;
import org.apache.jmeter.config.Arguments;
@@ -75,7 +78,7 @@
public final static String METHOD = "HTTPSampler.method"; // $NON-NLS-1$
- public final static String PATH = "HTTPSampler.path"; // $NON-NLS-1$
+ public final static String PATH = "HTTPSampler.path"; // $NON-NLS-1$
public final static String FOLLOW_REDIRECTS = "HTTPSampler.follow_redirects"; // $NON-NLS-1$
@@ -91,10 +94,26 @@
public final static String URL = "HTTPSampler.URL"; // $NON-NLS-1$
+ public final static String HEAD = "HEAD"; // $NON-NLS-1$
+
public final static String POST = "POST"; // $NON-NLS-1$
+ public final static String PUT = "PUT"; // $NON-NLS-1$
+
public final static String GET = "GET"; // $NON-NLS-1$
+ public final static String DEFAULT_METHOD = "GET"; // $NON-NLS-1$
+ // Supported methods:
+ private final static String [] METHODS = {
+ DEFAULT_METHOD,
+ HEAD,
+ POST,
+ PUT,
+ };
+
+ public final static List METHODLIST = Collections.unmodifiableList(Arrays.asList(METHODS));
+
+
public final static String USE_KEEPALIVE = "HTTPSampler.use_keepalive"; // $NON-NLS-1$
public final static String FILE_NAME = "HTTPSampler.FILE_NAME"; // $NON-NLS-1$
@@ -830,5 +849,9 @@
*/
protected boolean isSuccessCode(int code){
return (code >= 200 && code <= 399);
+ }
+
+ public static String[] getValidMethodsAsArray(){
+ return (String[]) METHODLIST.toArray(new String[0]);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org