You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2008/01/08 23:32:04 UTC

svn commit: r610203 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry/internal/services/ main/resources/org/apache/tapestry/ test/java/org/apache/tapestry/internal/services/

Author: hlship
Date: Tue Jan  8 14:32:03 2008
New Revision: 610203

URL: http://svn.apache.org/viewvc?rev=610203&view=rev
Log:
TAPESTRY-2017: AssetDispatcher doesn't stream asset when the 'If-Modified-Since' header can't be converted to a date

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/AssetDispatcher.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/default.css
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/AssetDispatcherTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/AssetDispatcher.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/AssetDispatcher.java?rev=610203&r1=610202&r2=610203&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/AssetDispatcher.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/AssetDispatcher.java Tue Jan  8 14:32:03 2008
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -59,8 +59,7 @@
         // Remember that the request path does not include the context path, so we can simply start
         // looking for the asset path prefix right off the bat.
 
-        if (!path.startsWith(TapestryConstants.ASSET_PATH_PREFIX))
-            return false;
+        if (!path.startsWith(TapestryConstants.ASSET_PATH_PREFIX)) return false;
 
         // ClassLoaders like their paths to start with a leading slash.
 
@@ -68,8 +67,7 @@
 
         Resource resource = findResourceAndValidateDigest(response, resourcePath);
 
-        if (resource == null)
-            return true;
+        if (resource == null) return true;
 
         URL url = resource.toURL();
 
@@ -80,10 +78,23 @@
             return true;
         }
 
-        long ifModifiedSince = request.getDateHeader(IF_MODIFIED_SINCE_HEADER);
+        long ifModifiedSince = 0;
+
+        try
+        {
+            ifModifiedSince = request.getDateHeader(IF_MODIFIED_SINCE_HEADER);
+        }
+        catch (IllegalArgumentException ex)
+        {
+            // Simulate the header being missing if it is poorly formatted.
+
+            ifModifiedSince = -1;
+        }
+
         if (ifModifiedSince > 0)
         {
             long modified = _resourceCache.getTimeModified(resource);
+
             if (ifModifiedSince >= modified)
             {
                 response.sendError(HttpServletResponse.SC_NOT_MODIFIED, "");
@@ -103,13 +114,11 @@
      *         digest is invalid (and an error has been sent back to the client)
      * @throws IOException
      */
-    private Resource findResourceAndValidateDigest(Response response, String resourcePath)
-            throws IOException
+    private Resource findResourceAndValidateDigest(Response response, String resourcePath) throws IOException
     {
         Resource resource = new ClasspathResource(resourcePath);
 
-        if (!_resourceCache.requiresDigest(resource))
-            return resource;
+        if (!_resourceCache.requiresDigest(resource)) return resource;
 
         String file = resource.getFile();
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/default.css
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/default.css?rev=610203&r1=610202&r2=610203&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/default.css (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/default.css Tue Jan  8 14:32:03 2008
@@ -341,7 +341,7 @@
 DIV.t-error-bevel SPAN {
     background: transparent url( 'error-bevel-left.png' ) no-repeat;
     display: block;
-    line-height: 33px;
+    line-height: 28px;
     margin-left: 0px;
     padding: 0px 5px 10px 22px;
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/AssetDispatcherTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/AssetDispatcherTest.java?rev=610203&r1=610202&r2=610203&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/AssetDispatcherTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/AssetDispatcherTest.java Tue Jan  8 14:32:03 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -225,6 +225,36 @@
         train_getTimeModified(cache, SMILEY, now - 1000);
 
         response.sendError(HttpServletResponse.SC_NOT_MODIFIED, "");
+
+        replay();
+
+        Dispatcher d = new AssetDispatcher(streamer, aliasManager, cache);
+
+        assertTrue(d.dispatch(request, response));
+
+        verify();
+    }
+
+    @Test
+    public void if_modified_since_header_not_readable() throws Exception
+    {
+        Request request = mockRequest();
+        Response response = mockResponse();
+        ClasspathAssetAliasManager aliasManager = mockClasspathAssetAliasManager();
+        ResourceCache cache = mockResourceCache();
+        ResourceStreamer streamer = mockResourceStreamer();
+        long now = System.currentTimeMillis();
+
+        train_getPath(request, SMILEY_CLIENT_URL);
+
+        train_toResourcePath(aliasManager, SMILEY_CLIENT_URL, SMILEY_PATH);
+
+        train_requiresDigest(cache, SMILEY, false);
+
+        expect(request.getDateHeader(AssetDispatcher.IF_MODIFIED_SINCE_HEADER)).andThrow(
+                new IllegalArgumentException("For testing."));
+
+        streamer.streamResource(SMILEY);
 
         replay();