[opencms-dev] Removing /opencms by a Filter class (web.xml)
Peter Birchmeier
peterbirchmeier at hotmail.com
Fri Sep 23 00:39:21 CEST 2005
Hi all,
My situation is: I'm using an OpenCms instance on a ISP server, so it's
difficult for me to update http.conf-rewrite statements. When I started
recently with the installation of jforum which should be included into the
same context, I realised that I would have to find another approach to solve
the path rewriting issue.
By chance i had the idea to use a Filter class that catches all requests to
the tomcat context and "rewrites" the uris by forwarding the requests to
other pathes.
Here's a basic example how it would look like:
public class ForwarderFilter implements Filter {
..
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
try {
HttpServletRequest req = (HttpServletRequest) request;
String uri = req.getRequestURI(); // e.g. /forum/list.page
int pos1 = 1, pos2 = uri.indexOf("/", pos1);
if ( pos != -1 ) {
String part = uri.substring( pos1, pos2 );
if ( part.equals( "forum" ) ) {
chain.doFilter(request, response);
return;
}
}
String forward = "/opencms" + uri;
RequestDispatcher dispatcher = request.getRequestDispatcher(forward);
dispatcher.forward(request, response);
} catch ( Exception e ) { chain.doFilter(request, response); }
}
...
}
and the web.xml directives:
<filter>
<filter-name>ForwarderFilter</filter-name>
<filter-class>.....ForwarderFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ForwarderFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
My main question is now: Is this a PERFORMANCE problem?
I haven't tested this method 100% but it looks promising. At the moment, I
go the bidirect way, meaning, Apache is rewriting everything to /opencms,
and my ForwarderFilter removes /opencms if necessary...
If this approach hasn't got significant performance issues, I would greatly
prefer it over all others, in my situation of course, due to the fact that I
can easily change the filter class and do not have to ask the ISP everytime.
Additionally, I would be able to realise a fine grained rewriting (what I
couldn't achieve in Apache 1.3)...
Thanks for your opinion,
regard Peter
_________________________________________________________________
Highlight Viewer - heben Sie von Ihnen gesuchte Wörter auf Webseiten hervor.
http://toolbar.msn.ch?&DI=165&XAPID=2170
More information about the opencms-dev
mailing list