On Wed, Nov 29, 2000 at 10:06:56PM +0000, Sean Legassick wrote:
> I think that there is a redirect loop problem when the initial URL that
> loads the Turbine servlet includes a reference to a specific template.
>
> I.E. If my first access to a TDK newapp is:
>
> http://localhost:8080/newapp/servlet/newapp
>
> all is fine.
>
> If instead I use
>
> http://localhost:8080/newapp/servlet/newapp/template/TestTemplate.vm
>
> then I get a redirect loop (mozilla M18 has a special error page). Further
> uses of the same URl are fine.
>
> I reckon this is related to the stuff in Turbine.java to redirect back with
> a session ID, but I haven't looked at it in any detail as its not a huge
> problem to me...
I decided to have a further look at this and worked out the problem.
Basically where cookies are used for the session data the browser gets
redirected to an identical URI. Actually this is OK, because this time
the session won't be new but the browser doesn't know this so complains
about a redirect loop.
This used to be avoided by the addition of screen/screen.homepage to the
URI, but John commented out this code - rightly IMO - because it's not
relevant where templates are used.
I've come up with a fix which involves adding a 'redirected=true' piece
of pathinfo when redirecting. This fools the browser into thinking it
has a different URI, and also means that a redirect loop can be spotted
by looking for that parameter in the URI.
I've attached the patch - if no-one has any objections I'll commit it...
Index: Turbine.java
===================================================================
RCS file: /products/cvs/turbine/turbine/src/java/org/apache/turbine/Turbine.java,v
retrieving revision 1.18
diff -u -r1.18 Turbine.java
--- Turbine.java 2000/11/21 16:05:00 1.18
+++ Turbine.java 2000/12/04 17:07:11
@@ -254,12 +254,7 @@
data.getSession().isNew() )
{
DynamicURI duri = new DynamicURI (data, true);
- // String homepage =
- // TurbineResources.getString("screen.homepage", null);
- // if (homepage != null)
- // {
- // duri.setScreen(homepage);
- // }
+
// Pass on the sent data in pathinfo.
for (Enumeration e = data.getParameters().keys() ;
e.hasMoreElements() ;)
@@ -269,27 +264,22 @@
(String) data.getParameters().getString ( key );
duri.addPathInfo((String)key, (String)value );
}
-
- /*
- Currently commented out because it caused a bunch of
- problems for some people. Left in here for
- reference.
- // Make sure that this URL you are about to redirect
- // to is not the current URL. If it is and you
- // redirect to it you will get caught in an infinite
- // redirect loop.
- String currentURI = DynamicURI.toString( data );
-
- if ( duri.toString().equals( currentURI ) )
+ // add a dummy bit of path info to fool browser into thinking
+ // this is a new URL
+ if (data.getParameters().getString("redirected") == null)
{
+ duri.addPathInfo("redirected", "true");
+ }
+ // if the redirected param was already there then we've been
+ // round this once already :-(
+ else
+ {
String message = "Infinite redirect detected...";
log(message);
Log.error(message);
throw new Exception(message);
- }
-
- */
+ }
data.getResponse().sendRedirect( duri.toString() );
return;
--
Sean Legassick
[EMAIL PROTECTED]
homo sum: humani nihil a me alienum puto
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?: [EMAIL PROTECTED]