mirror of https://github.com/apache/jmeter.git
Implement Bug 41921 for HTTP Samplers
git-svn-id: https://svn.apache.org/repos/asf/jakarta/jmeter/trunk@642854 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7eb8cd4aa1
commit
6ccc5cf068
Binary file not shown.
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 12 KiB |
|
|
@ -611,6 +611,7 @@ report_writer=Report Writer
|
|||
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
|
||||
|
|
|
|||
|
|
@ -48,7 +48,9 @@ public class HttpTestSampleGui extends AbstractSamplerGui {
|
|||
|
||||
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 @@ public class HttpTestSampleGui extends AbstractSamplerGui {
|
|||
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 @@ public class HttpTestSampleGui extends AbstractSamplerGui {
|
|||
sampler.removeProperty(HTTPSamplerBase.IMAGE_PARSER);
|
||||
}
|
||||
samplerBase.setMonitor(isMon.isSelected());
|
||||
samplerBase.setMD5(useMD5.isSelected());
|
||||
samplerBase.setEmbeddedUrlRE(embeddedRE.getText());
|
||||
this.configureTestElement(sampler);
|
||||
}
|
||||
|
|
@ -120,9 +124,14 @@ public class HttpTestSampleGui extends AbstractSamplerGui {
|
|||
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 @@ public class HttpTestSampleGui extends AbstractSamplerGui {
|
|||
super.clearGui();
|
||||
getImages.setSelected(false);
|
||||
isMon.setSelected(false);
|
||||
useMD5.setSelected(false);
|
||||
urlConfigGui.clear();
|
||||
embeddedRE.setText(""); // $NON-NLS-1$
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 @@ public class HTTPSampler extends HTTPSamplerBase {
|
|||
* 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 @@ public class HTTPSampler extends HTTPSamplerBase {
|
|||
}
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -830,25 +830,7 @@ public class HTTPSampler2 extends HTTPSamplerBase {
|
|||
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();
|
||||
|
|
|
|||
|
|
@ -19,12 +19,15 @@ package org.apache.jmeter.protocol.http.sampler;
|
|||
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 abstract class HTTPSamplerBase extends AbstractSampler
|
|||
|
||||
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 @@ public abstract class HTTPSamplerBase extends AbstractSampler
|
|||
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
|
||||
*/
|
||||
|
|
@ -1334,5 +1348,64 @@ public abstract class HTTPSamplerBase extends AbstractSampler
|
|||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -131,6 +131,7 @@ As a special case, if the HTTP Sampler path starts with "http://" or "https://"
|
|||
<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>
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 12 KiB |
|
|
@ -81,7 +81,7 @@ JMeter assumes the FTP server is listening on the default port.</property>
|
|||
|
||||
</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 @@ and send HTTP/HTTPS requests for all images, Java applets, JavaScript files, CSS
|
|||
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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue