cziegeler 2002/12/18 00:25:12 Modified: src/java/org/apache/cocoon/reading Tag: cocoon_2_0_3_branch ResourceReader.java . Tag: cocoon_2_0_3_branch changes.xml src/java/org/apache/cocoon/environment/http Tag: cocoon_2_0_3_branch HttpEnvironment.java Log: Fixing bug 12915 <action dev="CZ" type="fix" fixes-bug="12915"> The resource reader now checks if for the same URI the same source is read in order to test the if-last-modified header. This behaviour can be turned of (for more performance) by the quick-modified-test. </action> Revision Changes Path No revision No revision 1.7.2.3 +37 -9 xml-cocoon2/src/java/org/apache/cocoon/reading/ResourceReader.java Index: ResourceReader.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/reading/ResourceReader.java,v retrieving revision 1.7.2.2 retrieving revision 1.7.2.3 diff -u -r1.7.2.2 -r1.7.2.3 --- ResourceReader.java 5 Jun 2002 01:36:11 -0000 1.7.2.2 +++ ResourceReader.java 18 Dec 2002 08:25:11 -0000 1.7.2.3 @@ -50,6 +50,10 @@ */ package org.apache.cocoon.reading; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; import org.apache.avalon.framework.parameters.Parameters; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.caching.CacheValidity; @@ -57,17 +61,13 @@ import org.apache.cocoon.caching.TimeStampCacheValidity; import org.apache.cocoon.environment.Context; import org.apache.cocoon.environment.ObjectModelHelper; +import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.Response; import org.apache.cocoon.environment.Source; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.util.HashUtil; import org.xml.sax.SAXException; -import java.io.IOException; -import java.io.InputStream; -import java.util.Date; -import java.util.Map; - /** * The <code>ResourceReader</code> component is used to serve binary data * in a sitemap pipeline. It makes use of HTTP Headers to determine if @@ -81,19 +81,30 @@ * in miliseconds the resources can be cached by any proxy or browser * between Cocoon2 and the requesting visitor. * </dd> + * <dt><quick-modified-test></dt> + * <dd>This parameter is optional. This boolean parameter controlls the + * last modified test. If set to true (default is false), only the + * last modified of the current source is tested, but not if the + * same source is used as last time. + * </dd> * </dl> * * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a> * @version CVS $Id$ */ -public class ResourceReader +public final class ResourceReader extends AbstractReader implements Cacheable { /** The source */ private Source inputSource; - + /** The list of generated documents */ + private static final Map documents = new HashMap(); + + /** quick test */ + private boolean quickTest; + /** * Setup the reader. * The resource is opened to get an <code>InputStream</code>, @@ -102,6 +113,7 @@ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException { super.setup(resolver, objectModel, src, par); + this.quickTest = par.getParameterAsBoolean("quick-modified-test", false); this.inputSource = this.resolver.resolve(super.source); } @@ -144,7 +156,17 @@ * possible to detect */ public long getLastModified() { - return this.inputSource.getLastModified(); + if (this.quickTest) { + return this.inputSource.getLastModified(); + } + final Request request = ObjectModelHelper.getRequest(this.objectModel); + final String systemId = (String)documents.get(request.getRequestURI()); + if (this.inputSource.getSystemId().equals(systemId)) { + return this.inputSource.getLastModified(); + } else { + documents.remove(request.getRequestURI()); + return 0; + } } /** @@ -180,6 +202,12 @@ inputStream.close(); inputStream = null; out.flush(); + + if (!this.quickTest) { + // if everything is ok, add this to the list of generated documents + final Request request = ObjectModelHelper.getRequest(this.objectModel); + documents.put(request.getRequestURI(), this.inputSource.getSystemId()); + } } /** No revision No revision 1.138.2.78 +6 -1 xml-cocoon2/changes.xml Index: changes.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/changes.xml,v retrieving revision 1.138.2.77 retrieving revision 1.138.2.78 diff -u -r1.138.2.77 -r1.138.2.78 --- changes.xml 16 Dec 2002 14:58:56 -0000 1.138.2.77 +++ changes.xml 18 Dec 2002 08:25:11 -0000 1.138.2.78 @@ -40,6 +40,11 @@ </devs> <release version="@version@" date="@date@"> + <action dev="CZ" type="fix" fixes-bug="12915"> + The resource reader now checks if for the same URI the same source is read + in order to test the if-last-modified header. This behaviour can be turned + of (for more performance) by the quick-modified-test. + </action> <action dev="CH" type="update"> AbstractJXPathModule / JXPathMetaModule default to lenient mode i.e. do not throw an exception on unsupported attributes but return null instead. Made No revision No revision 1.12.2.4 +1 -6 xml-cocoon2/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java Index: HttpEnvironment.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java,v retrieving revision 1.12.2.3 retrieving revision 1.12.2.4 diff -u -r1.12.2.3 -r1.12.2.4 --- HttpEnvironment.java 29 Oct 2002 04:48:59 -0000 1.12.2.3 +++ HttpEnvironment.java 18 Dec 2002 08:25:11 -0000 1.12.2.4 @@ -249,15 +249,10 @@ * environment is not able to test it */ public boolean isResponseModified(long lastModified) { - // workaround for bug #12915 - // FIXME - return true; - /* long if_modified_since = this.request.getDateHeader("If-Modified-Since"); this.response.setDateHeader("Last-Modified", lastModified); return (if_modified_since < lastModified); - */ } /**
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]