You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Peter Lynch <pe...@yahoo.com> on 2001/07/03 02:25:22 UTC

Turbine.java redirect does not look right

In the turbine servlet there is code that does a
redirect if getRedirectURI() != null.

I would think that immediately after that, there
whould be a "return;" as the next few lines before the
end of the of try block are not intended to be
executed, I think. The lines are...

// Set the status code.
data.getResponse().setStatus ( data.getStatusCode() );
// Output the Page.
data.getPage().output (data.getOut());

Putting a "return;" does not prevent the finally{} of
the try block from executing if that is what was
thought by not putting it there. So the RunData will
get added back to the cache regardless.

What was intended by not putting a "return;" here and
is it a potential bug?

-Peter



__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Turbine.java redirect: query

Posted by James Devenish <j-...@users.sourceforge.net>.
On Mon, Jul 02, 2001 at 05:37:16PM -0700, Jon Stevens wrote:
> In either case, #1, must be executed so that one can control the type of
> status response (301 or 302).

Why does Turbine only honour 301 and 302? What about other codes? For
example, 303, 305 and 307 (are there others?). They may not be
understood by HTTP/1.0 browsers, but some people may have a restricted
usage where only HTTP/1.1 browsers (or other software) is going to
access the resources and it would be good to do things the modern
fashion rather than the backward-compatible fashion. It would seem
trivial to add these to the conditional clause, yet they have not
been. Is this intentional, or just an oversight?

Perhaps it would be good to put some of the turbine-user queries and
responses into the FAQ, and make the FAQ easier to find.


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Turbine.java redirect does not look right

Posted by James Devenish <j-...@users.sourceforge.net>.
On Mon, Jul 02, 2001 at 05:37:16PM -0700, Jon Stevens wrote:
> > Putting a "return;" does not prevent the finally{} of
> > the try block from executing if that is what was
> > thought by not putting it there. So the RunData will
> > get added back to the cache regardless.
> > 
> > What was intended by not putting a "return;" here and
> > is it a potential bug?
> 
> There is a case where a redirect header will get ignored by older (2.x?)
> browsers. In that case, it is a good idea to output a HTML page with a link
> in it so that people can click on it to continue.

Well Peter,

As Jon says, the redirect response should contain an HTML page with a
link in it, at least. This is not just for different browsers but for
non-browsers such as mirroring software. The mirroring software may be
told not to follow redirects that do or do not match certain servers or
paths. However, it is still valuable to have the link present so that an
end user can access the resource that was not mirrored. Of course, this
may not apply to your web application if it is for in-house purposes
only.

Nevertheless, I think it is the right thing to do if you are being
a "good citizen". So, imagine a page which looks like a 404 Not Found
page but which is instead a 302 Found page with a URL in it. If
you're using redirects then consider making a screen for this called
Redirect.vm (or whatever templating mechanism you use) that simply
outputs an HTML link with the message "This resource may be found at..."
or something. Then before your setRedirectURI, invoke setTemplate as
appropriate. Some browsers may use this as a fallback page if the
resource to which you have redirected them is not accessible (eg. a
server is down, etc.).

As a point of interest you can consider that if a client requests a
resource x and you redirect them using 302 to a resource y which is an
image/gif, for instance, the 302 response should actually be text/html
page. It is then up to the browser to make use of the 302 response
headers to access resource y. So your response to a request for x
would actually be a text/html, not image/gif.


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Turbine.java redirect does not look right

Posted by Jon Stevens <jo...@latchkey.com>.
on 7/2/01 5:25 PM, "Peter Lynch" <pe...@yahoo.com> wrote:

> In the turbine servlet there is code that does a
> redirect if getRedirectURI() != null.
> 
> I would think that immediately after that, there
> whould be a "return;" as the next few lines before the
> end of the of try block are not intended to be
> executed, I think. The lines are...
> 
> // Set the status code.
#1. > data.getResponse().setStatus ( data.getStatusCode() );
> // Output the Page.
#2. > data.getPage().output (data.getOut());
> 
> Putting a "return;" does not prevent the finally{} of
> the try block from executing if that is what was
> thought by not putting it there. So the RunData will
> get added back to the cache regardless.
> 
> What was intended by not putting a "return;" here and
> is it a potential bug?
> 
> -Peter

I totally see where you are coming from, but wish to discuss this a bit
further...(notice that I made a #1 and #2 above)...

There is a case where a redirect header will get ignored by older (2.x?)
browsers. In that case, it is a good idea to output a HTML page with a link
in it so that people can click on it to continue.

In either case, #1, must be executed so that one can control the type of
status response (301 or 302).

Is the in-efficiency of #2 in the case of a redirect really worth anything?
Personally, I don't think so because it allows us to still have the feature
to output content.

Having said that, here is the patch that would do what you want. Move the
setStatus() to the top and then only output content if it isn't a redirect.

Index: org/apache/turbine/Turbine.java
===================================================================
RCS file: 
/home/cvs/jakarta-turbine/src/java/org/apache/turbine/Turbine.java,v
retrieving revision 1.61
diff -r1.61 Turbine.java
563a564,566
>                     // Set the status code.
>                     data.getResponse().setStatus ( data.getStatusCode() );
>
573,577c576,580
<
<                     // Set the status code.
<                     data.getResponse().setStatus ( data.getStatusCode() );
<                     // Output the Page.
<                     data.getPage().output (data.getOut());
---
>                     else
>                     {
>                         // Output the Page.
>                         data.getPage().output (data.getOut());
>                     }

I'm not going to apply this to CVS quite yet because I think that the
feature of being able to output content is worth the minor in-efficiency in
a redirect (which is already highly inefficient and in most cases shouldn't
be used anyway).

Thanks,

-jon


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org