You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by da...@apache.org on 2015/09/11 19:00:24 UTC

wicket git commit: WICKET-5980 Servlet 3 Filter path calculated wrong

Repository: wicket
Updated Branches:
  refs/heads/master 51b1a9968 -> 294b0b2f8


WICKET-5980 Servlet 3 Filter path calculated wrong

When using Servlet 3.0 filter Wicket calculates filter path wrong. With a /web/* filter definition
in the annotation Wicket generates /web/*/ instead of /web/.

This fix uses the same approach as WicketFilter.getFilterPathFromConfig and other similar
extracters. Fixes WICKET-5980.


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/294b0b2f
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/294b0b2f
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/294b0b2f

Branch: refs/heads/master
Commit: 294b0b2f897dc0e2433b607d7543061145b320fc
Parents: 51b1a99
Author: Martijn Dashorst <ma...@gmail.com>
Authored: Fri Sep 11 18:40:16 2015 +0200
Committer: Martijn Dashorst <ma...@gmail.com>
Committed: Fri Sep 11 18:59:59 2015 +0200

----------------------------------------------------------------------
 .../wicket/protocol/http/WicketFilter.java      |  4 +++
 .../protocol/http/AnnotatedServlet3Filter.java  | 13 ++++++++
 .../wicket/protocol/http/WicketFilterTest.java  | 34 ++++++++++++++++++++
 3 files changed, 51 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/294b0b2f/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
index 679cfbf..d73a4a7 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
@@ -519,6 +519,10 @@ public class WicketFilter implements Filter
 				pattern = "";
 			}
 
+			if (pattern.endsWith("*"))
+			{
+				pattern = pattern.substring(0, pattern.length() - 1);
+			}
 			return pattern;
 		}
 		return null;

http://git-wip-us.apache.org/repos/asf/wicket/blob/294b0b2f/wicket-core/src/test/java/org/apache/wicket/protocol/http/AnnotatedServlet3Filter.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/AnnotatedServlet3Filter.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/AnnotatedServlet3Filter.java
new file mode 100644
index 0000000..a842b54
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/AnnotatedServlet3Filter.java
@@ -0,0 +1,13 @@
+package org.apache.wicket.protocol.http;
+
+import javax.servlet.annotation.WebFilter;
+import javax.servlet.annotation.WebInitParam;
+
+/**
+ * Test filter using Servlet 3.0 initialization.
+ */
+@WebFilter(value = "/web/*", initParams = {@WebInitParam(name = "applicationClassName",
+value = "org.apache.wicket.mock.MockApplication")})
+public class AnnotatedServlet3Filter extends WicketFilter
+{
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/294b0b2f/wicket-core/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java
index 82c7320..da1526c 100644
--- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.wicket.protocol.http;
 
+import static org.hamcrest.CoreMatchers.is;
 import static org.mockito.Mockito.*;
 
 import java.io.IOException;
@@ -88,6 +89,39 @@ public class WicketFilterTest extends Assert
 	}
 
 	/**
+	 * Test for WICKET-5980 When using Servlet 3.0 filter Wicket calculates filter path wrong.
+	 * 
+	 * When using a servlet 3.0 filter with annotations Wicket calculates the filter path wrong
+	 * causing it to not match any pages other than the home page. e.g.
+	 * 
+	 * <pre>
+	 * &#64;WebFilter(value = "/web/*", initParams = {
+	 * 		&#64;WebInitParam(name = "applicationClassName", value = "com.example.CheesrApplication") })
+	 * public class CheesrFilter extends WicketFilter
+	 * {
+	 * }
+	 * </pre>
+	 * 
+	 * @throws Exception
+	 */
+	@Test
+	public void parsingOfAnnotatedServlet3FiltersWorks() throws Exception
+	{
+		FilterTestingConfig config = new FilterTestingConfig();
+		config.initParameters.clear();
+		config.initParameters.put("applicationClassName", "org.apache.wicket.mock.MockApplication");
+
+		WicketFilter filter = new AnnotatedServlet3Filter();
+		filter.init(config);
+
+		// no idea why this fails, but without the line below another test fails.
+		application = filter.getApplication();
+
+		// assert that the filter path is not /web/*/
+		assertThat(filter.getFilterPath(), is("web/"));
+	}
+
+	/**
 	 * testFilterPath1()
 	 */
 	@Test