Return-Path: Delivered-To: apmail-tapestry-commits-archive@locus.apache.org Received: (qmail 16100 invoked from network); 16 Jun 2007 21:37:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Jun 2007 21:37:36 -0000 Received: (qmail 68405 invoked by uid 500); 16 Jun 2007 21:37:39 -0000 Delivered-To: apmail-tapestry-commits-archive@tapestry.apache.org Received: (qmail 68229 invoked by uid 500); 16 Jun 2007 21:37:38 -0000 Mailing-List: contact commits-help@tapestry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tapestry.apache.org Delivered-To: mailing list commits@tapestry.apache.org Received: (qmail 68215 invoked by uid 99); 16 Jun 2007 21:37:38 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Jun 2007 14:37:38 -0700 Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Jun 2007 14:37:34 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id BA2561A981A; Sat, 16 Jun 2007 14:37:13 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r547988 - in /tapestry/tapestry4/trunk: tapestry-framework/src/descriptor/META-INF/ tapestry-framework/src/java/org/apache/tapestry/asset/ tapestry-framework/src/java/org/apache/tapestry/services/ tapestry-framework/src/java/org/apache/tape... Date: Sat, 16 Jun 2007 21:37:13 -0000 To: commits@tapestry.apache.org From: jkuhnert@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070616213713.BA2561A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jkuhnert Date: Sat Jun 16 14:37:12 2007 New Revision: 547988 URL: http://svn.apache.org/viewvc?view=rev&rev=547988 Log: TAPESTRY-1578. AssetService was manually parsing out the date header fields instead of using the "built in" getDateHeader() API provided by the servlet container. Removed: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/PoolableDateFormatFactory.java Modified: tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.request.xml tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/WebRequestServicerFilter.java tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/EngineFactoryImpl.java tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/web/ServletWebRequest.java tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/web/ServletWebResponse.java tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/web/WebRequest.java tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/web/WebResponse.java tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/TestAssetService.java tapestry/tapestry4/trunk/tapestry-portlet/src/java/org/apache/tapestry/portlet/PortletWebRequest.java Modified: tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.request.xml URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.request.xml?view=diff&rev=547988&r1=547987&r2=547988 ============================================================================== --- tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.request.xml (original) +++ tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.request.xml Sat Jun 16 14:37:12 2007 @@ -16,234 +16,232 @@ --> - - Services and configurations for the Tapestry request processing pipeline. - It is expected that the IEngine interface will eventually "dissolve" into - a collection of loosely bound services. - - - - Contains engine instances, keyed on locale, ready for use in the current request. - - - - - - - - - - - - Encapsulates the logic for extracting the locale for the current request. - - - - - - - - - - - - - - - - - - - - Allows access to incoming HTTP cookie values for the active (per-thread) request. - - - - - - - - - - - - Obtains an IEngine implementation for the current request, either from a pool of - such engine instance, from a factory, or from the HttpSession. - - - - - - - - - - - - - Responsible for creating new instances of IEngine as needed. - - - - - - - - - - - - - A pipeline for processing an incoming servlet request. - - - - - - A pipeline for handling each request. - - - - - - - - - - - - - - - - - - - - - - - - A pipeline, invoked by the ServletRequestPipeline, that will process the request - using the generic WebRequest and WebResponse objects. - - - - - - A secondary pipeline for handling each requests wrapped in the WebRequest abstraction - layer. - - - - - - - - - - - - - Terminator service for the WebRequestServicerPipeline. This locates an IEngine instance that - can take control of the remainder of the request. - - - - - - - - - - - - Filter contributed into the ServletRequestServicerPipeline whose responsibility is - to provide a modified HttpServletRequest that reflects the results of - an IRequestDecoder (provided as the org.apache.tapestry.request-decoder - application extension). If the extension exists, then a different HttpServletRequest - is substituted. - - - - - - - - - - - Renders the active page as the response. - - - - - - - - - - - - - - - Uses HttpServletRequest information to build complete URLs, suitable for use when - sending client-side redirects. - - - - - - - - - - - - Creates new IRequestCycle instances. - - - - - - - - - - - - - - - - - Sets the output encoding for the request. - - - - - - - - - - - Uses the ResetEventHub to reset any cached data at the end of the request. - Only used during development, not in production. - - - - - - - - - - - - + + Services and configurations for the Tapestry request processing pipeline. + It is expected that the IEngine interface will eventually "dissolve" into + a collection of loosely bound services. + + + + Contains engine instances, keyed on locale, ready for use in the current request. + + + + + + + + + + + + Encapsulates the logic for extracting the locale for the current request. + + + + + + + + + + + + + + + + + + + + Allows access to incoming HTTP cookie values for the active (per-thread) request. + + + + + + + + + + + + Obtains an IEngine implementation for the current request, either from a pool of + such engine instance, from a factory, or from the HttpSession. + + + + + + + + + + + + + Responsible for creating new instances of IEngine as needed. + + + + + + + + + + + + + A pipeline for processing an incoming servlet request. + + + + + + A pipeline for handling each request. + + + + + + + + + + + + + + + + + + + + + + + + A pipeline, invoked by the ServletRequestPipeline, that will process the request + using the generic WebRequest and WebResponse objects. + + + + + + A secondary pipeline for handling each requests wrapped in the WebRequest abstraction + layer. + + + + + + + + + + + + + Terminator service for the WebRequestServicerPipeline. This locates an IEngine instance that + can take control of the remainder of the request. + + + + + + + + + + + + Filter contributed into the ServletRequestServicerPipeline whose responsibility is + to provide a modified HttpServletRequest that reflects the results of + an IRequestDecoder (provided as the org.apache.tapestry.request-decoder + application extension). If the extension exists, then a different HttpServletRequest + is substituted. + + + + + + + + + + + Renders the active page as the response. + + + + + + + + + + + + + + + Uses HttpServletRequest information to build complete URLs, suitable for use when + sending client-side redirects. + + + + + + + + + + + + Creates new IRequestCycle instances. + + + + + + + + + + + + + + + + + Sets the output encoding for the request. + + + + + + + + + + + Uses the ResetEventHub to reset any cached data at the end of the request. + Only used during development, not in production. + + + + + + + + + + + + Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java?view=diff&rev=547988&r1=547987&r2=547988 ============================================================================== --- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java (original) +++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java Sat Jun 16 14:37:12 2007 @@ -17,8 +17,6 @@ import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; -import org.apache.commons.pool.ObjectPool; -import org.apache.commons.pool.impl.StackObjectPool; import org.apache.hivemind.ClassResolver; import org.apache.hivemind.util.Defense; import org.apache.tapestry.IRequestCycle; @@ -41,9 +39,7 @@ import java.io.OutputStream; import java.net.URL; import java.net.URLConnection; -import java.text.DateFormat; import java.util.HashMap; -import java.util.Locale; import java.util.Map; import java.util.TreeMap; import java.util.zip.GZIPOutputStream; @@ -80,12 +76,7 @@ */ public static final String DIGEST = "digest"; - - /** - * Pool of date format objects. (pooled because DateFormat isn't thread safe ) - */ - static final ObjectPool CACHED_FORMAT_POOL = new StackObjectPool(new PoolableDateFormatFactory("EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH)); - + /** * Defaults MIME types, by extension, used when the servlet container doesn't provide MIME * types. ServletExec Debugger, for example, fails to provide these. @@ -168,7 +159,6 @@ Defense.isAssignable(parameter, String.class, "parameter"); String path = (String) parameter; - String digest = null; if(!_unprotectedMatcher.containsResource(path)) @@ -199,7 +189,8 @@ if (result == null) { int dotx = path.lastIndexOf('.'); - if (dotx > -1) { + if (dotx > -1) + { String key = path.substring(dotx + 1).toLowerCase(); result = (String) _mimeTypes.get(key); } @@ -306,40 +297,34 @@ { // even if it doesn't exist in header the value will be -1, // which means we need to write out the contents of the resource - - String header = _request.getHeader("If-Modified-Since"); - long modify = -1; - - if (_log.isDebugEnabled()) - _log.debug("cachedResource(" + resourceURL.getURL() + ") modified-since header is: " + header); - - DateFormat format = null; - - try { - if (header != null) - { - format = (DateFormat) CACHED_FORMAT_POOL.borrowObject(); - - modify = format.parse(header).getTime(); - } + long modifiedSince = _request.getDateHeader("If-Modified-Since"); - } catch (Exception e) { e.printStackTrace(); } - finally - { - if (format != null) - try { CACHED_FORMAT_POOL.returnObject(format); } catch (Throwable t) { t.printStackTrace(); } - } + if (modifiedSince <= 0) + return false; + + if (_log.isDebugEnabled()) + _log.debug("cachedResource(" + resourceURL.getURL() + ") modified-since header is: " + modifiedSince); - if (resourceURL.getLastModified() > modify) + if (resourceURL.getLastModified() > modifiedSince) return false; _response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return true; } - - /** @since 2.2 */ + + /** + * Writes the asset specified by resourceConnection out to the response stream. + * + * @param cycle + * The current request. + * @param resourcePath + * The path of the resource. + * @param resourceConnection + * A connection for the resource. + * @throws IOException On error. + */ private void writeAssetContent(IRequestCycle cycle, String resourcePath, URLConnection resourceConnection) throws IOException @@ -396,35 +381,35 @@ // check cache first - if (_cache.get(resourcePath) != null) { - + if (_cache.get(resourcePath) != null) + { cache = (CachedAsset)_cache.get(resourcePath); if (cache.getLastModified() < resourceConnection.getLastModified()) cache.clear(resourceConnection.getLastModified()); data = cache.getData(); - } else { - + } else + { cache = new CachedAsset(resourcePath, resourceConnection.getLastModified(), null, null); _cache.put(resourcePath, cache); } - if (data == null) { - + if (data == null) + { input = resourceConnection.getInputStream(); data = IOUtils.toByteArray(input); - + cache.setData(data); } // compress javascript responses when possible - if (GzipUtil.shouldCompressContentType(contentType) && GzipUtil.isGzipCapable(_request)) { - - if (cache.getGzipData() == null) { - + if (GzipUtil.shouldCompressContentType(contentType) && GzipUtil.isGzipCapable(_request)) + { + if (cache.getGzipData() == null) + { ByteArrayOutputStream bo = new ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(bo); @@ -433,10 +418,8 @@ data = bo.toByteArray(); cache.setGzipData(data); - } else { - + } else data = cache.getGzipData(); - } _response.setHeader("Content-Encoding", "gzip"); } Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/WebRequestServicerFilter.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/WebRequestServicerFilter.java?view=diff&rev=547988&r1=547987&r2=547988 ============================================================================== --- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/WebRequestServicerFilter.java (original) +++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/WebRequestServicerFilter.java Sat Jun 16 14:37:12 2007 @@ -14,11 +14,11 @@ package org.apache.tapestry.services; -import java.io.IOException; - import org.apache.tapestry.web.WebRequest; import org.apache.tapestry.web.WebResponse; +import java.io.IOException; + /** * Filter interface for {@link org.apache.tapestry.services.WebRequestServicer}. * @@ -28,7 +28,6 @@ public interface WebRequestServicerFilter { - void service(WebRequest request, WebResponse response, - WebRequestServicer servicer) + void service(WebRequest request, WebResponse response, WebRequestServicer servicer) throws IOException; } Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/EngineFactoryImpl.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/EngineFactoryImpl.java?view=diff&rev=547988&r1=547987&r2=547988 ============================================================================== --- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/EngineFactoryImpl.java (original) +++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/EngineFactoryImpl.java Sat Jun 16 14:37:12 2007 @@ -14,8 +14,6 @@ package org.apache.tapestry.services.impl; -import java.util.Locale; - import org.apache.hivemind.ApplicationRuntimeException; import org.apache.hivemind.ClassResolver; import org.apache.hivemind.ErrorLog; @@ -24,6 +22,8 @@ import org.apache.tapestry.services.EngineFactory; import org.apache.tapestry.spec.IApplicationSpecification; +import java.util.Locale; + /** * Standard implementation of {@link org.apache.tapestry.services.EngineFactory} service. This * should do for most purposes, since a major focus of Tapestry 4.0 is to no longer require @@ -77,9 +77,7 @@ } catch (Exception ex) { - throw new ApplicationRuntimeException(ImplMessages.errorInstantiatingEngine( - _engineClass, - ex), ex); + throw new ApplicationRuntimeException(ImplMessages.errorInstantiatingEngine(_engineClass, ex), ex); } } } Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/web/ServletWebRequest.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/web/ServletWebRequest.java?view=diff&rev=547988&r1=547987&r2=547988 ============================================================================== --- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/web/ServletWebRequest.java (original) +++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/web/ServletWebRequest.java Sat Jun 16 14:37:12 2007 @@ -204,6 +204,16 @@ return _servletRequest.getHeader(name); } + public long getDateHeader(String name) + { + return _servletRequest.getDateHeader(name); + } + + public int getIntHeader(String name) + { + return _servletRequest.getIntHeader(name); + } + public String getRemoteUser() { return _servletRequest.getRemoteUser(); Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/web/ServletWebResponse.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/web/ServletWebResponse.java?view=diff&rev=547988&r1=547987&r2=547988 ============================================================================== --- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/web/ServletWebResponse.java (original) +++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/web/ServletWebResponse.java Sat Jun 16 14:37:12 2007 @@ -53,6 +53,13 @@ /** * Alternate constructor used by some tests. + * + * @param response + * The wrapped response. + * @param log + * Logger. + * @param tomcatPatch + * Whether or not to apply tomcat workaround. */ ServletWebResponse(HttpServletResponse response, Log log, boolean tomcatPatch) { Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/web/WebRequest.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/web/WebRequest.java?view=diff&rev=547988&r1=547987&r2=547988 ============================================================================== --- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/web/WebRequest.java (original) +++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/web/WebRequest.java Sat Jun 16 14:37:12 2007 @@ -178,6 +178,55 @@ String getHeader(String name); /** + * Returns the value of the specified request header + * as a long value that represents a + * Date object. Use this method with + * headers that contain dates, such as + * If-Modified-Since. + * + *

The date is returned as + * the number of milliseconds since January 1, 1970 GMT. + * The header name is case insensitive. + * + *

If the request did not have a header of the + * specified name, this method returns -1. If the header + * can't be converted to a date, the method throws + * an IllegalArgumentException. + * + * @param name a String specifying the + * name of the header + * + * @return a long value representing the + * date specified in the header expressed as the number + * of milliseconds since January 1, 1970 GMT, or -1 if + * the named header was not included with the reqest + * + * @exception IllegalArgumentException If the header value + * can't be converted to a date + */ + long getDateHeader(String name); + + /** + * Returns the value of the specified request header + * as an int. If the request does not have a header + * of the specified name, this method returns -1. If the + * header cannot be converted to an integer, this method + * throws a NumberFormatException. + * + *

The header name is case insensitive. + * + * @param name a String specifying the name + * of a request header + * + * @return an integer expressing the value of the request header or -1 + * if the request doesn't have a header of this name + * + * @exception NumberFormatException If the header value can't be + * converted to an int + */ + int getIntHeader(String name); + + /** * Returns the login of the user making this request, if the user has been authenticated, or * null if the user has not been authenticated. * Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/web/WebResponse.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/web/WebResponse.java?view=diff&rev=547988&r1=547987&r2=547988 ============================================================================== --- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/web/WebResponse.java (original) +++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/web/WebResponse.java Sat Jun 16 14:37:12 2007 @@ -14,12 +14,12 @@ package org.apache.tapestry.web; +import org.apache.tapestry.util.ContentType; + import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; -import org.apache.tapestry.util.ContentType; - /** * Controls the response to the client, and specifically allows for creating the output stream (or * print writer) to which content is sent. This is essentially a generic version of @@ -35,24 +35,40 @@ /** * Returns a output stream to which output should be sent. This method should only be invoked * once on a response. - * + * + * @param contentType + * The encoding type that this outputstream will write content as. * @return the output stream, configured for the given type. + * + * @throws IOException On io error. */ - OutputStream getOutputStream(ContentType contentType) throws IOException; + OutputStream getOutputStream(ContentType contentType) + throws IOException; /** * Returns a {@link PrintWriter} to which output should be sent. This method should be invoked * once on a response. A second call is expected to be so that an exception page can be * rendered, and the underlying request data is reset. + * + * @param contentType + * The type of content encoding the writer is for. + * @return A new {@link PrintWriter} instance. + * + * @throws IOException On io error. */ - PrintWriter getPrintWriter(ContentType contentType) throws IOException; + PrintWriter getPrintWriter(ContentType contentType) + throws IOException; /** * Encodes a URL, which adds information to the URL needed to ensure that the request triggered * by the URL will be associated with the current session (if any). In most cases, the string is * returned unchanged. + * + * @param url + * The URL to encode. + * @return The url encoded. */ String encodeURL(String url); @@ -64,12 +80,20 @@ void reset(); + /** + * Sets the response content length header. + * + * @param contentLength + * The total content length this response will write. + */ void setContentLength(int contentLength); /** * Returns a value to be prefixed or suffixed with any client-side JavaScript elements * (variables and function names) to ensure that they are unique with the context of the entire * page. For servlets, this is the empty string. + * + * @return The namespace that this requests resources should be pre-pended with. */ String getNamespace(); @@ -107,12 +131,21 @@ /** * Sets the status code for this response. + * + * @param status + * The HTTP status code to set on the return header. */ void setStatus(int status); /** * Sends an error response. + * + * @param statusCode + * The error status code to set on the header. + * @param message + * The message to give as the reason for error. + * + * @throws IOException on io error. */ - void sendError(int statusCode, String message) throws IOException; } Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/TestAssetService.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/TestAssetService.java?view=diff&rev=547988&r1=547987&r2=547988 ============================================================================== --- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/TestAssetService.java (original) +++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/TestAssetService.java Sat Jun 16 14:37:12 2007 @@ -29,7 +29,6 @@ import javax.servlet.http.HttpServletResponse; import java.io.ByteArrayOutputStream; import java.net.URLConnection; -import java.text.DateFormat; /** @@ -48,42 +47,14 @@ AssetService service = new AssetService(); service.setRequest(request); service.setLog(LogFactory.getLog("test")); - - URLConnection url = org.easymock.classextension.EasyMock.createMock(URLConnection.class); - - expect(request.getHeader("If-Modified-Since")).andReturn(null); - expect(url.getLastModified()).andReturn(System.currentTimeMillis()); - - replay(); - org.easymock.classextension.EasyMock.replay(url); - - assertFalse(service.cachedResource(url)); - - verify(); - org.easymock.classextension.EasyMock.verify(url); - } - - public void test_Cached_Resource_Malformed_Modified() - { - WebRequest request = newMock(WebRequest.class); - checkOrder(request, false); - - AssetService service = new AssetService(); - service.setRequest(request); - service.setLog(LogFactory.getLog("test")); - - URLConnection url = org.easymock.classextension.EasyMock.createMock(URLConnection.class); - - expect(request.getHeader("If-Modified-Since")).andReturn("Woopedy woopedy"); - expect(url.getLastModified()).andReturn(System.currentTimeMillis()); + + expect(request.getDateHeader("If-Modified-Since")).andReturn(-1l); replay(); - org.easymock.classextension.EasyMock.replay(url); - - assertFalse(service.cachedResource(url)); + + assertFalse(service.cachedResource(null)); verify(); - org.easymock.classextension.EasyMock.verify(url); } public void test_Cached_Resource_Stale() @@ -96,8 +67,10 @@ service.setLog(LogFactory.getLog("test")); URLConnection url = org.easymock.classextension.EasyMock.createMock(URLConnection.class); - - expect(request.getHeader("If-Modified-Since")).andReturn("Sat, 29 Oct 1994 19:43:31 GMT"); + + long modifiedSince = System.currentTimeMillis() - 1000; + + expect(request.getDateHeader("If-Modified-Since")).andReturn(modifiedSince); expect(url.getLastModified()).andReturn(System.currentTimeMillis()); replay(); @@ -122,21 +95,12 @@ service.setLog(LogFactory.getLog("test")); URLConnection url = org.easymock.classextension.EasyMock.createMock(URLConnection.class); - - DateFormat format = null; - - try { - - format = (DateFormat) AssetService.CACHED_FORMAT_POOL.borrowObject(); - - expect(request.getHeader("If-Modified-Since")).andReturn("Sat, 29 Oct 1994 19:43:31 GMT"); - expect(url.getLastModified()).andReturn(format.parse("Sat, 1 Dec 1991 19:43:31 GMT").getTime()); - - } finally { - if (format != null) { - try { AssetService.CACHED_FORMAT_POOL.returnObject(format); } catch (Throwable t) {} - } - } + + long lastModified = System.currentTimeMillis() - 4000; + long modifiedSince = System.currentTimeMillis(); + + expect(request.getDateHeader("If-Modified-Since")).andReturn(modifiedSince); + expect(url.getLastModified()).andReturn(lastModified); response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); @@ -175,7 +139,7 @@ expect(matcher.containsResource("/org/apache/tapestry/asset/tapestry-in-action.png")).andReturn(true); - expect(request.getHeader("If-Modified-Since")).andReturn(null); + expect(request.getDateHeader("If-Modified-Since")).andReturn(-1L); expect(context.getMimeType("/org/apache/tapestry/asset/tapestry-in-action.png")).andReturn("image/png"); response.setDateHeader("Last-Modified", url.getLastModified()); Modified: tapestry/tapestry4/trunk/tapestry-portlet/src/java/org/apache/tapestry/portlet/PortletWebRequest.java URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-portlet/src/java/org/apache/tapestry/portlet/PortletWebRequest.java?view=diff&rev=547988&r1=547987&r2=547988 ============================================================================== --- tapestry/tapestry4/trunk/tapestry-portlet/src/java/org/apache/tapestry/portlet/PortletWebRequest.java (original) +++ tapestry/tapestry4/trunk/tapestry-portlet/src/java/org/apache/tapestry/portlet/PortletWebRequest.java Sat Jun 16 14:37:12 2007 @@ -161,6 +161,20 @@ return null; } + public long getDateHeader(String name) + { + unsupported("getDateHeader"); + + return -1; + } + + public int getIntHeader(String name) + { + unsupported("getIntHeader"); + + return -1; + } + public String getRemoteUser() { return _portletRequest.getRemoteUser();