You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-dev@portals.apache.org by Patrick Huber <st...@gmail.com> on 2005/12/06 18:47:11 UTC

Spring-Portlet: sending a redirect

Hello John

I hope you don't mind if I send you an e-mail directly. I've found
this address on a mailing list.

I am using spring-portlet and it works quite nice. But now I've come
across a problem: I have a small test Portlet which manages a list of
bookmarks. I intended to count the number of times someone clicks a
link and display the list with a descending click count. So to do
this, I added another controller and in the
handleActionRequestInternal method, I increase the click count and do
a response.sendRedirect.

When I call sendRedirect, Pluto complains like this:
java.lang.IllegalStateException: Can't invoke sendRedirect() after
certain methods have been called
	at org.apache.pluto.core.impl.ActionResponseImpl.sendRedirect(ActionResponseImpl.java:142)
	at net.swisstech.portlet.bookmark.web.controller.BookmarkVisitController.handleActionRequestInternal(BookmarkVisitController.java:38)
	at org.springframework.web.portlet.mvc.AbstractController.handleActionRequest(AbstractController.java:221)
	at org.springframework.web.portlet.mvc.SimpleControllerHandlerAdapter.handleAction(SimpleControllerHandlerAdapter.java:48)
	at org.springframework.web.portlet.DispatcherPortlet.doActionDispatch(DispatcherPortlet.java:779)
	at org.springframework.web.portlet.DispatcherPortlet.doActionService(DispatcherPortlet.java:702)
	at org.springframework.web.portlet.FrameworkPortlet.processRequest(FrameworkPortlet.java:431)
	at org.springframework.web.portlet.FrameworkPortlet.processAction(FrameworkPortlet.java:408)
	at org.apache.pluto.core.PortletServlet.dispatch(PortletServlet.java:171)
	at org.apache.pluto.core.PortletServlet.doGet(PortletServlet.java:113)

So I looked into plutos ActionRespnseImpl. It keeps a flag which is
flipped on certain calls like for example setRenderParameter.
ParameterMappingInterceptor does call that method in preHandle on line
73. So trying to send a redirect will then throw the above exception.

Is it possible to change the spring portlet code so redirecting can
work? Or is this a bug in plutos ActionResponseImpl?

Could you please comment on this issue?

Thank you
Patrick

--
"I love deadlines. I like the whooshing sound they make as they fly
by." -- Douglas Adams

Re: Spring-Portlet: sending a redirect

Posted by Patrick Huber <st...@gmail.com>.
Hi Nick

John and I continued discussing this off-list. The Problem was the
ParameterMappingInterceptor calling setRenderParameter. We're
currently trying to find a solution where the interceptor won't call
setRenderParameter until the controller has finished handling the
action.

Patrick

2005/12/10, Nick Lothian <ni...@mackmo.com>:
> David H. DeWolf wrote:
>
> >Patrick,
> >I think you need to ask this on the spring lists, not here.  I'm not
> >all that familiar with spring-portlet.  Not sure if anyone else is.
> >
> >
> >
> I wrote a fair bit of the original version, but that was over a year ago
> and it looks to have moved on a lot since then.
>
> >I think your conclusion is right though.
> >
> >
> >
>
> I agree
>
> Nick
>


--
"I love deadlines. I like the whooshing sound they make as they fly
by." -- Douglas Adams

Re: Spring-Portlet: sending a redirect

Posted by Nick Lothian <ni...@mackmo.com>.
David H. DeWolf wrote:

>Patrick,
>I think you need to ask this on the spring lists, not here.  I'm not
>all that familiar with spring-portlet.  Not sure if anyone else is.
>
>  
>
I wrote a fair bit of the original version, but that was over a year ago 
and it looks to have moved on a lot since then.

>I think your conclusion is right though.
>
>  
>

I agree

Nick

Re: Spring-Portlet: sending a redirect

Posted by "David H. DeWolf" <dd...@apache.org>.
Patrick,
I think you need to ask this on the spring lists, not here.  I'm not
all that familiar with spring-portlet.  Not sure if anyone else is.

I think your conclusion is right though.

David

On 12/8/05, Patrick Huber <st...@gmail.com> wrote:
> Hi again
>
> I've been investigating a little bit more in the mean time and it's a
> "bug" in spring portlet. The Portlet Spec, Chapter PLT.12.2.1 (page
> 50), defines the exact behaviour of sendRedirect (compare with the
> details in my first mail).
>
> Is it possible to work around the problem?
>
> If there is a place to post an official issue, I'll happily open an
> issue there. It's just, the springframework jira doesn't appear to be
> the right place since spring-portlet is not listed under the springweb
> module.
>
> regards
> Patrick
>
>
> 2005/12/6, Patrick Huber <st...@gmail.com>:
> > Hello John
> >
> > I hope you don't mind if I send you an e-mail directly. I've found
> > this address on a mailing list.
> >
> > I am using spring-portlet and it works quite nice. But now I've come
> > across a problem: I have a small test Portlet which manages a list of
> > bookmarks. I intended to count the number of times someone clicks a
> > link and display the list with a descending click count. So to do
> > this, I added another controller and in the
> > handleActionRequestInternal method, I increase the click count and do
> > a response.sendRedirect.
> >
> > When I call sendRedirect, Pluto complains like this:
> > java.lang.IllegalStateException: Can't invoke sendRedirect() after
> > certain methods have been called
> >         at org.apache.pluto.core.impl.ActionResponseImpl.sendRedirect(ActionResponseImpl.java:142)
> >         at net.swisstech.portlet.bookmark.web.controller.BookmarkVisitController.handleActionRequestInternal(BookmarkVisitController.java:38)
> >         at org.springframework.web.portlet.mvc.AbstractController.handleActionRequest(AbstractController.java:221)
> >         at org.springframework.web.portlet.mvc.SimpleControllerHandlerAdapter.handleAction(SimpleControllerHandlerAdapter.java:48)
> >         at org.springframework.web.portlet.DispatcherPortlet.doActionDispatch(DispatcherPortlet.java:779)
> >         at org.springframework.web.portlet.DispatcherPortlet.doActionService(DispatcherPortlet.java:702)
> >         at org.springframework.web.portlet.FrameworkPortlet.processRequest(FrameworkPortlet.java:431)
> >         at org.springframework.web.portlet.FrameworkPortlet.processAction(FrameworkPortlet.java:408)
> >         at org.apache.pluto.core.PortletServlet.dispatch(PortletServlet.java:171)
> >         at org.apache.pluto.core.PortletServlet.doGet(PortletServlet.java:113)
> >
> > So I looked into plutos ActionRespnseImpl. It keeps a flag which is
> > flipped on certain calls like for example setRenderParameter.
> > ParameterMappingInterceptor does call that method in preHandle on line
> > 73. So trying to send a redirect will then throw the above exception.
> >
> > Is it possible to change the spring portlet code so redirecting can
> > work? Or is this a bug in plutos ActionResponseImpl?
> >
> > Could you please comment on this issue?
> >
> > Thank you
> > Patrick
> >
> > --
> > "I love deadlines. I like the whooshing sound they make as they fly
> > by." -- Douglas Adams
> >
>
>
> --
> "I love deadlines. I like the whooshing sound they make as they fly
> by." -- Douglas Adams
>

Re: Spring-Portlet: sending a redirect

Posted by John Lewis <jl...@arcanumintl.com>.
Patrick,

Glad to hear that solved the problem.

I like your idea for the ParameterMappingInterceptor.  Unfortunately, 
the JSR-168 spec does not give us any way to see what render parameters 
have already been set -- if any.  So during the afterCompletion phase of 
the Interceptor, there is no way to know if the parameter used for 
mapping has already been set or not.  Let me know if you have any other 
ideas for how to accomplish this.

Thanks!

John


Patrick Huber wrote:

>Hi John
>
>Thank you for your answer, this helped a lot.
>
>When I started using Spring Portlet, I just copied most parts of the
>xml and didn't think about that interceptor. It was clear to me that
>it was the equivalent to the param resolver used for multiaction
>controllers in spring mvc and so I ignored it...
>
>Now I just removed the interceptor and the redirect works perfectly.
>
>I was also thinking about the interceptor. In certain scenarios it
>will definitely be very useful, but it shouldn't prevent redirects.
>So to sum this up: setting render parameters before executing
>handleAction prevents redirects. Until handleAction has completed,
>these parameters aren't used anyways, but setting them in
>afterCompletion may overwrite custom values set by the controller.
>Here's an idea:
>- in preHandle, create a copy of the request attributes
>- then let the controller handle the action
>- then in afterCompletion, merge the attributes copy into the original
>request, not overwriting parameters that have been set/changed by the
>controller.
>
>I don't know all the spring portlet internal but from the quick look
>I've had so far, I think this could work.
>
>Thanks again.
>Patrick
>
>
>2005/12/8, John Lewis <jl...@arcanumintl.com>:
>  
>
>> Patrick,
>>
>> Sorry for the slow response.  The sendRedirect issue is a serious pain and
>>does require some careful handling so that it can work.
>>
>> You are correct that the portlet spec makes it illegal to call sendRedirect
>>after certain other methods, like setRenderParameter, have been called.
>>
>> However, it is possible to use sendRedirect with Spring Portlet MVC.  In
>>fact the sample code includes an example portlet that will do a redirect to
>>an aribitrary URL.  Take a look at it for more details.
>>
>> So, this means that, either in the Spring Portlet code you are using or in
>>your own code, something that breaks sendRedirect is being called before you
>>can issue the redirect.  Most likely this means either the Controller or an
>>Interceptor is doing this.
>>
>> First, what specific Controller class does your controller decend from?  If
>>it is an AbstractController, then the issue must be elsewhere since
>>AbstractController itself never makes any calls to setRenderParameter (or
>>the other methods that break sendRedirect).  If your controller descends
>>from AbstractFormController, SimpleFormController, or
>>AbstractWizardFormController, then you must set the 'redirectAction'
>>property to true on this controller so that setRenderParameter will not be
>>called by the AbstractFormController code.
>>
>> Second, are you using the ParameterMappingInterceptor with this portlet?
>>If so, this will break redirect since the whole point of this Interceptor is
>>to automatically propagate the parameter you are using for your mapping from
>>the action phase to the render phase.  If so, remove this Interceptor and
>>propagate the parameter manually in your Controllers when you do need it.
>>Or create a different version of the Interceptor that propagates it during
>>the afterCompletion method instead of the preHandle method -- although this
>>will prevent you from changing the parameter in your Controller, if desired.
>>
>> I hope that helps you find the issue.  Let me know how it goes.
>>
>> John
>>
>>
>>
>>
>> Patrick Huber wrote:
>> Hi again
>>
>>I've been investigating a little bit more in the mean time and it's a
>>"bug" in spring portlet. The Portlet Spec, Chapter PLT.12.2.1 (page
>>50), defines the exact behaviour of sendRedirect (compare with the
>>details in my first mail).
>>
>>Is it possible to work around the problem?
>>
>>If there is a place to post an official issue, I'll happily open an
>>issue there. It's just, the springframework jira doesn't appear to be
>>the right place since spring-portlet is not listed under the springweb
>>module.
>>
>>regards
>>Patrick
>>
>>
>>2005/12/6, Patrick Huber <st...@gmail.com>:
>>
>>
>> Hello John
>>
>>I hope you don't mind if I send you an e-mail directly. I've found
>>this address on a mailing list.
>>
>>I am using spring-portlet and it works quite nice. But now I've come
>>across a problem: I have a small test Portlet which manages a list of
>>bookmarks. I intended to count the number of times someone clicks a
>>link and display the list with a descending click count. So to do
>>this, I added another controller and in the
>>handleActionRequestInternal method, I increase the click count and do
>>a response.sendRedirect.
>>
>>When I call sendRedirect, Pluto complains like this:
>>java.lang.IllegalStateException: Can't invoke sendRedirect() after
>>certain methods have been called
>> at
>>org.apache.pluto.core.impl.ActionResponseImpl.sendRedirect(ActionResponseImpl.java:142)
>> at
>>net.swisstech.portlet.bookmark.web.controller.BookmarkVisitController.handleActionRequestInternal(BookmarkVisitController.java:38)
>> at
>>org.springframework.web.portlet.mvc.AbstractController.handleActionRequest(AbstractController.java:221)
>> at
>>org.springframework.web.portlet.mvc.SimpleControllerHandlerAdapter.handleAction(SimpleControllerHandlerAdapter.java:48)
>> at
>>org.springframework.web.portlet.DispatcherPortlet.doActionDispatch(DispatcherPortlet.java:779)
>> at
>>org.springframework.web.portlet.DispatcherPortlet.doActionService(DispatcherPortlet.java:702)
>> at
>>org.springframework.web.portlet.FrameworkPortlet.processRequest(FrameworkPortlet.java:431)
>> at
>>org.springframework.web.portlet.FrameworkPortlet.processAction(FrameworkPortlet.java:408)
>> at
>>org.apache.pluto.core.PortletServlet.dispatch(PortletServlet.java:171)
>> at
>>org.apache.pluto.core.PortletServlet.doGet(PortletServlet.java:113)
>>
>>So I looked into plutos ActionRespnseImpl. It keeps a flag which is
>>flipped on certain calls like for example setRenderParameter.
>>ParameterMappingInterceptor does call that method in preHandle on line
>>73. So trying to send a redirect will then throw the above exception.
>>
>>Is it possible to change the spring portlet code so redirecting can
>>work? Or is this a bug in plutos ActionResponseImpl?
>>
>>Could you please comment on this issue?
>>
>>Thank you
>>Patrick
>>
>>--
>>"I love deadlines. I like the whooshing sound they make as they fly
>>by." -- Douglas Adams
>>
>>
>>
>>--
>>"I love deadlines. I like the whooshing sound they make as they fly
>>by." -- Douglas Adams
>>
>>
>>    
>>
>
>
>--
>"I love deadlines. I like the whooshing sound they make as they fly
>by." -- Douglas Adams
>  
>

Re: Spring-Portlet: sending a redirect

Posted by John Lewis <jl...@arcanumintl.com>.
Patrick,

Sorry for the slow response.  The sendRedirect issue is a serious pain 
and does require some careful handling so that it can work.

You are correct that the portlet spec makes it illegal to call 
sendRedirect after certain other methods, like setRenderParameter, have 
been called.

However, it is possible to use sendRedirect with Spring Portlet MVC.  In 
fact the sample code includes an example portlet that will do a redirect 
to an aribitrary URL.  Take a look at it for more details.

So, this means that, either in the Spring Portlet code you are using or 
in your own code, something that breaks sendRedirect is being called 
before you can issue the redirect.  Most likely this means either the 
Controller or an Interceptor is doing this.

First, what specific Controller class does your controller decend from?  
If it is an AbstractController, then the issue must be elsewhere since 
AbstractController itself never makes any calls to setRenderParameter 
(or the other methods that break sendRedirect).  If your controller 
descends from AbstractFormController, SimpleFormController, or 
AbstractWizardFormController, then you must set the 'redirectAction' 
property to true on this controller so that setRenderParameter will not 
be called by the AbstractFormController code.

Second, are you using the ParameterMappingInterceptor with this 
portlet?  If so, this will break redirect since the whole point of this 
Interceptor is to automatically propagate the parameter you are using 
for your mapping from the action phase to the render phase.  If so, 
remove this Interceptor and propagate the parameter manually in your 
Controllers when you do need it.  Or create a different version of the 
Interceptor that propagates it during the afterCompletion method instead 
of the preHandle method -- although this will prevent you from changing 
the parameter in your Controller, if desired.

I hope that helps you find the issue.  Let me know how it goes.

John



Patrick Huber wrote:

>Hi again
>
>I've been investigating a little bit more in the mean time and it's a
>"bug" in spring portlet. The Portlet Spec, Chapter PLT.12.2.1 (page
>50), defines the exact behaviour of sendRedirect (compare with the
>details in my first mail).
>
>Is it possible to work around the problem?
>
>If there is a place to post an official issue, I'll happily open an
>issue there. It's just, the springframework jira doesn't appear to be
>the right place since spring-portlet is not listed under the springweb
>module.
>
>regards
>Patrick
>
>
>2005/12/6, Patrick Huber <st...@gmail.com>:
>  
>
>>Hello John
>>
>>I hope you don't mind if I send you an e-mail directly. I've found
>>this address on a mailing list.
>>
>>I am using spring-portlet and it works quite nice. But now I've come
>>across a problem: I have a small test Portlet which manages a list of
>>bookmarks. I intended to count the number of times someone clicks a
>>link and display the list with a descending click count. So to do
>>this, I added another controller and in the
>>handleActionRequestInternal method, I increase the click count and do
>>a response.sendRedirect.
>>
>>When I call sendRedirect, Pluto complains like this:
>>java.lang.IllegalStateException: Can't invoke sendRedirect() after
>>certain methods have been called
>>        at org.apache.pluto.core.impl.ActionResponseImpl.sendRedirect(ActionResponseImpl.java:142)
>>        at net.swisstech.portlet.bookmark.web.controller.BookmarkVisitController.handleActionRequestInternal(BookmarkVisitController.java:38)
>>        at org.springframework.web.portlet.mvc.AbstractController.handleActionRequest(AbstractController.java:221)
>>        at org.springframework.web.portlet.mvc.SimpleControllerHandlerAdapter.handleAction(SimpleControllerHandlerAdapter.java:48)
>>        at org.springframework.web.portlet.DispatcherPortlet.doActionDispatch(DispatcherPortlet.java:779)
>>        at org.springframework.web.portlet.DispatcherPortlet.doActionService(DispatcherPortlet.java:702)
>>        at org.springframework.web.portlet.FrameworkPortlet.processRequest(FrameworkPortlet.java:431)
>>        at org.springframework.web.portlet.FrameworkPortlet.processAction(FrameworkPortlet.java:408)
>>        at org.apache.pluto.core.PortletServlet.dispatch(PortletServlet.java:171)
>>        at org.apache.pluto.core.PortletServlet.doGet(PortletServlet.java:113)
>>
>>So I looked into plutos ActionRespnseImpl. It keeps a flag which is
>>flipped on certain calls like for example setRenderParameter.
>>ParameterMappingInterceptor does call that method in preHandle on line
>>73. So trying to send a redirect will then throw the above exception.
>>
>>Is it possible to change the spring portlet code so redirecting can
>>work? Or is this a bug in plutos ActionResponseImpl?
>>
>>Could you please comment on this issue?
>>
>>Thank you
>>Patrick
>>
>>--
>>"I love deadlines. I like the whooshing sound they make as they fly
>>by." -- Douglas Adams
>>
>>    
>>
>
>
>--
>"I love deadlines. I like the whooshing sound they make as they fly
>by." -- Douglas Adams
>  
>

Re: Spring-Portlet: sending a redirect

Posted by Patrick Huber <st...@gmail.com>.
Hi again

I've been investigating a little bit more in the mean time and it's a
"bug" in spring portlet. The Portlet Spec, Chapter PLT.12.2.1 (page
50), defines the exact behaviour of sendRedirect (compare with the
details in my first mail).

Is it possible to work around the problem?

If there is a place to post an official issue, I'll happily open an
issue there. It's just, the springframework jira doesn't appear to be
the right place since spring-portlet is not listed under the springweb
module.

regards
Patrick


2005/12/6, Patrick Huber <st...@gmail.com>:
> Hello John
>
> I hope you don't mind if I send you an e-mail directly. I've found
> this address on a mailing list.
>
> I am using spring-portlet and it works quite nice. But now I've come
> across a problem: I have a small test Portlet which manages a list of
> bookmarks. I intended to count the number of times someone clicks a
> link and display the list with a descending click count. So to do
> this, I added another controller and in the
> handleActionRequestInternal method, I increase the click count and do
> a response.sendRedirect.
>
> When I call sendRedirect, Pluto complains like this:
> java.lang.IllegalStateException: Can't invoke sendRedirect() after
> certain methods have been called
>         at org.apache.pluto.core.impl.ActionResponseImpl.sendRedirect(ActionResponseImpl.java:142)
>         at net.swisstech.portlet.bookmark.web.controller.BookmarkVisitController.handleActionRequestInternal(BookmarkVisitController.java:38)
>         at org.springframework.web.portlet.mvc.AbstractController.handleActionRequest(AbstractController.java:221)
>         at org.springframework.web.portlet.mvc.SimpleControllerHandlerAdapter.handleAction(SimpleControllerHandlerAdapter.java:48)
>         at org.springframework.web.portlet.DispatcherPortlet.doActionDispatch(DispatcherPortlet.java:779)
>         at org.springframework.web.portlet.DispatcherPortlet.doActionService(DispatcherPortlet.java:702)
>         at org.springframework.web.portlet.FrameworkPortlet.processRequest(FrameworkPortlet.java:431)
>         at org.springframework.web.portlet.FrameworkPortlet.processAction(FrameworkPortlet.java:408)
>         at org.apache.pluto.core.PortletServlet.dispatch(PortletServlet.java:171)
>         at org.apache.pluto.core.PortletServlet.doGet(PortletServlet.java:113)
>
> So I looked into plutos ActionRespnseImpl. It keeps a flag which is
> flipped on certain calls like for example setRenderParameter.
> ParameterMappingInterceptor does call that method in preHandle on line
> 73. So trying to send a redirect will then throw the above exception.
>
> Is it possible to change the spring portlet code so redirecting can
> work? Or is this a bug in plutos ActionResponseImpl?
>
> Could you please comment on this issue?
>
> Thank you
> Patrick
>
> --
> "I love deadlines. I like the whooshing sound they make as they fly
> by." -- Douglas Adams
>


--
"I love deadlines. I like the whooshing sound they make as they fly
by." -- Douglas Adams