[opencms-dev] Removing /opencms by a Filter class (web.xml)
Peter Birchmeier
peterbirchmeier at hotmail.com
Fri Sep 23 01:30:20 CEST 2005
I just tested the Filter class and it works :)
here a slightly modified version:
private final static String[] EXCLUDES = new String[] {
"export", "resources", "opencms", "forum"
};
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
try {
HttpServletRequest req = (HttpServletRequest) request;
String uri = req.getRequestURI();
int pos1 = 1, pos2 = uri.indexOf("/", pos1);
if ( pos2 != -1 ) {
String part = uri.substring( pos1, pos2 );
boolean exclude = false;
for (int i=0; i<EXCLUDES.length; i++) {
if (uri.equals(EXCLUDES[i])) {
exclude = true;
break;
}
}
if (exclude) {
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); }
}
>From: "Peter Birchmeier" <peterbirchmeier at hotmail.com>
>Reply-To: The OpenCms mailing list <opencms-dev at opencms.org>
>To: opencms-dev at opencms.org
>Subject: [opencms-dev] Removing /opencms by a Filter class (web.xml)
>Date: Fri, 23 Sep 2005 00:39:21 +0200
>
>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
>
>
>
>_______________________________________________
>This mail is send to you from the opencms-dev mailing list
>To change your list options, or to unsubscribe from the list, please visit
>http://mail.opencms.org/mailman/listinfo/opencms-dev
_________________________________________________________________
Umfangreich, essenziell und aktuell! Auf MSN Search werden Sie schnell
fündig! http://search.msn.ch/
More information about the opencms-dev
mailing list