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 2007/05/04 15:56:33 UTC
svn commit: r535241 - in /jakarta/jmeter/branches/rel-2-2:
src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
xdocs/changes.xml xdocs/usermanual/component_reference.xml
Author: sebb
Date: Fri May 4 06:56:32 2007
New Revision: 535241
URL: http://svn.apache.org/viewvc?view=rev&rev=535241
Log:
Add "file:" protocol handling to HTTP Sampler (for testing)
Modified:
jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml
jakarta/jmeter/branches/rel-2-2/xdocs/usermanual/component_reference.xml
Modified: jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java?view=diff&rev=535241&r1=535240&r2=535241
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java (original)
+++ jakarta/jmeter/branches/rel-2-2/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java Fri May 4 06:56:32 2007
@@ -17,10 +17,13 @@
package org.apache.jmeter.protocol.http.sampler;
import java.io.ByteArrayOutputStream;
+import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
@@ -29,6 +32,7 @@
import java.util.List;
import java.util.Map;
+import org.apache.commons.io.IOUtils;
import org.apache.jmeter.config.Argument;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.engine.event.LoopIterationEvent;
@@ -103,6 +107,8 @@
public static final String PROTOCOL_HTTPS = "https"; // $NON-NLS-1$
+ private static final String PROTOCOL_FILE = "file"; // $NON-NLS-1$
+
public final static String DEFAULT_PROTOCOL = PROTOCOL_HTTP;
public final static String URL = "HTTPSampler.URL"; // $NON-NLS-1$
@@ -828,12 +834,61 @@
public SampleResult sample() {
SampleResult res = null;
try {
- res = sample(getUrl(), getMethod(), false, 0);
+ if (PROTOCOL_FILE.equalsIgnoreCase(getProtocol())){
+ res = fileSample(new URI(PROTOCOL_FILE,getPath(),null));
+ } else {
+ res = sample(getUrl(), getMethod(), false, 0);
+ }
res.setSampleLabel(getName());
return res;
} catch (MalformedURLException e) {
return errorResult(e, new HTTPSampleResult());
+ } catch (IOException e) {
+ return errorResult(e, new HTTPSampleResult());
+ } catch (URISyntaxException e) {
+ return errorResult(e, new HTTPSampleResult());
+ }
+ }
+
+ private HTTPSampleResult fileSample(URI uri) throws IOException {
+
+ String urlStr = uri.toString();
+
+
+ HTTPSampleResult res = new HTTPSampleResult();
+ res.setMonitor(isMonitor());
+ res.setHTTPMethod(GET); // Dummy
+ res.setURL(new URL(urlStr));
+ res.setSampleLabel(urlStr);
+ FileReader reader = null;
+ res.sampleStart();
+ try {
+ byte[] responseData;
+ StringBuffer ctb=new StringBuffer("text/html"); // $NON-NLS-1$
+ reader = new FileReader(getPath());
+ String contentEncoding = getContentEncoding();
+ if (contentEncoding.length() == 0) {
+ responseData = IOUtils.toByteArray(reader);
+ } else {
+ ctb.append("; charset="); // $NON-NLS-1$
+ ctb.append(contentEncoding);
+ responseData = IOUtils.toByteArray(reader,contentEncoding);
+ }
+ res.sampleEnd();
+ res.setResponseData(responseData);
+ res.setResponseCodeOK();
+ res.setResponseMessage(""); // TODO - what should this be?
+ res.setSuccessful(true);
+ String ct = ctb.toString();
+ res.setContentType(ct);
+ res.setEncodingAndType(ct);
+ } finally {
+ IOUtils.closeQuietly(reader);
}
+
+ //res.setResponseHeaders("");
+
+ return res;
}
/**
Modified: jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml?view=diff&rev=535241&r1=535240&r2=535241
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml (original)
+++ jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml Fri May 4 06:56:32 2007
@@ -139,6 +139,7 @@
<li>Bug 42223 - Add ability to upload files via FTP</li>
<li>Extend JDBC Sampler: Commit, Rollback, AutoCommit</li>
<li>Bug 42247 - improve HCI</li>
+<li>Support "file" protocol in HTTP Samplers</li>
</ul>
<h4>Non-functional improvements:</h4>
Modified: jakarta/jmeter/branches/rel-2-2/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/xdocs/usermanual/component_reference.xml?view=diff&rev=535241&r1=535240&r2=535241
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/xdocs/usermanual/component_reference.xml (original)
+++ jakarta/jmeter/branches/rel-2-2/xdocs/usermanual/component_reference.xml Fri May 4 06:56:32 2007
@@ -113,7 +113,8 @@
See Java bugs 6226610 and 6208335.
</li>
</ul>
-
+ <p>Note: the FILE protocol is intended for testing puposes only.
+ It is handled by the same code regardless of which HTTP Sampler is used.</p>
<p>If the request requires server or proxy login authorization (i.e. where a browser would create a pop-up dialog box),
you will also have to add an <complink name="HTTP Authorization Manager"/> Configuration Element.
For normal logins (i.e. where the user enters login information in a form), you will need to work out what the form submit button does,
@@ -137,8 +138,9 @@
<property name="Name" required="No">Descriptive name for this controller that is shown in the tree.</property>
<property name="Server" required="No">Domain name or IP address of the web server.</property>
<property name="Port" required="No">Port the web server is listening to. Default: 80</property>
- <property name="Protocol" required="No">HTTP or HTTPS. Default: HTTP</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="Content Encoding" required="No">Content encoding to be used (for POST and FILE)</property>
<property name="Redirect Automatically" required="Yes">
Sets the underlying http protocol handler to automatically follow redirects,
so they are not seen by JMeter, and thus will not appear as samples.
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org