Author: milamber
Date: Mon Apr 4 19:30:40 2011
New Revision: 1088748
URL: http://svn.apache.org/viewvc?rev=1088748&view=rev
Log:
Simplify new properties to change method to calculate getBytes()
Save Headers size and Content-length on sample (in HTTPSampleResult) instead of
calculting when gets results
Modified:
jakarta/jmeter/trunk/bin/jmeter.properties
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java
jakarta/jmeter/trunk/xdocs/changes.xml
jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml
Modified: jakarta/jmeter/trunk/bin/jmeter.properties
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/bin/jmeter.properties?rev=1088748&r1=1088747&r2=1088748&view=diff
==============================================================================
--- jakarta/jmeter/trunk/bin/jmeter.properties (original)
+++ jakarta/jmeter/trunk/bin/jmeter.properties Mon Apr 4 19:30:40 2011
@@ -247,10 +247,11 @@ log_level.jorphan=INFO
#---------------------------------------------------------------------------
# Response size calculate method
-# default: only data (uncompress size if deflate)
-#http.getbytes.type=default
-#http.getbytes.type=calculate_headers_size+default
-#http.getbytes.type=calculate_headers_size+content-length_value
+# Include headers: add the headers size in total of response size
+# Use Content-Length: if web server uses a deflate/gzip module,
+# gets the value of Content-Length to get response size rather uncompressed
length
+#http.getbytes.include.headers=true
+#http.getbytes.use.contentlength=true
#---------------------------------------------------------------------------
# HTTP Java configuration
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java?rev=1088748&r1=1088747&r2=1088748&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java
Mon Apr 4 19:30:40 2011
@@ -289,6 +289,14 @@ public class HTTPHC3Impl extends HTTPHCA
res.setRedirectLocation(headerLocation.getValue());
}
+ // record some sizes to allow HTTPSampleResult.getBytes() with
different options
+ res.setContentLength((int) httpMethod.getResponseContentLength());
+ res.setHeadersSize(calculateHeadersSize(httpMethod));
+ if (log.isDebugEnabled()) {
+ log.debug("ResponseHeadersSize=" + res.getHeadersSize() + "
Content-Length=" + res.getContentLength()
+ + " Total=" + (res.getHeadersSize() +
res.getContentLength()));
+ }
+
// If we redirected automatically, the URL may have changed
if (getAutoRedirects()){
res.setURL(new URL(httpMethod.getURI().toString()));
@@ -325,6 +333,25 @@ public class HTTPHC3Impl extends HTTPHCA
}
}
}
+
+ /**
+ * Calculate response headers size
+ *
+ * @return the size response headers (in bytes)
+ */
+ private static int calculateHeadersSize(HttpMethodBase httpMethod) {
+ int headerSize = 0;
+ headerSize += 9 // Http proto length + 1 space (i.e.: "HTTP/1.x ")
+ + String.valueOf(httpMethod.getStatusCode()).length() + 1 //
add one space
+ + httpMethod.getStatusText().length() + 2; // add a \r\n
+ Header[] rh = httpMethod.getResponseHeaders();
+ for (int i = 0; i < rh.length; i++) {
+ headerSize += (rh[i]).toString().length(); // already include the
\r\n
+ }
+ headerSize += 2; // last \r\n before response data
+ // add response data length to headerSize
+ return headerSize;
+ }
/**
* Returns an <code>HttpConnection</code> fully ready to attempt
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java?rev=1088748&r1=1088747&r2=1088748&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
Mon Apr 4 19:30:40 2011
@@ -262,6 +262,15 @@ public class HTTPHC4Impl extends HTTPHCA
res.setRedirectLocation(headerLocation.getValue());
}
+ // record some sizes to allow HTTPSampleResult.getBytes() with
different options
+ res.setContentLength((int) entity.getContentLength());
+ res.setHeadersSize(res.getResponseHeaders().replaceAll("\n",
"\r\n") // $NON-NLS-1$ $NON-NLS-2$
+ .length() + 2); // add 2 for a '\r\n' at end of headers
(before data)
+ if (log.isDebugEnabled()) {
+ log.debug("ResponseHeadersSize=" + res.getHeadersSize() + "
Content-Length=" + res.getContentLength()
+ + " Total=" + (res.getHeadersSize() +
res.getContentLength()));
+ }
+
// If we redirected automatically, the URL may have changed
if (getAutoRedirects()){
HttpUriRequest req = (HttpUriRequest)
localContext.getAttribute(ExecutionContext.HTTP_REQUEST);
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java?rev=1088748&r1=1088747&r2=1088748&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java
Mon Apr 4 19:30:40 2011
@@ -556,11 +556,22 @@ public class HTTPJavaImpl extends HTTPAb
res.setEncodingAndType(ct);
}
- res.setResponseHeaders(getResponseHeaders(conn));
+ String responseHeaders = getResponseHeaders(conn);
+ res.setResponseHeaders(responseHeaders);
if (res.isRedirect()) {
res.setRedirectLocation(conn.getHeaderField(HEADER_LOCATION));
}
-
+
+ // record some sizes to allow HTTPSampleResult.getBytes() with
different options
+ String contentLength = conn.getHeaderField(HEADER_CONTENT_LENGTH);
+ res.setContentLength(contentLength != null ?
Integer.parseInt(contentLength) : 0); // 0 to getBytes with responseData length
+ res.setHeadersSize(responseHeaders.replaceAll("\n", "\r\n") //
$NON-NLS-1$ $NON-NLS-2$
+ .length() + 2); // add 2 for a '\r\n' at end of headers
(before data)
+ if (log.isDebugEnabled()) {
+ log.debug("ResponseHeadersSize=" + res.getHeadersSize() + "
Content-Length=" + res.getContentLength()
+ + " Total=" + (res.getHeadersSize() +
res.getContentLength()));
+ }
+
// If we redirected automatically, the URL may have changed
if (getAutoRedirects()){
res.setURL(conn.getURL());
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java?rev=1088748&r1=1088747&r2=1088748&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java
Mon Apr 4 19:30:40 2011
@@ -33,18 +33,22 @@ public class HTTPSampleResult extends Sa
private static final long serialVersionUID = 240L;
- private static final String GETBYTES_TYPE_DEFAULT = "default";
+ private static final boolean GETBYTES_INCLUDE_HEADERS =
+ JMeterUtils.getPropDefault("http.getbytes.include.headers", false); //
$NON-NLS-1$
- private static final String GETBYTES_TYPE_HEAD_CONTENTLENGTH =
"calculate_headers_size+content-length_value";
-
- private static final String GETBYTES_TYPE_HEAD_DEFAULT =
"calculate_headers_size+default";
+ private static final boolean GETBYTES_USE_CONTENTLENGTH =
+ JMeterUtils.getPropDefault("http.getbytes.use.contentlength", false);
// $NON-NLS-1$
- private static final String GETBYTES_TYPE =
- JMeterUtils.getPropDefault("http.getbytes.type",
GETBYTES_TYPE_DEFAULT); // $NON-NLS-1$
+ private static final boolean GETBYTES_HEADERS_CONTENTLENGTH =
+ GETBYTES_INCLUDE_HEADERS && GETBYTES_USE_CONTENTLENGTH ? true : false;
private String cookies = ""; // never null
private String method;
+
+ private int headersSize = 0;
+
+ private int contentLength = 0;
/**
* The raw value of the Location: header; may be null.
@@ -225,6 +229,38 @@ public class HTTPSampleResult extends Sa
setResponseCode(HTTP_NO_CONTENT_CODE);
setResponseMessage(HTTP_NO_CONTENT_MSG);
}
+
+ /**
+ * Set the headers size in bytes
+ *
+ * @param size
+ */
+ public void setHeadersSize(int size) {
+ this.headersSize = size;
+ }
+
+ /**
+ * Get the headers size in bytes
+ *
+ * @return the headers size
+ */
+ public int getHeadersSize() {
+ return headersSize;
+ }
+
+ /**
+ * @return the contentLength
+ */
+ public int getContentLength() {
+ return contentLength == 0 ? super.getBytes() : contentLength;
+ }
+
+ /**
+ * @param contentLength the contentLength to set
+ */
+ public void setContentLength(int contentLength) {
+ this.contentLength = contentLength;
+ }
/*
* (non-Javadoc)
@@ -233,28 +269,14 @@ public class HTTPSampleResult extends Sa
*/
@Override
public int getBytes() {
- if (GETBYTES_TYPE.equals(GETBYTES_TYPE_HEAD_CONTENTLENGTH)) {
- return calculateHeadersSize()
- +
JMeterUtils.getHeaderContentLength(this.getResponseHeaders());
- }
- if (GETBYTES_TYPE.equals(GETBYTES_TYPE_HEAD_DEFAULT)) {
- return calculateHeadersSize() + super.getBytes();
+ if (GETBYTES_HEADERS_CONTENTLENGTH) {
+ return headersSize + contentLength;
+ } else if (GETBYTES_INCLUDE_HEADERS) {
+ return headersSize + super.getBytes();
+ } else if (GETBYTES_USE_CONTENTLENGTH) {
+ return contentLength;
}
return super.getBytes(); // Default
}
-
- /**
- * Calculate response headers size
- *
- * @return the size response headers (in bytes)
- */
- private int calculateHeadersSize() {
- int headersSize = 0;
- headersSize += 9 // Http proto length + 1 space (i.e.: "HTTP/1.x ")
- + String.valueOf(this.getResponseCode()).length()
- + this.getResponseMessage().length();
- headersSize += this.getResponseHeaders().length();
- return headersSize;
- }
}
Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=1088748&r1=1088747&r2=1088748&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Mon Apr 4 19:30:40 2011
@@ -150,7 +150,7 @@ Fixed RMI startup to provide location of
<li>Allow HTTP implementation to be selected at run-time</li>
<li>Bug 50684 - Optionally disable Content-Type and Transfer-Encoding in
Multipart POST</li>
<li>Bug 50943 - Allowing concurrent downloads of embedded resources in html
page</li>
-<li>Bug 50170 - Bytes reported by http sampler is after GUnZip<br></br>Add an
optional property to allow change the method to get response size</li>
+<li>Bug 50170 - Bytes reported by http sampler is after GUnZip<br></br>Add
optional properties to allow change the method to get response size</li>
</ul>
<h3>Other samplers</h3>
Modified: jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1088748&r1=1088747&r2=1088748&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml Mon Apr 4
19:30:40 2011
@@ -334,14 +334,12 @@ The HttpClient version of the sampler su
#httpclient.socket.https.cps=0
</pre>
<p><b>Method to calculate Response size</b><br></br>
-An optional property to allow change the method to get response size:<br></br>
-<ul><li>Default behavior: Size in bytes is the response data length (without
response headers)
-<pre>http.getbytes.type=default</pre></li>
-<li>Response headers length and default (response data length)
-<pre>http.getbytes.type=calculate_headers_size+default</pre></li>
-<li>Response headers length and value of "Content-length" header (generally
provide by web server)<br></br>
+Optional properties to allow change the method to get response size:<br></br>
+<ul><li>Include the headers length with the response data length
+<pre>http.getbytes.include.headers=false</pre></li>
+<li>Uses value of "Content-length" header (generally provide by web server),
rather than decompressed response data length<br></br>
Useful when web server uses a deflate/gzip method to compress response data
-<pre>http.getbytes.type=calculate_headers_size+content-length_value</pre></li></ul>
+<pre>http.getbytes.use.contentlength=false</pre></li></ul>
</p>
<links>
<link href="test_plan.html#assertions">Assertion</link>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]