Author: sebb
Date: Mon Dec 6 11:27:09 2010
New Revision: 1042587
URL: http://svn.apache.org/viewvc?rev=1042587&view=rev
Log:
Add Apache HttpClient support
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java
Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java?rev=1042587&r1=1042586&r2=1042587&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java
Mon Dec 6 11:27:09 2010
@@ -28,11 +28,11 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Date;
-import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.URIException;
import org.apache.commons.httpclient.util.DateParseException;
import org.apache.commons.httpclient.util.DateUtil;
+import org.apache.http.HttpResponse;
import org.apache.jmeter.config.ConfigTestElement;
import org.apache.jmeter.engine.event.LoopIterationEvent;
import org.apache.jmeter.protocol.http.util.HTTPConstantsInterface;
@@ -98,7 +98,7 @@ public class CacheManager extends Config
/**
* Save the Last-Modified, Etag, and Expires headers if the result is
cacheable.
- *
+ * Version for Java implementation.
* @param conn connection
* @param res result
*/
@@ -115,7 +115,7 @@ public class CacheManager extends Config
/**
* Save the Last-Modified, Etag, and Expires headers if the result is
cacheable.
- *
+ * Version for Commons HttpClient implementation.
* @param method
* @param res result
*/
@@ -130,6 +130,23 @@ public class CacheManager extends Config
}
}
+ /**
+ * Save the Last-Modified, Etag, and Expires headers if the result is
cacheable.
+ * Version for Apache HttpClient implementation.
+ * @param method
+ * @param res result
+ */
+ public void saveDetails(HttpResponse method, SampleResult res) {
+ if (isCacheable(res)){
+ method.getLastHeader(USE_EXPIRES);
+ String lastModified = getHeader(method
,HTTPConstantsInterface.LAST_MODIFIED);
+ String expires = getHeader(method ,HTTPConstantsInterface.EXPIRES);
+ String etag = getHeader(method ,HTTPConstantsInterface.ETAG);
+ String cacheControl = getHeader(method,
HTTPConstantsInterface.CACHE_CONTROL);
+ setCache(lastModified, cacheControl, expires, etag,
res.getUrlAsString()); // TODO correct URL?
+ }
+ }
+
// helper method to save the cache entry
private void setCache(String lastModified, String cacheControl, String
expires, String etag, String url) {
if (log.isDebugEnabled()){
@@ -156,9 +173,15 @@ public class CacheManager extends Config
getCache().put(url, new CacheEntry(lastModified, expiresDate, etag));
}
- // Helper method to deal with missing headers
+ // Helper method to deal with missing headers - Commons HttpClient
private String getHeader(HttpMethod method, String name){
- Header hdr = method.getResponseHeader(name);
+ org.apache.commons.httpclient.Header hdr =
method.getResponseHeader(name);
+ return hdr != null ? hdr.getValue() : null;
+ }
+
+ // Apache HttpClient
+ private String getHeader(HttpResponse method, String name) {
+ org.apache.http.Header hdr = method.getLastHeader(name);
return hdr != null ? hdr.getValue() : null;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]