UrlRewrite and SiteMesh

212 views
Skip to first unread message

verytired1

unread,
Mar 15, 2007, 7:16:59 PM3/15/07
to UrlRewrite
I'm using Spring, SiteMesh and UrlRewrite in an application.
UrlRewrite works fine on redirecting the requests to the appropriate
JSP's. The JSP's work properly but they do not get decorated if I use
a <to type="forward">. They do work if I do <to type="redirect">.
SiteMesh always properly decorates all the non-rewritten pages. I
feel like I must be making a stupid mistake somewhere since it seems
like others use this same combination of technologies. I searched
here and and on the SiteMesh site for any relevant info, but couldn't
find anything.

These are the only filters I'm using on the app. Here is the excerpt
from my web.xml


<!-- OSIV filter -->
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate.support.OpenSessionInViewFilter
</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!-- mod_rewrite type filter -->
<filter>
<filter-name>urlRewriteFilter</filter-name>
<filter-class>
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
</filter-class>
<init-param>
<param-name>statusEnabled</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>urlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!-- Sitemesh for templating -->
<filter>
<filter-name>siteMesh</filter-name>
<filter-class>
com.opensymphony.module.sitemesh.filter.PageFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>siteMesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


Anybody have any ideas or can point me to a resource that might help
me understand what's going on?

Paul Tuckey

unread,
Mar 15, 2007, 7:53:16 PM3/15/07
to urlre...@googlegroups.com
Hi,

I think your filter-mapping for sitemesh needs to be above the
filter-mapping for urlrewrite.

Cheers,
Paul.

AndreJ

unread,
Mar 16, 2007, 10:36:22 AM3/16/07
to UrlRewrite
Hello,
I have the exact same setup and problem.

Changing the order of filter-mappings does not seem to help... also
shouldn't urlrewrite filter come first anyway as the sitemesh filter
needs the actual url?

Regards,
AndreJ

On Mar 16, 12:53 am, "Paul Tuckey" <p...@tuckey.org> wrote:
> Hi,
>
> I think your filter-mapping for sitemesh needs to be above the
> filter-mapping for urlrewrite.
>
> Cheers,
> Paul.
>

verytired1

unread,
Mar 16, 2007, 11:36:36 AM3/16/07
to UrlRewrite
I thought it would be something simple like that. That seems to have
fixed it. Thanks for the help!

AndreJ

unread,
Mar 16, 2007, 12:35:58 PM3/16/07
to UrlRewrite
I still can't get it to work :(
I must have missed something here. Think you could help me out if you
got it sorted?

Also I can't seem to get any log output from UrlRewriteFilter...

Any help is appreciated!

My setup:

Container: JBoss 4.0.4.GA (Tomcat 5.5)

web.xml
-----------
<servlet>
<servlet-name>TheApp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</
servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>TheApp</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>

<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</
filter-class>
</filter>

<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</
filter-class>
<init-param>
<param-name>logLevel</param-name>
<param-value>log4j:DEBUG</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

---

decorators.xml
---------------
<decorators defaultdir="/decorators">
<decorator name="main" page="main.jsp">
<pattern>/page.html*</pattern>
</decorator>
</decorators>
---


I'm accessing the page by http://localhost:8080/context/some/path

These are the rules I've tried:

<rule>
<from>^/some/path$</from>
<to type="forward">/page.html?id=41&amp;menu=41</to>
</rule>
Result: page is not decorated by sitemesh filter

<rule>
<from>^/some/path$</from>
<to type="passthrough">/page.html?id=41&amp;menu=41</to>
</rule>
Result: page is not decorated by sitemesh filter


<rule>
<from>^/some/path$</from>
<to type="redirect">%{context-path}/page.html?id=41&amp;menu=41</to>
</rule>
Result: everything works, except the <to> url shows in address bar

<rule>
<from>^/some/path$</from>
<to type="redirect" encode="true">%{context-path}/page.html?
id=41&amp;menu=41</to>
</rule>
<outbound-rule>
<from>/page.html?id=42&amp;menu=42</from>
<to>/some/path</to>
</outbound-rule>
Result: same, outbound rule has no effect

<rule>
<from>^/some/path$</from>
<to type="redirect">%{context-path}/page.html?id=41&amp;menu=41</to>
</rule>
<outbound-rule>
<from>/page.html?id=42&amp;menu=42</from>
<to>/some/path</to>
</outbound-rule>
Result: same, outbound rule has no effect

<rule>
<from>^/some/path$</from>
<to type="redirect">%{context-path}/page.html?id=41&amp;menu=41</to>
</rule>
<outbound-rule>
<from>%{context-path}/page.html?id=42&amp;menu=42</from>
<to>%{context-path}/some/path</to>
</outbound-rule>
Result: 404 not found: /context/some/path

<rule>
<from>^/some/path$</from>
<to type="redirect">%{context-path}/page.html?id=41&amp;menu=41</to>
</rule>
<outbound-rule>
<from>%{context-path}/page.html?id=42&amp;menu=42</from>
<to>/some/path</to>
</outbound-rule>
Result: 404 not found: /context/some/path

<rule>
<from>^/some/path$</from>
<to type="forward">%{context-path}/page.html?id=42&amp;menu=42</
to>
</rule>
<outbound-rule>
<from>/page.html?id=42&amp;menu=42</from>
<to>/some/path</to>
</outbound-rule>
Result: [org.springframework.web.servlet.PageNotFound] No mapping for
[/context/context/page.html]

janning

unread,
Mar 17, 2007, 7:51:40 AM3/17/07
to UrlRewrite
Maybe you run in a servlet 2.4 or 2.5 environment and you need
<dispatcher> configurations like this as urlrewriter FORWARDS the
rewritten Url:
(only filter-mappings are shown as filter are defined as usual):

<filter>...</filter>


<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>

<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>

<!-- Sitemesh filter -->
<!--
Sitemesh Filter must accept FORWARD Dispachter for Request
rewritten by UrlRewriterfilter
-->
<filter>...</filter>

<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/webapp/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>


AndreJ

unread,
Mar 17, 2007, 11:02:58 AM3/17/07
to UrlRewrite
Yes you are right, janning, thank you very much!

ravi

unread,
Mar 20, 2007, 3:31:25 PM3/20/07
to UrlRewrite
Hi paul,

I am having similar problem with the urlrewrite, The url's are been
rewritten correctly as expected but not for all the links. It is not
rewritting the urls for the jsp:include pages. for example.
This is my main template.
The urls in the<jsp:include page="/common/header.jsp"/> and
<jsp:include page="/common/footer.jsp"/> are not rewritten but only
urls in <decorator:body/> are rewritten.

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<%-- Include common set of meta tags for each layout --%>
<%@ include file="/common/meta.jsp" %>
<title><decorator:title/></title>

<link rel="stylesheet" type="text/css" media="all"
href="<c:url value='/styles/default.css'/>" />
<link rel="stylesheet" type="text/css" media="all"
href="<c:url value='/styles/messages.css'/>" />
<link rel="stylesheet" type="text/css" media="all"
href="<c:url value='/styles/displaytag.css'/>" />

<decorator:head/>
</head>
<body <decorator:getProperty property="body.id"
writeEntireProperty="true"/> leftmargin="0" topmargin="0"
marginwidth="0" marginheight="0" bgcolor="#f8f8f8">
<div style="background-color:transparent;width:1px;height:5px;"></
div>
<table cellpadding="0" cellspacing="0" border="0" width="1000"
align="center">
<tr>
<td id="header"><br><jsp:include page="/common/header.jsp"/></
td>
</tr>
<tr>
<td id="content" align="center"><decorator:body/></td>
</tr>
<tr>
<td id="footer"><jsp:include page="/common/footer.jsp"/></td>
</tr>
</table>
</body>
</html>

urlrewirte.xml This is my outbound rule to strip the jsessionId.


<outbound-rule encodefirst="true">
<name>remove outbound jsessionid</name>
<from>^(.*);jsessionid=[^\?]*(.*)$</from>
<to>$1$2</to>
</outbound-rule>

This is my web.xml file :
<filter-mapping>
<filter-name>pageCachingFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>compressionFilter</filter-name>
<url-pattern>*.html</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>localeFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>


Help please....

Thanks.

On Mar 15, 7:53 pm, "Paul Tuckey" <p...@tuckey.org> wrote:
> Hi,
>
> I think your filter-mapping for sitemesh needs to be above the
> filter-mapping for urlrewrite.
>
> Cheers,
> Paul.
>

janning

unread,
Mar 21, 2007, 4:23:31 AM3/21/07
to UrlRewrite
Try this in a servlet 2.4/2.5 environment:
<filter-mapping>
<filter-name>urlrewrite</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>INCLUDE</dispatcher>

<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
Reply all
Reply to author
Forward
0 new messages