Created
March 7, 2011 23:41
-
-
Save mraible/859528 to your computer and use it in GitHub Desktop.
What it took to implement extensionless URLs in Stripes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: stripes/src/main/webapp/WEB-INF/web.xml | |
=================================================================== | |
--- stripes/src/main/webapp/WEB-INF/web.xml (revision 163) | |
+++ stripes/src/main/webapp/WEB-INF/web.xml (revision ) | |
@@ -17,7 +17,6 @@ | |
<filter-name>exportFilter</filter-name> | |
<filter-class>org.displaytag.filter.ResponseOverrideFilter</filter-class> | |
</filter> | |
- | |
<filter> | |
<filter-name>encodingFilter</filter-name> | |
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> | |
@@ -30,7 +29,6 @@ | |
<param-value>true</param-value> | |
</init-param> | |
</filter> | |
- | |
<filter> | |
<filter-name>messageFilter</filter-name> | |
<filter-class>org.appfuse.web.MessageFilter</filter-class> | |
@@ -43,10 +41,27 @@ | |
<!-- Use "org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter" if you're using JPA --> | |
<filter> | |
+ <filter-name>rewriteFilter</filter-name> | |
+ <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class> | |
+ <!-- sets up log level (will be logged to context log) | |
+ can be: TRACE, DEBUG, INFO (default), WARN, ERROR, FATAL, log4j, commons, sysout:{level} (ie, sysout:DEBUG) | |
+ if you are having trouble using normal levels use sysout:DEBUG --> | |
+ <init-param> | |
+ <param-name>logLevel</param-name> | |
+ <param-value>commons</param-value> | |
+ </init-param> | |
+ <!-- set the amount of seconds the conf file will be checked for reload | |
+ can be a valid integer (0 denotes check every time, | |
+ -1 denotes no reload check, default -1) --> | |
+ <init-param> | |
+ <param-name>confReloadCheckInterval</param-name> | |
+ <param-value>-1</param-value> | |
+ </init-param> | |
+ </filter> | |
+ <filter> | |
<filter-name>sitemesh</filter-name> | |
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class> | |
</filter> | |
- | |
<filter> | |
<filter-name>stripesFilter</filter-name> | |
<filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class> | |
@@ -61,8 +76,7 @@ | |
<init-param> | |
<param-name>Interceptor.Classes</param-name> | |
<param-value> | |
- net.sourceforge.stripes.integration.spring.SpringInterceptor, | |
- net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor | |
+ net.sourceforge.stripes.integration.spring.SpringInterceptor | |
</param-value> | |
</init-param> | |
<init-param> | |
@@ -83,44 +97,43 @@ | |
classpath:/applicationContext-service.xml | |
</param-value> | |
</context-param> | |
- | |
<filter-mapping> | |
<filter-name>encodingFilter</filter-name> | |
<url-pattern>/*</url-pattern> | |
</filter-mapping> | |
- | |
<filter-mapping> | |
<filter-name>messageFilter</filter-name> | |
<url-pattern>/*</url-pattern> | |
<dispatcher>REQUEST</dispatcher> | |
<dispatcher>FORWARD</dispatcher> | |
</filter-mapping> | |
- | |
<!--<filter-mapping> | |
<filter-name>lazyLoadingFilter</filter-name> | |
<url-pattern>/*</url-pattern> | |
</filter-mapping>--> | |
- | |
<filter-mapping> | |
<filter-name>exportFilter</filter-name> | |
- <url-pattern>*.html</url-pattern> | |
+ <url-pattern>*.action</url-pattern> | |
</filter-mapping> | |
- | |
<filter-mapping> | |
<filter-name>sitemesh</filter-name> | |
<url-pattern>/*</url-pattern> | |
</filter-mapping> | |
- | |
<filter-mapping> | |
+ <filter-name>rewriteFilter</filter-name> | |
+ <url-pattern>/*</url-pattern> | |
+ </filter-mapping> | |
+ <filter-mapping> | |
<filter-name>stripesFilter</filter-name> | |
<url-pattern>*.jsp</url-pattern> | |
<dispatcher>REQUEST</dispatcher> | |
+ <dispatcher>FORWARD</dispatcher> | |
</filter-mapping> | |
- | |
<filter-mapping> | |
<filter-name>stripesFilter</filter-name> | |
<servlet-name>stripesDispatcher</servlet-name> | |
<dispatcher>REQUEST</dispatcher> | |
+ <dispatcher>FORWARD</dispatcher> | |
</filter-mapping> | |
<listener> | |
@@ -132,7 +145,6 @@ | |
<servlet-class>net.sourceforge.stripes.controller.DispatcherServlet</servlet-class> | |
<load-on-startup>1</load-on-startup> | |
</servlet> | |
- | |
<servlet> | |
<servlet-name>dwr-invoker</servlet-name> | |
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class> | |
@@ -144,7 +156,7 @@ | |
<servlet-mapping> | |
<servlet-name>stripesDispatcher</servlet-name> | |
- <url-pattern>*.html</url-pattern> | |
+ <url-pattern>*.action</url-pattern> | |
</servlet-mapping> | |
<servlet-mapping> | |
Index: stripes/src/main/webapp/decorators/default.jsp | |
=================================================================== | |
--- stripes/src/main/webapp/decorators/default.jsp (revision 242) | |
+++ stripes/src/main/webapp/decorators/default.jsp (revision ) | |
@@ -70,7 +70,7 @@ | |
<h2 class="accessibility">Navigation</h2> | |
<ul class="clearfix"> | |
<li><a href="${ctx}/" title="Home"><span>Home</span></a></li> | |
- <li><a href="${ctx}/users.html" title="View Users"><span>Users</span></a></li> | |
+ <li><a href="${ctx}/users" title="View Users"><span>Users</span></a></li> | |
</ul> | |
</div> | |
</div><!-- end nav --> | |
Index: stripes/src/test/java/org/appfuse/web/UserWebTest.java | |
=================================================================== | |
--- stripes/src/test/java/org/appfuse/web/UserWebTest.java (revision 161) | |
+++ stripes/src/test/java/org/appfuse/web/UserWebTest.java (revision ) | |
@@ -23,7 +23,7 @@ | |
} | |
public void testAddUser() { | |
- beginAt("/userform.html"); | |
+ beginAt("/userform"); | |
assertTitleKeyMatches("userForm.title"); | |
setTextField("user.username", "stripesuser"); | |
setTextField("user.password", "stripespass"); | |
@@ -35,7 +35,7 @@ | |
} | |
public void testListUsers() { | |
- beginAt("/users.html"); | |
+ beginAt("/users"); | |
// check that table is present | |
assertTablePresent("userList"); | |
@@ -45,14 +45,14 @@ | |
} | |
public void testEditUser() { | |
- beginAt("/userform.html?id=" + getInsertedUserId()); | |
+ beginAt("/userform?id=" + getInsertedUserId()); | |
assertTextFieldEquals("user.firstName", "Spring"); | |
submit("save"); | |
assertTitleKeyMatches("userList.title"); | |
} | |
public void testDeleteUser() { | |
- beginAt("/userform.html?id=" + getInsertedUserId()); | |
+ beginAt("/userform?id=" + getInsertedUserId()); | |
assertTitleKeyMatches("userForm.title"); | |
submit("delete"); | |
assertTitleKeyMatches("userList.title"); | |
@@ -64,7 +64,7 @@ | |
* @return last id in the table | |
*/ | |
protected String getInsertedUserId() { | |
- beginAt("/users.html"); | |
+ beginAt("/users"); | |
assertTablePresent("userList"); | |
assertTextInTable("userList", "Spring"); | |
Table table = getTable("userList"); | |
Index: stripes/src/main/webapp/404.jsp | |
=================================================================== | |
--- stripes/src/main/webapp/404.jsp (revision 242) | |
+++ stripes/src/main/webapp/404.jsp (revision ) | |
@@ -68,7 +68,7 @@ | |
<h2 class="accessibility">Navigation</h2> | |
<ul class="clearfix"> | |
<li><a href="${ctx}/" title="Home"><span>Home</span></a></li> | |
- <li><a href="${ctx}/users.html" title="View Users"><span>Users</span></a></li> | |
+ <li><a href="${ctx}/users" title="View Users"><span>Users</span></a></li> | |
</ul> | |
</div> | |
</div><!-- end nav --> | |
Index: stripes/src/main/webapp/WEB-INF/urlrewrite.xml | |
=================================================================== | |
--- stripes/src/main/webapp/WEB-INF/urlrewrite.xml (revision ) | |
+++ stripes/src/main/webapp/WEB-INF/urlrewrite.xml (revision ) | |
@@ -0,0 +1,45 @@ | |
+<?xml version="1.0" encoding="UTF-8"?> | |
+<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.0//EN" | |
+ "http://tuckey.org/res/dtds/urlrewrite3.0.dtd"> | |
+ | |
+<urlrewrite default-match-type="wildcard"> | |
+ | |
+ <!-- Add rules here for anything that shouldn't be served up by Struts. --> | |
+ <rule> | |
+ <from>/dwr/**</from> | |
+ <to>/dwr/$1</to> | |
+ </rule> | |
+ <rule> | |
+ <from>/services/**</from> | |
+ <to>/services/$1</to> | |
+ </rule> | |
+ <rule> | |
+ <from>/images/**</from> | |
+ <to>/images/$1</to> | |
+ </rule> | |
+ <rule> | |
+ <from>/scripts/**</from> | |
+ <to>/scripts/$1</to> | |
+ </rule> | |
+ <rule> | |
+ <from>/styles/**</from> | |
+ <to>/styles/$1</to> | |
+ </rule> | |
+ | |
+ <!-- Struts --> | |
+ <rule match-type="regex"> | |
+ <from>^([^?]*)/([^?/\.]+)(\?.*)?$</from> | |
+ <to last="true">$1/$2.action$3</to> | |
+ </rule> | |
+ <outbound-rule match-type="regex"> | |
+ <from>^(.*)\.action(\?.*)?$</from> | |
+ <to last="false">$1$2</to> | |
+ </outbound-rule> | |
+ <!-- Remove JSESSIONID from URLs when cookies disabled --> | |
+ <!-- http://stackoverflow.com/questions/962729/is-it-possible-to-disable-jsessionid-in-tomcat-servlet --> | |
+ <outbound-rule encodefirst="true" match-type="regex"> | |
+ <name>Strip URL Session ID's</name> | |
+ <from>^(.*?)(?:\;jsessionid=[^\?#]*)?(\?[^#]*)?(#.*)?$</from> | |
+ <to>$1$2$3</to> | |
+ </outbound-rule> | |
+</urlrewrite> | |
Index: stripes/src/main/java/org/appfuse/web/UserListBean.java | |
=================================================================== | |
--- stripes/src/main/java/org/appfuse/web/UserListBean.java (revision 169) | |
+++ stripes/src/main/java/org/appfuse/web/UserListBean.java (revision ) | |
@@ -8,7 +8,7 @@ | |
import org.appfuse.service.UserManager; | |
import org.appfuse.model.User; | |
-@UrlBinding("/users.html") | |
+@UrlBinding("/users.action") | |
public class UserListBean extends BaseActionBean { | |
@SpringBean | |
private UserManager userManager; | |
Index: stripes/src/main/webapp/userList.jsp | |
=================================================================== | |
--- stripes/src/main/webapp/userList.jsp (revision 164) | |
+++ stripes/src/main/webapp/userList.jsp (revision ) | |
@@ -4,11 +4,11 @@ | |
<stripes:messages/> | |
-<button onclick="location.href='userform.html'" style="float: right; margin-top: -30px; width: 100px">Add User</button> | |
+<button onclick="location.href='userform'" style="float: right; margin-top: -30px; width: 100px">Add User</button> | |
-<display:table name="actionBean.users" class="table" requestURI="users.html" id="userList" export="true" pagesize="10" excludedParams="ajax"> | |
+<display:table name="actionBean.users" class="table" requestURI="users" id="userList" export="true" pagesize="10" excludedParams="ajax"> | |
<display:setProperty name="export.pdf.filename" value="users.pdf"/> | |
- <display:column property="id" sortable="true" href="userform.html" media="html" | |
+ <display:column property="id" sortable="true" href="userform" media="html" | |
paramId="id" paramProperty="id" titleKey="user.id"/> | |
<display:column property="id" media="csv excel xml pdf" titleKey="user.id"/> | |
<display:column property="firstName" sortable="true" titleKey="user.firstName" escapeXml="true"/> | |
Index: stripes/src/main/java/org/appfuse/web/UserFormBean.java | |
=================================================================== | |
--- stripes/src/main/java/org/appfuse/web/UserFormBean.java (revision 161) | |
+++ stripes/src/main/java/org/appfuse/web/UserFormBean.java (revision ) | |
@@ -71,6 +71,6 @@ | |
} | |
private Resolution showList() { | |
- return new RedirectResolution("/users.html").flash(this); | |
+ return new RedirectResolution("/users").flash(this); | |
} | |
} | |
\ No newline at end of file | |
Index: stripes/src/main/java/org/appfuse/web/ActionResolver.java | |
=================================================================== | |
--- stripes/src/main/java/org/appfuse/web/ActionResolver.java (revision 161) | |
+++ stripes/src/main/java/org/appfuse/web/ActionResolver.java (revision ) | |
@@ -15,12 +15,4 @@ | |
} | |
return name; | |
} | |
- | |
- /** | |
- * Set default suffix to .html instead of .action | |
- * @return ".html" | |
- */ | |
- protected String getBindingSuffix() { | |
- return ".html"; | |
- } | |
+} | |
-} | |
Index: stripes/src/main/webapp/userForm.jsp | |
=================================================================== | |
--- stripes/src/main/webapp/userForm.jsp (revision 161) | |
+++ stripes/src/main/webapp/userForm.jsp (revision ) | |
@@ -6,7 +6,7 @@ | |
<p>Please fill in user's information below:</p> | |
-<stripes:form action="/userform.html" id="userForm"> | |
+<stripes:form action="/userform.action" id="userForm"> | |
<stripes:errors globalErrorsOnly="true"/> | |
<stripes:hidden name="user.id"/> | |
<stripes:hidden name="user.version"/> | |
Index: stripes/src/main/webapp/index.jsp | |
=================================================================== | |
--- stripes/src/main/webapp/index.jsp (revision 216) | |
+++ stripes/src/main/webapp/index.jsp (revision ) | |
@@ -3,7 +3,7 @@ | |
<div id="intro"> | |
<h2>Welcome to AppFuse Light!</h2> | |
<p> | |
- <a href="http://appfuse-light.dev.java.net">AppFuse Light</a> is a lightweight version of <a href="http://appfuse.org">AppFuse</a>. | |
+ <a href="http://appfuse-light.java.net">AppFuse Light</a> is a lightweight version of <a href="http://appfuse.org">AppFuse</a>. | |
I was inspired to create it while writing <a href="http://springlive.com">Spring Live</a> and | |
looking at the <em>struts-blank</em> and <em>webapp-minimal</em> | |
applications that ship with Struts and Spring, respectively. | |
@@ -17,7 +17,7 @@ | |
to learn more about AppFuse Light. | |
</p> | |
<p> | |
- <button class="button" onclick="location.href='users.html'">View Demonstration</button> | |
+ <button class="button" onclick="location.href='users'">View Demonstration</button> | |
</p> | |
</div> | |
<div id="readmore" style="display:none"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment