Author: sebb
Date: Sun Mar 30 18:45:15 2008
New Revision: 642854
URL: http://svn.apache.org/viewvc?rev=642854&view=rev
Log:
Implement Bug 41921 for HTTP Samplers
Modified:
jakarta/jmeter/trunk/docs/images/screenshots/webtest/http-request.png
jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
jakarta/jmeter/trunk/xdocs/changes.xml
jakarta/jmeter/trunk/xdocs/images/screenshots/webtest/http-request.png
jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml
Modified: jakarta/jmeter/trunk/docs/images/screenshots/webtest/http-request.png
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/docs/images/screenshots/webtest/http-request.png?rev=642854&r1=642853&r2=642854&view=diff
==============================================================================
Binary files - no diff available.
Modified:
jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=642854&r1=642853&r2=642854&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
(original)
+++
jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
Sun Mar 30 18:45:15 2008
@@ -611,6 +611,7 @@
report_writer_html=HTML Report Writer
request_data=Request Data
reset_gui=Reset Gui
+response_save_as_md5=Save response as MD5 hash?
restart=Restart
resultaction_title=Result Status Action Handler
resultsaver_errors=Save Failed Responses only
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java?rev=642854&r1=642853&r2=642854&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java
Sun Mar 30 18:45:15 2008
@@ -48,7 +48,9 @@
private JCheckBox isMon;
- private JLabeledTextField embeddedRE; // regular expression used to
match against embedded resource URLs
+ private JCheckBox useMD5;
+
+ private JLabeledTextField embeddedRE; // regular expression used to match
against embedded resource URLs
public HttpTestSampleGui() {
init();
@@ -60,6 +62,7 @@
final HTTPSamplerBase samplerBase = (HTTPSamplerBase) element;
getImages.setSelected(samplerBase.isImageParser());
isMon.setSelected(samplerBase.isMonitor());
+ useMD5.setSelected(samplerBase.useMD5());
embeddedRE.setText(samplerBase.getEmbeddedUrlRE());
}
@@ -87,6 +90,7 @@
sampler.removeProperty(HTTPSamplerBase.IMAGE_PARSER);
}
samplerBase.setMonitor(isMon.isSelected());
+ samplerBase.setMD5(useMD5.isSelected());
samplerBase.setEmbeddedUrlRE(embeddedRE.getText());
this.configureTestElement(sampler);
}
@@ -120,9 +124,14 @@
getImages = new
JCheckBox(JMeterUtils.getResString("web_testing_retrieve_images")); //
$NON-NLS-1$
// Is monitor
isMon = new
JCheckBox(JMeterUtils.getResString("monitor_is_title")); // $NON-NLS-1$
- checkBoxPanel.add(getImages);
+ // Use MD5
+ useMD5 = new
JCheckBox(JMeterUtils.getResString("response_save_as_md5")); // $NON-NLS-1$
+
+ checkBoxPanel.add(getImages);
checkBoxPanel.add(isMon);
- optionalTasksPanel.add(checkBoxPanel);
+ checkBoxPanel.add(useMD5);
+ optionalTasksPanel.add(checkBoxPanel);
+
// Embedded URL match regex
embeddedRE = new
JLabeledTextField(JMeterUtils.getResString("web_testing_embedded_url_pattern"),30);
// $NON-NLS-1$
optionalTasksPanel.add(embeddedRE);
@@ -142,6 +151,7 @@
super.clearGui();
getImages.setSelected(false);
isMon.setSelected(false);
+ useMD5.setSelected(false);
urlConfigGui.clear();
embeddedRE.setText(""); // $NON-NLS-1$
}
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java?rev=642854&r1=642853&r2=642854&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java
Sun Mar 30 18:45:15 2008
@@ -17,7 +17,6 @@
package org.apache.jmeter.protocol.http.sampler;
import java.io.BufferedInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -198,10 +197,10 @@
* if an I/O exception occurs
*/
protected byte[] readResponse(HttpURLConnection conn, SampleResult res)
throws IOException {
- byte[] readBuffer = getThreadContext().getReadBuffer();
BufferedInputStream in;
- if ((conn.getContentLength() == 0)
+ final int contentLength = conn.getContentLength();
+ if ((contentLength == 0)
&& JMeterUtils.getPropDefault("httpsampler.obey_contentlength",
// $NON-NLS-1$
false)) {
log.info("Content-Length: 0, not reading http-body");
@@ -250,20 +249,7 @@
}
in = new BufferedInputStream(conn.getErrorStream());
}
- java.io.ByteArrayOutputStream w = new ByteArrayOutputStream();
- int x = 0;
- boolean first = true;
- while ((x = in.read(readBuffer)) > -1) {
- if (first) {
- res.latencyEnd();
- first = false;
- }
- w.write(readBuffer, 0, x);
- }
- in.close();
- w.flush();
- w.close();
- return w.toByteArray();
+ return readResponse(res, in, contentLength);
}
/**
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java?rev=642854&r1=642853&r2=642854&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
Sun Mar 30 18:45:15 2008
@@ -830,25 +830,7 @@
if (responseHeader!= null &&
ENCODING_GZIP.equals(responseHeader.getValue())) {
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);
- }
-
- res.setResponseData(outstream.toByteArray());
- outstream.close();
-
+ res.setResponseData(readResponse(res, instream, (int)
httpMethod.getResponseContentLength()));
}
res.sampleEnd();
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java?rev=642854&r1=642853&r2=642854&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
Sun Mar 30 18:45:15 2008
@@ -19,12 +19,15 @@
import java.io.ByteArrayOutputStream;
import java.io.FileReader;
import java.io.IOException;
+import java.io.InputStream;
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.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -153,6 +156,9 @@
public final static String MONITOR = "HTTPSampler.monitor"; //
$NON-NLS-1$
+ // Store MD5 hash instead of storing response
+ private final static String MD5 = "HTTPSampler.md5"; // $NON-NLS-1$
+
/** A number to indicate that the port has not been set. */
public static final int UNSPECIFIED_PORT = 0;
public static final String UNSPECIFIED_PORT_AS_STRING = "0"; // $NON-NLS-1$
@@ -440,6 +446,14 @@
return this.getPropertyAsString(IMPLEMENTATION);
}
+ public boolean useMD5() {
+ return this.getPropertyAsBoolean(MD5, false);
+ }
+
+ public void setMD5(boolean truth) {
+ this.setProperty(MD5, truth, false);
+ }
+
/**
* Add an argument which has already been encoded
*/
@@ -1333,6 +1347,65 @@
public void threadStarted(){
}
public void threadFinished(){
+ }
+
+ /**
+ * Read response from the input stream, converting to MD5 digest if the
useMD5 property is set.
+ *
+ * For the MD5 case, the result byte count is set to the size of the
original response.
+ *
+ * @param sampleResult
+ * @param in input stream
+ * @param length expected input length or zero
+ * @return the response or the MD5 of the response
+ * @throws IOException
+ */
+ public byte[] readResponse(SampleResult sampleResult, InputStream in, int
length) throws IOException {
+
+ byte[] readBuffer = getThreadContext().getReadBuffer();
+ int bufferSize=32;// Enough for MD5
+
+ MessageDigest md=null;
+ boolean asMD5 = useMD5();
+ if (asMD5) {
+ try {
+ md = MessageDigest.getInstance("MD5"); //$NON-NLS-1$
+ } catch (NoSuchAlgorithmException e) {
+ log.error("Should not happen - could not find MD5 digest", e);
+ asMD5=false;
+ }
+ } else {
+ if (length <= 0) {// may also happen if long value > int.max
+ bufferSize = 4 * 1024;
+ } else {
+ bufferSize = length;
+ }
+ }
+ ByteArrayOutputStream w = new ByteArrayOutputStream(bufferSize);
+ int bytesRead = 0;
+ int totalBytes = 0;
+ boolean first = true;
+ while ((bytesRead = in.read(readBuffer)) > -1) {
+ if (first) {
+ sampleResult.latencyEnd();
+ first = false;
+ }
+ if (asMD5 && md != null) {
+ md.update(readBuffer, 0 , bytesRead);
+ totalBytes += bytesRead;
+ } else {
+ w.write(readBuffer, 0, bytesRead);
+ }
+ }
+ in.close();
+ w.flush();
+ if (asMD5 && md != null) {
+ byte[] md5Result = md.digest();
+ w.write(JOrphanUtils.baToHexString(md5Result).getBytes());
+ sampleResult.setBytes(totalBytes);
+ }
+ w.close();
+ return w.toByteArray();
}
}
Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=642854&r1=642853&r2=642854&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Sun Mar 30 18:45:15 2008
@@ -131,6 +131,7 @@
<li>Bug 42204 - add thread group name to Aggregate and Summary reports</li>
<li>FTP Sampler sets latency = time to login</li>
<li>FTP Sampler sets a URL if it can</li>
+<li>Bug 41921 - add option for samplers to store MD5 of response; done for
HTTP Samplers.</li>
</ul>
<h4>Non-functional changes</h4>
Modified: jakarta/jmeter/trunk/xdocs/images/screenshots/webtest/http-request.png
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/images/screenshots/webtest/http-request.png?rev=642854&r1=642853&r2=642854&view=diff
==============================================================================
Binary files - no diff available.
Modified: jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=642854&r1=642853&r2=642854&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml Sun Mar 30
18:45:15 2008
@@ -81,7 +81,7 @@
</component>
-<component name="HTTP Request" index="§-num;.1.2" width="688"
height="592" screenshot="webtest/http-request.png">
+<component name="HTTP Request" index="§-num;.1.2" width="683"
height="590" screenshot="webtest/http-request.png">
<description>
<p>This sampler lets you send an HTTP/HTTPS request to a web server.
It
@@ -233,6 +233,11 @@
See below for more details.
</property>
<property name="Use as monitor" required="Yes">For use with the
<complink name="Monitor Results"/> listener.</property>
+ <property name="Save response as MD5 hash?" required="Yes">
+ If this is selected, then the response is not stored in the sample
result.
+ Instead, the 32 character MD5 hash of the data is calculated and stored
instead.
+ This is intended for testing large amounts of data.
+ </property>
<property name="Embedded URLs must match:" required="No">
If present, this must be a regular expression that is used to match
against any embedded URLs found.
So if you only want to download embedded resources from
http://example.com/, use the expression:
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]