tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject git commit: TAP5-2278: ModuleDispatcher should send 404 response when the request includes the prefix, but not a valid module path
Date Fri, 01 Aug 2014 17:38:24 GMT
Repository: tapestry-5
Updated Branches:
  refs/heads/master 0d3c9bc95 -> 37c2f877b


TAP5-2278: ModuleDispatcher should send 404 response when the request includes the prefix,
but not a valid module path


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/37c2f877
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/37c2f877
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/37c2f877

Branch: refs/heads/master
Commit: 37c2f877be6fc7181c37bcfc8493f396409f90e8
Parents: 0d3c9bc
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Fri Aug 1 10:38:27 2014 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Fri Aug 1 10:38:27 2014 -0700

----------------------------------------------------------------------
 .../services/javascript/ModuleDispatcher.java     | 18 ++++++++++++++----
 .../javascript/ModuleDispatcherTests.groovy       | 14 ++++++++++++--
 2 files changed, 26 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/37c2f877/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleDispatcher.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleDispatcher.java
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleDispatcher.java
index a841578..372fabd 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleDispatcher.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleDispatcher.java
@@ -1,5 +1,3 @@
-// Copyright 2012, 2013 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
@@ -25,6 +23,7 @@ import org.apache.tapestry5.services.Request;
 import org.apache.tapestry5.services.Response;
 import org.apache.tapestry5.services.javascript.ModuleManager;
 
+import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.util.EnumSet;
 import java.util.Set;
@@ -69,8 +68,19 @@ public class ModuleDispatcher implements Dispatcher
     {
         String path = request.getPath();
 
-        return path.startsWith(requestPrefix) &&
-                handleModuleRequest(path.substring(requestPrefix.length()));
+        if (path.startsWith(requestPrefix))
+        {
+            String extraPath = path.substring(requestPrefix.length());
+
+            if (! handleModuleRequest(extraPath))
+            {
+                response.sendError(HttpServletResponse.SC_NOT_FOUND, String.format("No module
for path '%s'.", extraPath));
+            }
+
+            return true;
+        }
+
+        return false;
 
     }
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/37c2f877/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleDispatcherTests.groovy
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleDispatcherTests.groovy
b/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleDispatcherTests.groovy
index c239026..30d0066 100644
--- a/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleDispatcherTests.groovy
+++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleDispatcherTests.groovy
@@ -5,25 +5,32 @@ import org.apache.tapestry5.ioc.internal.QuietOperationTracker
 import org.apache.tapestry5.ioc.test.TestBase
 import org.apache.tapestry5.services.PathConstructor
 import org.apache.tapestry5.services.Request
+import org.apache.tapestry5.services.Response
+import org.easymock.EasyMock
 import org.testng.annotations.DataProvider
 import org.testng.annotations.Test
 
+import javax.servlet.http.HttpServletResponse
+
 class ModuleDispatcherTests extends TestBase {
 
     @Test(dataProvider = "unknownPaths")
     void "invalid extension is ignored"(path) {
         def request = newMock Request
+        def response = newMock Response
         def pc = newMock PathConstructor
 
         expect(pc.constructDispatchPath("modules")).andReturn("/modules")
 
         expect(request.path).andReturn(path)
 
+        expect(response.sendError(EasyMock.eq(HttpServletResponse.SC_NOT_FOUND), EasyMock.notNull()))
+
         replay()
 
         def handler = new ModuleDispatcher(null, null, new QuietOperationTracker(), pc, "modules",
false)
 
-        assert handler.dispatch(request, null) == false
+        assert handler.dispatch(request, response) == true
 
         verify()
     }
@@ -43,6 +50,7 @@ class ModuleDispatcherTests extends TestBase {
 
         def manager = newMock ModuleManager
         def request = newMock Request
+        def response = newMock Response
         def pc = newMock PathConstructor
 
         expect(pc.constructDispatchPath("modules")).andReturn("/modules")
@@ -51,11 +59,13 @@ class ModuleDispatcherTests extends TestBase {
 
         expect(manager.findResourceForModule("foo/bar")).andReturn null
 
+        expect(response.sendError(EasyMock.eq(HttpServletResponse.SC_NOT_FOUND), EasyMock.notNull()))
+
         replay()
 
         def handler = new ModuleDispatcher(manager, null, new QuietOperationTracker(), pc,
"modules", false)
 
-        assert handler.dispatch(request, null) == false
+        assert handler.dispatch(request, response) == true
 
         verify()
     }


Mime
View raw message