You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2007/03/07 19:12:12 UTC
svn commit: r515673 - in /tapestry/tapestry5/tapestry-core/trunk/src:
main/java/org/apache/tapestry/internal/services/StaticFilesFilter.java
test/java/org/apache/tapestry/internal/services/StaticFilesFilterTest.java
Author: hlship
Date: Wed Mar 7 10:12:11 2007
New Revision: 515673
URL: http://svn.apache.org/viewvc?view=rev&rev=515673
Log:
TAPESTRY-1322: Spurious errors in log concerning page "favicon"
Added:
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/StaticFilesFilterTest.java
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/StaticFilesFilter.java
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/StaticFilesFilter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/StaticFilesFilter.java?view=diff&rev=515673&r1=515672&r2=515673
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/StaticFilesFilter.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/StaticFilesFilter.java Wed Mar 7 10:12:11 2007
@@ -41,6 +41,13 @@
{
String path = request.getPath();
+ // TAPESTRY-1322: Treat requests from the browser for a favorites icon via the normal
+ // servlet even if the file doesn't exist, to keep the request from looking like a
+ // component action request.
+
+ if (path.equals("/favicon.ico"))
+ return false;
+
// We are making the questionable assumption that all files to be vended out will contain
// an extension (with a dot seperator). Without this, the filter tends to match against
// folder names when we don't want it to (especially for the root context path).
Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/StaticFilesFilterTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/StaticFilesFilterTest.java?view=auto&rev=515673
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/StaticFilesFilterTest.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/StaticFilesFilterTest.java Wed Mar 7 10:12:11 2007
@@ -0,0 +1,124 @@
+// Copyright 2007 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.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.internal.services;
+
+import java.io.IOException;
+import java.net.URL;
+
+import org.apache.tapestry.internal.test.InternalBaseTestCase;
+import org.apache.tapestry.services.Context;
+import org.apache.tapestry.services.Request;
+import org.apache.tapestry.services.RequestFilter;
+import org.apache.tapestry.services.RequestHandler;
+import org.apache.tapestry.services.Response;
+import org.testng.annotations.Test;
+
+public class StaticFilesFilterTest extends InternalBaseTestCase
+{
+ @Test
+ public void request_for_favicon() throws IOException
+ {
+ Request request = newRequest("/favicon.ico");
+ Response response = newResponse();
+ RequestHandler handler = newRequestHandler();
+ Context context = newContext();
+
+ replay();
+
+ RequestFilter filter = new StaticFilesFilter(context);
+
+ assertFalse(filter.service(request, response, handler));
+
+ verify();
+ }
+
+ @Test
+ public void path_does_not_contain_a_period() throws Exception
+ {
+ Request request = newRequest("/start");
+ Response response = newResponse();
+ RequestHandler handler = newRequestHandler();
+ Context context = newContext();
+
+ train_service(handler, request, response, true);
+
+ replay();
+
+ RequestFilter filter = new StaticFilesFilter(context);
+
+ assertTrue(filter.service(request, response, handler));
+
+ verify();
+ }
+
+ @Test
+ public void existing_file() throws Exception
+ {
+ URL url = new URL("file://.");
+ String path = "/cell.gif";
+
+ Request request = newRequest(path);
+ Response response = newResponse();
+ RequestHandler handler = newRequestHandler();
+ Context context = newContext();
+
+ train_getResource(context, path, url);
+
+ replay();
+
+ RequestFilter filter = new StaticFilesFilter(context);
+
+ assertFalse(filter.service(request, response, handler));
+
+ verify();
+ }
+
+ @Test
+ public void not_a_static_file_request() throws Exception
+ {
+ String path = "/start.update";
+
+ Request request = newRequest(path);
+ Response response = newResponse();
+ RequestHandler handler = newRequestHandler();
+ Context context = newContext();
+
+ train_getResource(context, path, null);
+ train_service(handler, request, response, true);
+
+ replay();
+
+ RequestFilter filter = new StaticFilesFilter(context);
+
+ assertTrue(filter.service(request, response, handler));
+
+ verify();
+ }
+
+ protected final void train_getResource(Context context, String path, URL url)
+ {
+ expect(context.getResource(path)).andReturn(url);
+ }
+
+ protected final Request newRequest(String path)
+ {
+ Request request = newRequest();
+
+ train_getPath(request, path);
+
+ return request;
+ }
+
+}