Hello,

I've included a patch for bug #6640 with this mail. I don't know how many people are using the JumpersFilter and because I'm not absolutely sure nothing will break with some specific jumpers, I haven't checked in this patch. Maybe somebody can test it with their own jumpers?

I've tested all different kinds of jumpers I could think of:
- absolute with a scheme (http://www.servername.nl/context/bla/bla123),
- absolute without a scheme (/bla/bla123)
- relative (bla/bla123)

If no problems are found I'll put the patch in cvs (head an 1.7 branch).

Gerard
Index: JumpersFilter.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/servlet/JumpersFilter.java,v
retrieving revision 1.9
diff -u -r1.9 JumpersFilter.java
--- JumpersFilter.java  24 Feb 2004 11:53:19 -0000      1.9
+++ JumpersFilter.java  30 Dec 2004 15:19:25 -0000
@@ -11,6 +11,8 @@
 
 import javax.servlet.*;
 import javax.servlet.http.*;
+import java.net.URI;
+import java.net.URISyntaxException;
 import org.mmbase.module.builders.Jumpers;
 import org.mmbase.module.core.*;
 import org.mmbase.util.logging.*;
@@ -57,7 +59,7 @@
         // never mind, simply, ignore
     }
     /**
-     * @javadoc
+     * Initializes the filter
      */
     public void init(javax.servlet.FilterConfig filterConfig) throws 
ServletException {
         name = filterConfig.getFilterName();
@@ -71,7 +73,11 @@
     }
 
     /**
-     * @javadoc
+     * Filters the request: tries to find a jumper and redirects to this url 
when found, otherwise the 
+     * request will be handled somewhere else in the filterchain.
+     * @param servletRequest The ServletRequest.
+     * @param servletResponse The ServletResponse.
+     * @param filterChain The FilterChain.
      */
     public void doFilter(ServletRequest servletRequest, ServletResponse 
servletResponse, FilterChain filterChain) throws java.io.IOException, 
ServletException {
         if (bul == null) {
@@ -92,15 +98,33 @@
          * The path starts with a "/" character but does not end with a "/" 
character.
          * For servlets in the default (root) context, this method returns "". 
The container does not decode this string.
          */
-        int contextPart = req.getContextPath().length();
+        String context = "";
+        context = req.getContextPath();
+        int contextPart = context.length();
         String reqURI = req.getRequestURI();
         String key = "";
         if (contextPart < reqURI.length()) {
             // also remove the leading "/", unless it's an empty string.
-            key = 
req.getRequestURI().substring(req.getContextPath().length()+1);
+            key = req.getRequestURI().substring(context.length()+1);
         }
 
-        if (key.indexOf('.') == -1 && !key.endsWith("/")) {
+        if (log.isDebugEnabled()) {
+            log.debug("contextpath is: " + context);
+            log.debug("key is: " + key);
+            log.debug("uri is: " + reqURI);
+        }
+        
+        //ignore keys with extensions
+        if (key.indexOf('.') == -1 ) {
+            // because Tomcat version > 5.0.5 always adds a trailing slash if
+            // there's a directory with the same name, the trailing slash must 
be removed
+            if (key.endsWith("/")) {
+                key = key.substring(0,key.length()-1);
+                if (log.isDebugEnabled()){
+                    log.debug("after removing trailing slash key becomes: " + 
key);
+                }
+            }
+            //get jumper from Jumpers builder
             String url = bul.getJump(key);
             if (url != null) {
                 /*
@@ -113,7 +137,27 @@
                  *  After using this method, the response should be considered 
to be committed and should not be written to.
                  */
                 // res.sendRedirect(res.encodeRedirectURL(req.getContextPath() 
+ url));
-                res.sendRedirect(url);
+
+                // there can be different types of jumper uris which all must 
behandled
+                // differently:
+                // - absolute with a scheme 
(http://www.servername.nl/context/bla/bla123), muste be redirected
+                // - absolute without a scheme (/bla/bla123), must be 
redirected
+                // - relative (bla/bla123), must be made absolute and then be 
redirected
+                URI redirURI = null;
+                try {
+                    redirURI = new URI(url);
+                } catch (URISyntaxException ex) {
+                    log.error ("jumper URI syntax is not valid");
+                }
+                if (redirURI != null) {
+                    if (redirURI.isAbsolute()) {
+                        res.sendRedirect(url);
+                    } else if (url.startsWith("/")) {
+                        res.sendRedirect(url);
+                    } else {
+                        res.sendRedirect(context +"/" + url);
+                    }
+                }
                 return;
             }
         }
@@ -121,7 +165,7 @@
     }
 
     /**
-     * @javadoc
+     * destroys the filter
      */
     public void destroy() {
         log.info("Filter " + name + " destroyed.");
_______________________________________________
Developers mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/developers

Reply via email to