You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jc...@apache.org on 2007/03/09 22:16:20 UTC

svn commit: r516552 - /incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java

Author: jcompagner
Date: Fri Mar  9 13:16:20 2007
New Revision: 516552

URL: http://svn.apache.org/viewvc?view=rev&rev=516552
Log:
also buffer setStatus so that it doesn't get send with the redirect but really only when te redirect is rendered

Modified:
    incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java

Modified: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java?view=diff&rev=516552&r1=516551&r2=516552
==============================================================================
--- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java (original)
+++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java Fri Mar  9 13:16:20 2007
@@ -54,6 +54,9 @@
 	/** cookies list */
 	private List cookies;
 
+	/** status list */
+	private List status;
+
 	/** headers map */
 	private Map headers;
 
@@ -282,7 +285,11 @@
 	 */
 	public void setStatus(int sc)
 	{
-		realResponse.setStatus(sc);
+		if (status == null)
+		{
+			status = new ArrayList(2);
+		}
+		status.add(new Integer(sc));
 	}
 
 	/**
@@ -292,8 +299,7 @@
 	 */
 	public void setStatus(int sc, String sm)
 	{
-		isOpen();
-		realResponse.setStatus(sc, sm);
+		throw new UnsupportedOperationException("not supported in tbe bufferd http response, use setStatus");
 	}
 
 	/**
@@ -506,6 +512,14 @@
 	 */
 	public void writeTo(HttpServletResponse servletResponse) throws IOException
 	{
+		if (status != null)
+		{
+			Iterator it = status.iterator();
+			while (it.hasNext())
+			{
+				servletResponse.setStatus( ((Integer)it.next()).intValue());
+			}
+		}
 		if (headers != null)
 		{
 			Iterator it = headers.entrySet().iterator();



Re: svn commit: r516552 - /incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java

Posted by Johan Compagner <jc...@gmail.com>.
> Yes, please  keep only an int.   BTW, thanks for the  fix.  I also


change it to an int.
(i am on an airport with not a very good connection )

fixed it  before you, but the  wrong way, so I'm  reverting my own
> commit now.   Except the extra unit  tests, I keep them,  they are
> always good to detect that kind of things and fail early.


more unit test are always good ! :)

However I admit I don't really understand the REDIRECT_TO_BUFFER
> thing.  Can you explain what is the purpose of this?


see eelco's reply and:
Also what it is mostly helpfull for is that the request/listener invoke and
the response/render phase
are done in the same request. This is very helpfull for hibernate objects
and sessions etc
Because if we would really do a redirect after post. Then we do a detach of
the page after the listener invoke
then everything gets detached and then the page comes back and must be
attached again.
Most programmeurs don't think this way. The request and response are the
same thread/event they expect it more
or less to be in one pass.

johan

Re: svn commit: r516552 - /incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java

Posted by Igor Vaynberg <ig...@gmail.com>.
basically the advantage being that you always have a GET url that points to
a VIEW in the browser, and never a POST url that points to an ACTION. so if
user presses refresh or back you never see that annoying "submit post
values" popup and pressing refresh never triggers any action as well.

-igor


On 3/9/07, Eelco Hillenius <ee...@gmail.com> wrote:
>
> > However I admit I don't really understand the REDIRECT_TO_BUFFER
> > thing.  Can you explain what is the purpose of this?
>
>         /**
>          * All logical parts of a request (the action and render part) are
> handled
>          * within the same request, but instead of streaming the render
> result to
>          * the browser directly, the result is cached on the server. A
> client side
>          * redirect command is issued to the browser specifically to
> render this
>          * request.
>          */
>         public static final IRequestCycleSettings.RenderStrategy
> REDIRECT_TO_BUFFER = new IRequestCycleSettings.RenderStrategy(
>                         "REDIRECT_BUFFER");
>
> It is a variation of the theme that commonly is named 'redirect after
> post' in other frameworks, only we do it for everything including
> links. And if fact, most frameworks don't even have a default facility
> for this, so while it's not a feature that will immediately obvious to
> people new to Wicket, it is actually a pretty cool 'selling point'.
>
> There are three options with wicket:
> * the default, redirect to buffer, which renders the whole response to
> a buffer kept in the application (with a max of three) and immediately
> redirect to a request that just streams out that buffer
> * redirect to render, which separates the 'action' and 'render' phase
> of the request. Not typically recommended, but needed for portlets
> * one pass render, which doesn't do any redirect magic. But that means
> that you'll have to provide a solution for the redirect after post
> thing yourself (if you care, but you should imo).
>
> Eelco
>

Re: svn commit: r516552 - /incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java

Posted by Jean-Baptiste Quenot <jb...@apache.org>.
Thanks all for your explanations.  This article also helped me
understand the concept:
http://www.theserverside.com/tt/articles/article.tss?l=RedirectAfterPost

However, while I understand the need  for this in general, I don't
think  it's very  useful for  an error  page, is  it?  Because  if
REDIRECT_TO_BUFFER is false, anyway we store the exception page in
the session.   I don't  think there's a  difference in  that case,
right?
-- 
     Jean-Baptiste Quenot
aka  John Banana   Qwerty
http://caraldi.com/jbq/

Re: svn commit: r516552 - /incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java

Posted by Eelco Hillenius <ee...@gmail.com>.
> However I admit I don't really understand the REDIRECT_TO_BUFFER
> thing.  Can you explain what is the purpose of this?

	/**
	 * All logical parts of a request (the action and render part) are handled
	 * within the same request, but instead of streaming the render result to
	 * the browser directly, the result is cached on the server. A client side
	 * redirect command is issued to the browser specifically to render this
	 * request.
	 */
	public static final IRequestCycleSettings.RenderStrategy
REDIRECT_TO_BUFFER = new IRequestCycleSettings.RenderStrategy(
			"REDIRECT_BUFFER");

It is a variation of the theme that commonly is named 'redirect after
post' in other frameworks, only we do it for everything including
links. And if fact, most frameworks don't even have a default facility
for this, so while it's not a feature that will immediately obvious to
people new to Wicket, it is actually a pretty cool 'selling point'.

There are three options with wicket:
* the default, redirect to buffer, which renders the whole response to
a buffer kept in the application (with a max of three) and immediately
redirect to a request that just streams out that buffer
* redirect to render, which separates the 'action' and 'render' phase
of the request. Not typically recommended, but needed for portlets
* one pass render, which doesn't do any redirect magic. But that means
that you'll have to provide a solution for the redirect after post
thing yourself (if you care, but you should imo).

Eelco

Re: svn commit: r516552 - /incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java

Posted by Jean-Baptiste Quenot <jb...@apache.org>.
* Johan Compagner:

> i was  over protective for  that point.   I just didn't  want to
> really throw away  stuff But if there really is  only one status
> code we could keep it in an int.

Yes, please  keep only an int.   BTW, thanks for the  fix.  I also
fixed it  before you, but the  wrong way, so I'm  reverting my own
commit now.   Except the extra unit  tests, I keep them,  they are
always good to detect that kind of things and fail early.

However I admit I don't really understand the REDIRECT_TO_BUFFER
thing.  Can you explain what is the purpose of this?
-- 
     Jean-Baptiste Quenot
aka  John Banana   Qwerty
http://caraldi.com/jbq/

Re: svn commit: r516552 - /incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java

Posted by Johan Compagner <jc...@gmail.com>.
i was over protective for that point.
I just didn't want to really throw away stuff
But if there really is only one status code we could keep it in an int.

johan


On 3/9/07, Jean-Baptiste Quenot <jb...@apache.org> wrote:
>
> * jcompagner@apache.org:
> > Author: jcompagner
> > Date: Fri Mar  9 13:16:20 2007
> > New Revision: 516552
> >
> > URL: http://svn.apache.org/viewvc?view=rev&rev=516552
> > Log:
> > also buffer setStatus so that it doesn't get send with the redirect but
> really only when te redirect is rendered
> >
> > Modified:
> >     incubator/wicket/branches/wicket-1.x
> /wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java
> >
> > Modified: incubator/wicket/branches/wicket-1.x
> /wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java
> > URL:
> http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java?view=diff&rev=516552&r1=516551&r2=516552
> >
> ==============================================================================
> > --- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java
> (original)
> > +++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java
> Fri Mar  9 13:16:20 2007
> > @@ -54,6 +54,9 @@
> >       /** cookies list */
> >       private List cookies;
> >
> > +     /** status list */
> > +     private List status;
> > +
> >       /** headers map */
> >       private Map headers;
> >
> > @@ -282,7 +285,11 @@
> >        */
> >       public void setStatus(int sc)
> >       {
> > -             realResponse.setStatus(sc);
> > +             if (status == null)
> > +             {
> > +                     status = new ArrayList(2);
> > +             }
> > +             status.add(new Integer(sc));
> >       }
> >
> >       /**
> > @@ -292,8 +299,7 @@
> >        */
> >       public void setStatus(int sc, String sm)
> >       {
> > -             isOpen();
> > -             realResponse.setStatus(sc, sm);
> > +             throw new UnsupportedOperationException("not supported in
> tbe bufferd http response, use setStatus");
> >       }
> >
> >       /**
> > @@ -506,6 +512,14 @@
> >        */
> >       public void writeTo(HttpServletResponse servletResponse) throws
> IOException
> >       {
> > +             if (status != null)
> > +             {
> > +                     Iterator it = status.iterator();
> > +                     while (it.hasNext())
> > +                     {
> > +                             servletResponse.setStatus(
> ((Integer)it.next()).intValue());
> > +                     }
> > +             }
> >               if (headers != null)
> >               {
> >                       Iterator it = headers.entrySet().iterator();
> >
> >
>
> Hi Johan,
>
> Is it really useful to put a List of status codes, whereas you
> call servletResponse.setStatus() for every status code?  I would
> only keep one status code in the class.  The last status that has
> been set wins.
> --
>      Jean-Baptiste Quenot
> aka  John Banana   Qwerty
> http://caraldi.com/jbq/
>

Re: svn commit: r516552 - /incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java

Posted by Jean-Baptiste Quenot <jb...@apache.org>.
* jcompagner@apache.org:
> Author: jcompagner
> Date: Fri Mar  9 13:16:20 2007
> New Revision: 516552
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=516552
> Log:
> also buffer setStatus so that it doesn't get send with the redirect but really only when te redirect is rendered
> 
> Modified:
>     incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java
> 
> Modified: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java
> URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java?view=diff&rev=516552&r1=516551&r2=516552
> ==============================================================================
> --- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java (original)
> +++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/BufferedHttpServletResponse.java Fri Mar  9 13:16:20 2007
> @@ -54,6 +54,9 @@
>  	/** cookies list */
>  	private List cookies;
>  
> +	/** status list */
> +	private List status;
> +
>  	/** headers map */
>  	private Map headers;
>  
> @@ -282,7 +285,11 @@
>  	 */
>  	public void setStatus(int sc)
>  	{
> -		realResponse.setStatus(sc);
> +		if (status == null)
> +		{
> +			status = new ArrayList(2);
> +		}
> +		status.add(new Integer(sc));
>  	}
>  
>  	/**
> @@ -292,8 +299,7 @@
>  	 */
>  	public void setStatus(int sc, String sm)
>  	{
> -		isOpen();
> -		realResponse.setStatus(sc, sm);
> +		throw new UnsupportedOperationException("not supported in tbe bufferd http response, use setStatus");
>  	}
>  
>  	/**
> @@ -506,6 +512,14 @@
>  	 */
>  	public void writeTo(HttpServletResponse servletResponse) throws IOException
>  	{
> +		if (status != null)
> +		{
> +			Iterator it = status.iterator();
> +			while (it.hasNext())
> +			{
> +				servletResponse.setStatus( ((Integer)it.next()).intValue());
> +			}
> +		}
>  		if (headers != null)
>  		{
>  			Iterator it = headers.entrySet().iterator();
> 
> 

Hi Johan,

Is it really useful to put a List of status codes, whereas you
call servletResponse.setStatus() for every status code?  I would
only keep one status code in the class.  The last status that has
been set wins.
-- 
     Jean-Baptiste Quenot
aka  John Banana   Qwerty
http://caraldi.com/jbq/