ObjectWeb Consortium
Search ObjectWeb Mail Archive: 

Advanced Search - Powered by Google


Mail Archive Home | enhydra List | June 2004 Index

<--  Date Index  --> <--  Thread Index  -->

patch for the ServerSideRedirectException code I posted 20 months ago


Hi all,

I found the problem I posted here (subject "doubled query values")
earlier this week. It was a bug in my own code in Enhydra. I am
attaching a patch (fixbug.diff) that can be applied safely because it
changes code that is commented out.

However I would like to get accepted the other patch instead
(cleanupandexplain.diff). This one touches live code but makes it
clearer and explains why there are two ways of redirecting and their
pros and cons.

Thanks for accepting this patch. I hope I'll never run into this problem
again :)

Petr

P.S. remember the cleanupandexplain.diff replaces the fixbug.diff. Don't
try to apply one on top of the other.

--- /tmp/StandardApplication.java	2004-04-14 17:55:32.000000000 +0200
+++ modules/EnhydraAppManager/src/com/lutris/appserver/server/StandardApplication.java	2004-06-18 16:47:15.000000000 +0200
@@ -669,11 +669,6 @@
                 } else {
                     target = defaultUrl;
                 }
-                // get query string and add it to target
-                String query = comms.request.getQueryString();
-                if (query != null) {
-                    target += "?" + query;
-                }
                 throw new ServerPageRedirectException(target);
             }
 	}
--- /tmp/enhydra-5.1/modules/EnhydraAppManager/src/com/lutris/appserver/server/StandardApplication.java	2004-04-14 17:55:32.000000000 +0200
+++ modules/EnhydraAppManager/src/com/lutris/appserver/server/StandardApplication.java	2004-06-18 17:20:53.000000000 +0200
@@ -41,6 +41,7 @@
 import org.enhydra.xml.xmlc.deferredparsing.XMLCDeferredParsingFactory;
 
 import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
+import com.lutris.appserver.server.httpPresentation.ServerPageRedirectException;
 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
 import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
 import com.lutris.appserver.server.httpPresentation.HttpPresentationManager;
@@ -654,7 +655,6 @@
 	/**
 	 * Remap / ---> "defaultUrl" if defined.
 	 */
-	 /*
 	if (defaultUrl != null) {
 	    String ap = comms.request.getApplicationPath();
 	    if (!ap.endsWith("/"))
@@ -663,50 +663,53 @@
 	    if (!page.endsWith("/"))
 		page += "/";
 	    if (page.equals(ap)) {
-                String target="";
+                String target;
                 if (defaultUrl.startsWith("/")) {
                     target = defaultUrl.substring(1);
                 } else {
                     target = defaultUrl;
                 }
-                // get query string and add it to target
-                String query = comms.request.getQueryString();
-                if (query != null) {
-                    target += "?" + query;
-                }
-                throw new ServerPageRedirectException(target);
-            }
-	}
-*/
-	/**
-	 * Remap / ---> "defaultUrl" if defined.
-	 */
-	if (defaultUrl != null) {
-	    String ap = comms.request.getApplicationPath();
-	    if (!ap.endsWith("/"))
-		ap += "/";
-	    String page = comms.request.getPresentationObjectPath();
-	    if (!page.endsWith("/"))
-		page += "/";
-	    if (page.equals(ap)) {
-                // Don't want two slashes in a row.
-                String target = comms.request.getHttpServletRequest().getContextPath();
-                if (target.equals("/")) {
-                    target = "";
-                }
-                target = "";
-
-                if (defaultUrl.startsWith("/")) {
-                    target += ap + defaultUrl.substring(1);
-                } else {
-                    target += ap + defaultUrl;
-                }
-                // get query string and add it to target
-                String query = comms.request.getQueryString();
-                if (query != null) {
-                    target += "?" + query;
+                /*
+                 * For redirecting to the defaultUrl we may use either
+                 * Client- or Server- PageRedirectException.
+                 * Each has its pros and cons:
+                 *
+                 *   ClientPageRedirectException can redirect into a folder
+                 *   (when defaultUrl contains a path, not just page name)
+                 *   but it does not preserve information send in a POST
+                 *   request (output of a <form method="post" action="/">)
+                 *   Also ClientPageRedirect takes longer because it has
+                 *   to instruct client browser to go and load another page.
+                 *
+                 *   ServerPageRedirectException does preserve the POST
+                 *   parameters but cannot redirect you to a subfolder
+                 *   safely because client's browser still points to
+                 *   the "/" URL. If you used relative URLs in the subfolder
+                 *   page and tried to go to a sibbling page it would fail
+                 *   (DiscRack demo is an example of an application that
+                 *   wouldn't work with the ServerPageRedirect).
+                 *
+                 *   Neither solution is clearly superior so we stick with
+                 *   the ClientPageRedirectException mainly for backward
+                 *   compatibility. Be warned and don't try to send POST
+                 *   requests to your "/". Or edit the source line below
+                 *   and change the if (true) to (false). After rebuilding
+                 *   Enhydra you'll get the ServerPageRedirect.
+                 *
+                 *   Comments or questions to Enhydra mailing list.
+                 *   Petr Stehlik on 2004/06/18.
+                 */
+                if (true) {
+                    // get query string and add it to target
+                    String query = comms.request.getQueryString();
+                    if (query != null) {
+                        target += "?" + query;
+                    }
+                    throw new ClientPageRedirectException(target);
                 }
-                throw new ClientPageRedirectException(target);
+                else {
+               	    throw new ServerPageRedirectException(target);
+               	}
             }
 	}
 


<--  Date Index  --> <--  Thread Index  -->

Reply via email to:

Powered by MHonArc.

Copyright © 1999-2005, ObjectWeb Consortium | contact | webmaster.