You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jd...@apache.org on 2010/08/01 22:36:14 UTC
svn commit: r981312 - in /wicket/trunk/wicket/src:
main/java/org/apache/wicket/protocol/http/WicketFilter.java
test/java/org/apache/wicket/protocol/http/WicketFilterTest.java
Author: jdonnerstag
Date: Sun Aug 1 20:36:14 2010
New Revision: 981312
URL: http://svn.apache.org/viewvc?rev=981312&view=rev
Log:
fix the fix :)
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java?rev=981312&r1=981311&r2=981312&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java Sun Aug 1 20:36:14 2010
@@ -118,6 +118,7 @@ public class WicketFilter implements Fil
HttpServletRequest httpServletRequest = (HttpServletRequest)request;
HttpServletResponse httpServletResponse = (HttpServletResponse)response;
+ // Make sure getFilterPath() gets called before checkIfRedirectRequired()
String filterPath = getFilterPath(httpServletRequest);
String redirectURL = checkIfRedirectRequired(httpServletRequest);
@@ -257,12 +258,16 @@ public class WicketFilter implements Fil
application.setName(filterConfig.getFilterName());
application.setWicketFilter(this);
- filterPath = new WebXmlFile().getFilterPath(filterConfig);
+ // Allow the filterPath to tbe preset via setFilterPath()
if (filterPath == null)
{
- log.info("Unable to parse filter mapping web.xml for " + filterConfig.getFilterName() +
- ". " + "Configure with init-param " + FILTER_MAPPING_PARAM +
- " if it is not \"/*\".");
+ filterPath = new WebXmlFile().getFilterPath(filterConfig);
+ if (filterPath == null)
+ {
+ log.info("Unable to parse filter mapping web.xml for " +
+ filterConfig.getFilterName() + ". " + "Configure with init-param " +
+ FILTER_MAPPING_PARAM + " if it is not \"/*\".");
+ }
}
final ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader();
@@ -385,8 +390,8 @@ public class WicketFilter implements Fil
}
// request.getContextPath() + "/" + filterPath. But without any trailing "/".
- int homePathLenth = contextPath.length() + (filterPathLength > 0 ? 1 : 0) +
- filterPathLength;
+ int homePathLenth = contextPath.length() +
+ (filterPathLength > 0 ? 1 + filterPathLength : 0);
if (uriLength != homePathLenth)
{
// requestURI and homePath are different (in length)
@@ -414,4 +419,24 @@ public class WicketFilter implements Fil
// no match => standard request processing; no redirect
return null;
}
+
+ /**
+ * Sets the filter path instead of reading it from web.xml.
+ *
+ * Please note that you must subclass WicketFilter.init(FilterConfig) and set your filter path
+ * before you call super.init(filterConfig).
+ *
+ * @param filterPath
+ */
+ public final void setFilterPath(final String filterPath)
+ {
+ // see https://issues.apache.org/jira/browse/WICKET-701
+ if (this.filterPath != null)
+ {
+ throw new IllegalStateException(
+ "Filter path is write-once. You can not change it. Current value='" + filterPath +
+ "'");
+ }
+ this.filterPath = filterPath;
+ }
}
Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java?rev=981312&r1=981311&r2=981312&view=diff
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java (original)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java Sun Aug 1 20:36:14 2010
@@ -209,7 +209,8 @@ public class WicketFilterTest extends Te
{
WicketFilter filter = new WicketFilter();
- // Simulate url-pattern = "/*" and request = http://localhost:8080
- assertEquals("", filter.checkIfRedirectRequired("/", ""));
+ // Simulate url-pattern = "/*" and request = http://localhost:8080 => null == no redirect
+ filter.setFilterPath("");
+ assertNull("", filter.checkIfRedirectRequired("/", ""));
}
}