View | Details | Raw Unified | Return to bug 47461
Collapse All | Expand All

(-)src/core/org/apache/jmeter/util/JMeterVersion.java (-1 / +1 lines)
Lines 44-50 Link Here
44
	 * This ensures that JMeterUtils always gets the correct
44
	 * This ensures that JMeterUtils always gets the correct
45
	 * version, even if JMeterUtils is not re-compiled during the build.
45
	 * version, even if JMeterUtils is not re-compiled during the build.
46
	 */
46
	 */
47
	private static final String VERSION = "2.3.2 r665936";
47
	private static final String VERSION = "2.3.2.20090216";
48
48
49
	static final String COPYRIGHT = "Copyright (c) 1998-2008 The Apache Software Foundation";
49
	static final String COPYRIGHT = "Copyright (c) 1998-2008 The Apache Software Foundation";
50
50
(-)src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java (-8 / +49 lines)
Lines 26-31 Link Here
26
import java.net.URLConnection;
26
import java.net.URLConnection;
27
import java.util.HashMap;
27
import java.util.HashMap;
28
import java.util.Map;
28
import java.util.Map;
29
import java.util.Date;
30
import java.text.SimpleDateFormat;
29
31
30
import org.apache.commons.httpclient.Header;
32
import org.apache.commons.httpclient.Header;
31
import org.apache.commons.httpclient.HttpMethod;
33
import org.apache.commons.httpclient.HttpMethod;
Lines 48-53 Link Here
48
50
49
	public static final String CLEAR = "clearEachIteration"; // $NON-NLS-1$
51
	public static final String CLEAR = "clearEachIteration"; // $NON-NLS-1$
50
52
53
	private static final SimpleDateFormat expiresDateFormat = new java.text.SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
54
	
51
	private transient ThreadLocal threadCache;
55
	private transient ThreadLocal threadCache;
52
	
56
	
53
	public CacheManager() {
57
	public CacheManager() {
Lines 61-74 Link Here
61
	 */
65
	 */
62
	private static class CacheEntry{
66
	private static class CacheEntry{
63
	    private final String lastModified;
67
	    private final String lastModified;
68
	    private final String expires;
64
	    private final String etag;
69
	    private final String etag;
65
	    public CacheEntry(String lastModified, String etag){
70
	    public CacheEntry(String lastModified, String expires, String etag){
66
	       this.lastModified = lastModified;
71
	       this.lastModified = lastModified;
72
	       this.expires = expires;
67
	       this.etag = etag;
73
	       this.etag = etag;
68
	   }
74
	   }
69
        public String getLastModified() {
75
        public String getLastModified() {
70
            return lastModified;
76
            return lastModified;
71
        }
77
        }
78
        public String getExpires() {
79
            return expires;
80
        }
72
        public String getEtag() {
81
        public String getEtag() {
73
            return etag;
82
            return etag;
74
        }
83
        }
Lines 78-84 Link Here
78
	}
87
	}
79
88
80
	/**
89
	/**
81
	 * Save the Last-Modified and Etag headers if the result is cacheable.
90
	 * Save the Last-Modified, Etag, and Expires headers if the result is cacheable.
82
	 * 
91
	 * 
83
	 * @param conn connection
92
	 * @param conn connection
84
	 * @param res result
93
	 * @param res result
Lines 86-99 Link Here
86
	public void saveDetails(URLConnection conn, SampleResult res){
95
	public void saveDetails(URLConnection conn, SampleResult res){
87
	    if (isCacheable(res)){
96
	    if (isCacheable(res)){
88
	        String lastModified = conn.getHeaderField(HTTPConstantsInterface.LAST_MODIFIED);
97
	        String lastModified = conn.getHeaderField(HTTPConstantsInterface.LAST_MODIFIED);
98
	        String expires = conn.getHeaderField(HTTPConstantsInterface.EXPIRES);
89
	        String etag = conn.getHeaderField(HTTPConstantsInterface.ETAG);
99
	        String etag = conn.getHeaderField(HTTPConstantsInterface.ETAG);
90
	        String url = conn.getURL().toString();
100
	        String url = conn.getURL().toString();
91
	        setCache(lastModified, etag, url);	        
101
	        setCache(lastModified, expires, etag, url);	        
92
	    }
102
	    }
93
	}
103
	}
94
104
95
    /**
105
    /**
96
     * Save the Last-Modified and Etag headers if the result is cacheable.
106
     * Save the Last-Modified, Etag, and Expires headers if the result is cacheable.
97
     * 
107
     * 
98
     * @param method
108
     * @param method
99
     * @param res result
109
     * @param res result
Lines 101-118 Link Here
101
    public void saveDetails(HttpMethod method, SampleResult res) throws URIException{
111
    public void saveDetails(HttpMethod method, SampleResult res) throws URIException{
102
        if (isCacheable(res)){
112
        if (isCacheable(res)){
103
            String lastModified = getHeader(method ,HTTPConstantsInterface.LAST_MODIFIED);
113
            String lastModified = getHeader(method ,HTTPConstantsInterface.LAST_MODIFIED);
114
            String expires = getHeader(method ,HTTPConstantsInterface.EXPIRES);
104
            String etag = getHeader(method ,HTTPConstantsInterface.ETAG);
115
            String etag = getHeader(method ,HTTPConstantsInterface.ETAG);
105
            String url = method.getURI().toString();
116
            String url = method.getURI().toString();
106
            setCache(lastModified, etag, url);
117
            setCache(lastModified, expires, etag, url);
107
        }
118
        }
108
    }
119
    }
109
120
110
    // helper method to save the cache entry
121
    // helper method to save the cache entry
111
    private void setCache(String lastModified, String etag, String url) {
122
    private void setCache(String lastModified, String expires, String etag, String url) {
112
        if (log.isDebugEnabled()){
123
        if (log.isDebugEnabled()){
113
            log.debug("SET(both) "+url + " " + lastModified + " " + etag);
124
            log.debug("SET(both) "+url + " " + lastModified + " " + " " + expires + " " + etag);
114
        }
125
        }
115
        getCache().put(url, new CacheEntry(lastModified, etag));
126
        getCache().put(url, new CacheEntry(lastModified, expires, etag));
116
    }
127
    }
117
128
118
    // Helper method to deal with missing headers
129
    // Helper method to deal with missing headers
Lines 179-184 Link Here
179
        }
190
        }
180
    }
191
    }
181
192
193
    
194
    /**
195
     * Check the cache, if the entry has an expires header and the entry has not expired, return true<br/>
196
     * @param url URL to look up in cache
197
     */
198
    public boolean inCache(URL url) {
199
        CacheEntry entry = (CacheEntry) getCache().get(url.toString());
200
        if (log.isDebugEnabled()){
201
            log.debug("inCache "+url.toString()+" "+entry);
202
        }
203
        if (entry != null){
204
            final String expires = entry.getExpires();
205
            if (expires != null){
206
            	java.util.Date expiresDate = null;
207
            	try { expiresDate = expiresDateFormat.parse(expires); } catch (Exception e) { }
208
            	if (expiresDate != null) {
209
	                if (expiresDate.after(new Date())) {
210
	                    if (log.isDebugEnabled()){
211
	                    	log.debug("Expires= " + expiresDate + " (Valid)");
212
	                    }
213
	                	return true;
214
	                } else if (log.isDebugEnabled()){
215
	                   	log.debug("Expires= " + expiresDate + " (Expired)");
216
	                }
217
            	}
218
            }
219
        }
220
        return false;
221
    }
222
    
182
    private Map getCache(){
223
    private Map getCache(){
183
        return (Map) threadCache.get();
224
        return (Map) threadCache.get();
184
    }
225
    }
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java (-1 / +19 lines)
Lines 133-138 Link Here
133
	 *                if an I/O Exception occurs
133
	 *                if an I/O Exception occurs
134
	 */
134
	 */
135
	protected HttpURLConnection setupConnection(URL u, String method, HTTPSampleResult res) throws IOException {
135
	protected HttpURLConnection setupConnection(URL u, String method, HTTPSampleResult res) throws IOException {
136
		
136
        SSLManager sslmgr = null;
137
        SSLManager sslmgr = null;
137
        if (PROTOCOL_HTTPS.equalsIgnoreCase(u.getProtocol())) {
138
        if (PROTOCOL_HTTPS.equalsIgnoreCase(u.getProtocol())) {
138
            try {
139
            try {
Lines 419-424 Link Here
419
        
420
        
420
		res.setSampleLabel(urlStr);
421
		res.setSampleLabel(urlStr);
421
		res.sampleStart(); // Count the retries as well in the time
422
		res.sampleStart(); // Count the retries as well in the time
423
424
        // Check cache for an entry with an Expires header in the future
425
        CacheManager cacheManager = getCacheManager();
426
        if (cacheManager != null) {
427
	        if (cacheManager.inCache(url)) {
428
	        	// The below works in my tests to short-circuit running the sample, 
429
	        	//   but I don't know if this is the proper way to do that.
430
	            log.debug(url.toString() + " In cache, valid");
431
				res.sampleEnd();
432
			    res.setResponseCode("OK");
433
			    res.setSuccessful(true);
434
			    res.setResponseMessage("in cache");
435
	            return res;
436
	        } else {
437
	            log.debug(url.toString() + " Not in cache, or expired");
438
	        }
439
        }
440
        
422
		try {
441
		try {
423
			// Sampling proper - establish the connection and read the response:
442
			// Sampling proper - establish the connection and read the response:
424
			// Repeatedly try to connect:
443
			// Repeatedly try to connect:
Lines 520-526 Link Here
520
			saveConnectionCookies(conn, url, getCookieManager());
539
			saveConnectionCookies(conn, url, getCookieManager());
521
540
522
            // Save cache information
541
            // Save cache information
523
            final CacheManager cacheManager = getCacheManager();
524
            if (cacheManager != null){
542
            if (cacheManager != null){
525
                cacheManager.saveDetails(conn, res);
543
                cacheManager.saveDetails(conn, res);
526
            }
544
            }
(-)src/protocol/http/org/apache/jmeter/protocol/http/util/HTTPConstantsInterface.java (+1 lines)
Lines 60-64 Link Here
60
    public static final String IF_MODIFIED_SINCE = "If-Modified-Since"; // $NON-NLS-1$
60
    public static final String IF_MODIFIED_SINCE = "If-Modified-Since"; // $NON-NLS-1$
61
    public static final String ETAG = "Etag"; // $NON-NLS-1$
61
    public static final String ETAG = "Etag"; // $NON-NLS-1$
62
    public static final String LAST_MODIFIED = "Last-Modified"; // $NON-NLS-1$
62
    public static final String LAST_MODIFIED = "Last-Modified"; // $NON-NLS-1$
63
    public static final String EXPIRES = "Expires"; // $NON-NLS-1$
63
64
64
}
65
}

Return to bug 47461