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 2007/11/30 22:10:31 UTC

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

Author: hlship
Date: Fri Nov 30 13:10:29 2007
New Revision: 599967

URL: http://svn.apache.org/viewvc?rev=599967&view=rev
Log:
TAPESTRY-1947: Mangled URLs that should result in standard 404 error pages are instead resulting in a Tapestry exception report

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentActionDispatcher.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ComponentActionDispatcherTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentActionDispatcher.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentActionDispatcher.java?rev=599967&r1=599966&r2=599967&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentActionDispatcher.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentActionDispatcher.java Fri Nov 30 13:10:29 2007
@@ -17,10 +17,7 @@
 import org.apache.tapestry.TapestryConstants;
 import org.apache.tapestry.internal.InternalConstants;
 import org.apache.tapestry.internal.TapestryInternalUtils;
-import org.apache.tapestry.services.ComponentActionRequestHandler;
-import org.apache.tapestry.services.Dispatcher;
-import org.apache.tapestry.services.Request;
-import org.apache.tapestry.services.Response;
+import org.apache.tapestry.services.*;
 
 import java.io.IOException;
 
@@ -30,13 +27,17 @@
  */
 public class ComponentActionDispatcher implements Dispatcher
 {
+    private final ComponentClassResolver _componentClassResolver;
+
     private final ComponentActionRequestHandler _componentActionRequestHandler;
 
     private final String[] _emptyString = new String[0];
 
-    public ComponentActionDispatcher(ComponentActionRequestHandler componentActionRequestHandler)
+    public ComponentActionDispatcher(ComponentActionRequestHandler componentActionRequestHandler,
+                                     ComponentClassResolver componentClassResolver)
     {
         _componentActionRequestHandler = componentActionRequestHandler;
+        _componentClassResolver = componentClassResolver;
     }
 
     public boolean dispatch(Request request, Response response) throws IOException
@@ -102,6 +103,10 @@
         }
 
         if (logicalPageName == null) return false;
+
+        // We've identified a page name ... does the application contain a page with that name?
+
+        if (!_componentClassResolver.isPageName(logicalPageName)) return false;
 
         String[] eventContext = contextStart > 0 ? decodeContext(path.substring(contextStart)) : _emptyString;
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java?rev=599967&r1=599966&r2=599967&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java Fri Nov 30 13:10:29 2007
@@ -1209,7 +1209,8 @@
 
         configuration.add("PageRender", new PageRenderDispatcher(componentClassResolver, pageRenderRequestHandler));
 
-        configuration.add("ComponentAction", new ComponentActionDispatcher(componentActionRequestHandler),
+        configuration.add("ComponentAction",
+                          new ComponentActionDispatcher(componentActionRequestHandler, componentClassResolver),
                           "after:PageRender");
     }
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml?rev=599967&r1=599966&r2=599967&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml Fri Nov 30 13:10:29 2007
@@ -15,7 +15,7 @@
    limitations under the License.
 -->
 
-<suite name="Tapestry Core" annotations="1.5" verbose="2">
+<suite name="Tapestry Core" annotations="1.5" verbose="2" parallel="tests">
     <test name="Integration Tests">
         <packages>
             <package name="org.apache.tapestry.integration"/>

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ComponentActionDispatcherTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ComponentActionDispatcherTest.java?rev=599967&r1=599966&r2=599967&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ComponentActionDispatcherTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ComponentActionDispatcherTest.java Fri Nov 30 13:10:29 2007
@@ -17,10 +17,7 @@
 import org.apache.tapestry.TapestryConstants;
 import org.apache.tapestry.internal.InternalConstants;
 import org.apache.tapestry.internal.test.InternalBaseTestCase;
-import org.apache.tapestry.services.ComponentActionRequestHandler;
-import org.apache.tapestry.services.Dispatcher;
-import org.apache.tapestry.services.Request;
-import org.apache.tapestry.services.Response;
+import org.apache.tapestry.services.*;
 import static org.easymock.EasyMock.aryEq;
 import static org.easymock.EasyMock.eq;
 import org.testng.annotations.Test;
@@ -40,7 +37,7 @@
 
         replay();
 
-        Dispatcher dispatcher = new ComponentActionDispatcher(handler);
+        Dispatcher dispatcher = new ComponentActionDispatcher(handler, null);
 
         assertFalse(dispatcher.dispatch(request, response));
 
@@ -107,9 +104,12 @@
         ComponentActionRequestHandler handler = newComponentActionRequestHandler();
         Request request = mockRequest();
         Response response = mockResponse();
+        ComponentClassResolver resolver = mockComponentClassResolver();
 
         train_getPath(request, "/mypage:eventname");
 
+        train_isPageName(resolver, "mypage", true);
+
         train_getParameter(request, InternalConstants.PAGE_CONTEXT_NAME, "alpha/beta");
 
         handler.handle(eq("mypage"), eq(""), eq("eventname"), aryEq(new String[0]),
@@ -117,29 +117,53 @@
 
         replay();
 
-        Dispatcher dispatcher = new ComponentActionDispatcher(handler);
+        Dispatcher dispatcher = new ComponentActionDispatcher(handler, resolver);
 
         assertTrue(dispatcher.dispatch(request, response));
 
         verify();
     }
 
+    @Test
+    public void request_path_reference_non_existent_page() throws Exception
+    {
+        ComponentActionRequestHandler handler = newComponentActionRequestHandler();
+        Request request = mockRequest();
+        Response response = mockResponse();
+        ComponentClassResolver resolver = mockComponentClassResolver();
+
+        train_getPath(request, "/mypage.foo");
+
+        train_isPageName(resolver, "mypage", false);
+
+        replay();
+
+        Dispatcher dispatcher = new ComponentActionDispatcher(handler, resolver);
+
+        assertFalse(dispatcher.dispatch(request, response));
+
+        verify();
+    }
+
     private void test(String requestPath, String logicalPageName, String nestedComponentId, String eventType,
                       String... context) throws IOException
     {
         ComponentActionRequestHandler handler = newComponentActionRequestHandler();
         Request request = mockRequest();
         Response response = mockResponse();
+        ComponentClassResolver resolver = mockComponentClassResolver();
 
         train_getPath(request, requestPath);
 
+        train_isPageName(resolver, logicalPageName, true);
+
         train_getParameter(request, InternalConstants.PAGE_CONTEXT_NAME, null);
 
         handler.handle(eq(logicalPageName), eq(nestedComponentId), eq(eventType), aryEq(context), aryEq(new String[0]));
 
         replay();
 
-        Dispatcher dispatcher = new ComponentActionDispatcher(handler);
+        Dispatcher dispatcher = new ComponentActionDispatcher(handler, resolver);
 
         assertTrue(dispatcher.dispatch(request, response));