You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by TH Lim <ss...@gmail.com> on 2012/02/02 12:27:49 UTC

Re: Unnecessary 302 redirects in Wicket 1.5

Is it possible to set the redirect feature localized to a page instead of
every page? There are 2 out 10 pages I don't want to redirect. Thanks

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unnecessary-302-redirects-in-Wicket-1-5-tp3921623p4351160.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Unnecessary 302 redirects in Wicket 1.5

Posted by sylvain <sy...@interview-efm.com>.
Hi, 
In order to avoid redirect, we add this code in our application class :


setPageRendererProvider(new IPageRendererProvider() {	
			@Override
			public PageRenderer get(final RenderPageRequestHandler context) {
				return new WebPageRenderer(context){
					@Override
					protected RedirectPolicy getRedirectPolicy() {
						RedirectPolicy result;
						if (!((WebRequest) RequestCycle.get().getRequest()).isAjax()) {
							result = RedirectPolicy.NEVER_REDIRECT;
						} else {
							result = super.getRedirectPolicy();
						}
						return result;
					}
				};					
			}
		})

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unnecessary-302-redirects-in-Wicket-1-5-tp3921623p4650219.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Unnecessary 302 redirects in Wicket 1.5

Posted by TH Lim <ss...@gmail.com>.
This worked. It didn't do a POST/REDIRECT/GET when I posted from Javascript
and/or HTML Form. This solution works great because, as you mentioned, I can
use  @SpringBean and other Wicket features along side with it. Thanks.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unnecessary-302-redirects-in-Wicket-1-5-tp3921623p4360263.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Unnecessary 302 redirects in Wicket 1.5

Posted by "Serban.Balamaci" <th...@gmail.com>.
Hi Lim,
What about using an AbstractResource instead for serving the xml.

You can do something like:
    @Override
    protected ResourceResponse newResourceResponse(Attributes attributes) {
        final ResourceResponse response = new ResourceResponse();
        
        PageParameters requestParams = attributes.getParameters();
        response.setLastModified(Time.now());
        response.disableCaching();
        response.setContentType("text/xml");
        response.setTextEncoding("UTF-8");

        response.setWriteCallback(new WriteCallback() {
            @Override
            public void writeData(final Attributes attributes) {
                attributes.getResponse().write("<xml..>");
            }
        });

        response.setContentDisposition(ContentDisposition.INLINE);
        return response.
     }

And you have all the benefits wicket like @SpringBean available, access to
wicket session, etc.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unnecessary-302-redirects-in-Wicket-1-5-tp3921623p4355660.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Unnecessary 302 redirects in Wicket 1.5

Posted by TH Lim <ss...@gmail.com>.
I could use a servlet. I thought I could easily setup a Wicket page to do
something similar. Since I have @SpringBean ready to load services and DAOs.
I was almost there. Just that I couldn't get the NEVER_REDIRECT directive
work on a per page basis instead of global. 


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unnecessary-302-redirects-in-Wicket-1-5-tp3921623p4355044.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Unnecessary 302 redirects in Wicket 1.5

Posted by Martin Grigorov <mg...@apache.org>.
For this you don't need Wicket Page at all. Just use a normal Servlet,
fire a POST request to its URL and return whatever response you need.

On Fri, Feb 3, 2012 at 5:19 PM, TH Lim <ss...@gmail.com> wrote:
> What I want is a very simple end point to service a POST request originated
> from my JS using AJAX. What I was expecting was to do a POST and returned an
> acknowledgement as response. What happened was, after the  POST request, the
> browser received a HTTP 302 to redirect the browser to GET the final
> response. I can see these states using the browser debugging tool. How do I
> set this page to do what I was expecting?  thanks
>
>
> P-R-G,  http://en.wikipedia.org/wiki/Post/Redirect/Get Post/Redirect/Get
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unnecessary-302-redirects-in-Wicket-1-5-tp3921623p4354872.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Unnecessary 302 redirects in Wicket 1.5

Posted by TH Lim <ss...@gmail.com>.
What I want is a very simple end point to service a POST request originated
from my JS using AJAX. What I was expecting was to do a POST and returned an
acknowledgement as response. What happened was, after the  POST request, the
browser received a HTTP 302 to redirect the browser to GET the final
response. I can see these states using the browser debugging tool. How do I
set this page to do what I was expecting?  thanks


P-R-G,  http://en.wikipedia.org/wiki/Post/Redirect/Get Post/Redirect/Get 

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unnecessary-302-redirects-in-Wicket-1-5-tp3921623p4354872.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Unnecessary 302 redirects in Wicket 1.5

Posted by Martin Grigorov <mg...@apache.org>.
Please start over with your problem. What do you want to achieve? What
did you try? What problems did you face ?
And I'm not sure what is PRG.

On Fri, Feb 3, 2012 at 4:47 PM, TH Lim <ss...@gmail.com> wrote:
> Thanks for your help so far. It would be great if you could pass me some
> hints to allow me to do some research on my own. Thanks
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unnecessary-302-redirects-in-Wicket-1-5-tp3921623p4354785.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Unnecessary 302 redirects in Wicket 1.5

Posted by TH Lim <ss...@gmail.com>.
Thanks for your help so far. It would be great if you could pass me some
hints to allow me to do some research on my own. Thanks

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unnecessary-302-redirects-in-Wicket-1-5-tp3921623p4354785.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Unnecessary 302 redirects in Wicket 1.5

Posted by TH Lim <ss...@gmail.com>.
I tried and observed the PRG behavior as before. Even if it had worked, for
every page I need to an additional "transfer" page. I don't think this is a
good solution.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unnecessary-302-redirects-in-Wicket-1-5-tp3921623p4354302.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Unnecessary 302 redirects in Wicket 1.5

Posted by Martin Grigorov <mg...@apache.org>.
On Fri, Feb 3, 2012 at 12:05 PM, TH Lim <ss...@gmail.com> wrote:
> The original constructor was
>
> public class AppLogin extends WebPage implements IMarkupCacheKeyProvider,
> IMarkupResourceStreamProvider
>  {
>    public AppLogin(PageParameters params) {
>        setStatelessHint(true);
>        startAsyncProcss(params);
> *  throw new RestartResponseException(new PageProvider(getClass(), params),
>            RenderPageRequestHandler.RedirectPolicy.NEVER_REDIRECT);

This is wrong as you already found.
You need to use this code to come to this page.
I.e. from the previous page instead of using
setResponsePage(AppLogin.class) use the exception.

> *    }
>
> The additional code, in bold, caused stackoverflow exception. This page
> would be invoked by JavaScript call.
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unnecessary-302-redirects-in-Wicket-1-5-tp3921623p4354166.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Unnecessary 302 redirects in Wicket 1.5

Posted by TH Lim <ss...@gmail.com>.
The original constructor was

public class AppLogin extends WebPage implements IMarkupCacheKeyProvider,
IMarkupResourceStreamProvider 
 { 
    public AppLogin(PageParameters params) { 
        setStatelessHint(true); 
        startAsyncProcss(params);  
*  throw new RestartResponseException(new PageProvider(getClass(), params),
            RenderPageRequestHandler.RedirectPolicy.NEVER_REDIRECT);
*    }

The additional code, in bold, caused stackoverflow exception. This page
would be invoked by JavaScript call.


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unnecessary-302-redirects-in-Wicket-1-5-tp3921623p4354166.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Unnecessary 302 redirects in Wicket 1.5

Posted by Martin Grigorov <mg...@apache.org>.
There is no code related to redirections below.

On Fri, Feb 3, 2012 at 11:06 AM, TH Lim <ss...@gmail.com> wrote:
> import org.apache.wicket.MarkupContainer;
> import org.apache.wicket.markup.IMarkupCacheKeyProvider;
> import org.apache.wicket.markup.IMarkupResourceStreamProvider;
> import org.apache.wicket.markup.html.WebPage;
> import org.apache.wicket.request.http.WebResponse;
> import org.apache.wicket.request.mapper.parameter.PageParameters;
> import org.apache.wicket.util.resource.IResourceStream;
> import org.apache.wicket.util.resource.StringResourceStream;
>
> public class AppLogin extends WebPage implements IMarkupCacheKeyProvider,
> IMarkupResourceStreamProvider
> {
>    public AppLogin(PageParameters params) {
>        setStatelessHint(true);
>        startAsyncProcss(params);
>    }
>
>    private void startAsyncProcss(PageParameters params)
>    {
>        // start asynchronous process with POSTed param
>    }
>
>    @Override
>    public String getCacheKey(MarkupContainer components, Class<?> aClass)
>    {
>        return null;
>    }
>
>    @Override
>    public IResourceStream getMarkupResourceStream(MarkupContainer
> components, Class<?> aClass)
>    {
>        return new StringResourceStream("<?xml version=\"1.0\"?><ok />");
>    }
>
>    @Override
>    protected void configureResponse(WebResponse response)
>    {
>        super.configureResponse(response);
>        response.setContentType("text/xml");
>    }
> }
>
> Thanks.
>
> http://apache-wicket.1842946.n4.nabble.com/file/n4354074/p-r-g.png
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unnecessary-302-redirects-in-Wicket-1-5-tp3921623p4354074.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Unnecessary 302 redirects in Wicket 1.5

Posted by TH Lim <ss...@gmail.com>.
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.markup.IMarkupCacheKeyProvider;
import org.apache.wicket.markup.IMarkupResourceStreamProvider;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.request.http.WebResponse;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.resource.StringResourceStream;

public class AppLogin extends WebPage implements IMarkupCacheKeyProvider,
IMarkupResourceStreamProvider
{
    public AppLogin(PageParameters params) {
        setStatelessHint(true);
        startAsyncProcss(params);
    }

    private void startAsyncProcss(PageParameters params)
    {
        // start asynchronous process with POSTed param
    }

    @Override
    public String getCacheKey(MarkupContainer components, Class<?> aClass)
    {
        return null;
    }

    @Override
    public IResourceStream getMarkupResourceStream(MarkupContainer
components, Class<?> aClass)
    {
        return new StringResourceStream("<?xml version=\"1.0\"?><ok />");
    }

    @Override
    protected void configureResponse(WebResponse response)
    {
        super.configureResponse(response);
        response.setContentType("text/xml");
    }
}

Thanks. 

http://apache-wicket.1842946.n4.nabble.com/file/n4354074/p-r-g.png 



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unnecessary-302-redirects-in-Wicket-1-5-tp3921623p4354074.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Unnecessary 302 redirects in Wicket 1.5

Posted by Martin Grigorov <mg...@apache.org>.
Can you share your code so we can take a look and help you ?

On Fri, Feb 3, 2012 at 9:04 AM, TH Lim <ss...@gmail.com> wrote:
> The compilation error was my fault. I tried and it didn't work. Probably I
> missed something. What I did was throw the RestartResponseException at the
> end of the said page and StackOverflowException was thrown, quite obvious to
> me what has happened. With my limited knowledge of Wicket internal working
> mechanism, I think RestartResponseException was not the right solution. What
> I understood was a page accepted a request, redirected the request to a page
> targeted by the exception. it basically worked like P-R-G.
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unnecessary-302-redirects-in-Wicket-1-5-tp3921623p4353854.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Unnecessary 302 redirects in Wicket 1.5

Posted by TH Lim <ss...@gmail.com>.
The compilation error was my fault. I tried and it didn't work. Probably I
missed something. What I did was throw the RestartResponseException at the
end of the said page and StackOverflowException was thrown, quite obvious to
me what has happened. With my limited knowledge of Wicket internal working
mechanism, I think RestartResponseException was not the right solution. What
I understood was a page accepted a request, redirected the request to a page
targeted by the exception. it basically worked like P-R-G.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unnecessary-302-redirects-in-Wicket-1-5-tp3921623p4353854.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Unnecessary 302 redirects in Wicket 1.5

Posted by TH Lim <ss...@gmail.com>.
I have compilation error with this statement. Any help here would be great.
And I suppose I put this line of code at the end of my web page constructor,
right?


Martin Grigorov-4 wrote
> 
> On Thu, Feb 2, 2012 at 1:27 PM, TH Lim &lt;sshark@&gt; wrote:
>> Is it possible to set the redirect feature localized to a page instead of
>> every page? There are 2 out 10 pages I don't want to redirect. Thanks
> 
> Experiment with new RestartResponseException(new
> PageProvider(YourPage.class, PageParameters),
> RedirectPolicy.NEVER_REDIRECT)
> 




--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unnecessary-302-redirects-in-Wicket-1-5-tp3921623p4353522.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Unnecessary 302 redirects in Wicket 1.5

Posted by Martin Grigorov <mg...@apache.org>.
On Thu, Feb 2, 2012 at 1:27 PM, TH Lim <ss...@gmail.com> wrote:
> Is it possible to set the redirect feature localized to a page instead of
> every page? There are 2 out 10 pages I don't want to redirect. Thanks

Experiment with new RestartResponseException(new
PageProvider(YourPage.class, PageParameters),
RedirectPolicy.NEVER_REDIRECT)

>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unnecessary-302-redirects-in-Wicket-1-5-tp3921623p4351160.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org