[ 
https://issues.apache.org/jira/browse/WICKET-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12662773#action_12662773
 ] 

Juergen Donnerstag commented on WICKET-2013:
--------------------------------------------

>From Session.invalidateNow()
/**
* Invalidates this session immediately. Calling this method will remove all 
Wicket components
* from this session, which means that you will no longer be able to work with 
them.
*/

Session.invalidateNow() does not unset the Session. The Session object can 
still be accessed via Session.get(), but the invalidated flag is set 
(Session.get().isSessionInvalidated()). If you want to avoid that you can ever 
access a invalited session you may modify MySession.get() follows

public static MySession get()
{
MySession session = (MySession)Session.get();
if ((session != null) && session.isSessionInvalidated())
{
session = (MySession)Session.findOrCreate();
}
return session;
} 

> Session doesn't get invalidated when using RestartResponseException.
> --------------------------------------------------------------------
>
>                 Key: WICKET-2013
>                 URL: https://issues.apache.org/jira/browse/WICKET-2013
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4-RC1
>            Reporter: Maarten Billemont
>
> When invalidating a session using Session.get().invalidateNow(), I normally 
> want to stop processing the current request.  When I do this in a constructor 
> of a page which might be extended by another page, I don't want any other 
> code to get exected.  Not my own, not that of any possible pages extending my 
> page.
> To do this, I throw an AbortException or a RestartResponseException.  
> However, it seems the session isn't actually properly cleaned this way.
> The following code demonstrates the problem:
> {code:title=TinyTests.java}
> package test.spike;
> import org.apache.wicket.Page;
> import org.apache.wicket.Request;
> import org.apache.wicket.Response;
> import org.apache.wicket.RestartResponseException;
> import org.apache.wicket.Session;
> import org.apache.wicket.markup.html.WebPage;
> import org.apache.wicket.protocol.http.WebApplication;
> import org.apache.wicket.protocol.http.WebSession;
> import org.apache.wicket.util.tester.WicketTester;
> import org.junit.Test;
> public class TinyTests {
>     public static class MyApp extends WebApplication {
>         /**
>          * {...@inheritdoc}
>          */
>         @Override
>         public Class<? extends Page> getHomePage() {
>             return MyPage.class;
>         }
>         /**
>          * {...@inheritdoc}
>          */
>         @Override
>         public Session newSession(Request request, Response response) {
>             return new MySession(request);
>         }
>     }
>     public static class MySession extends WebSession {
>         public MySession(Request request) {
>             super(request);
>         }
>         public static MySession get() {
>             return (MySession) Session.get();
>         }
>         private static final long serialVersionUID = 1L;
>         private String            name;
>         public void setName(String name) {
>             this.name = name;
>         }
>         public String getName() {
>             return name;
>         }
>     }
>     public static class MyPage extends WebPage {
>         public MyPage() {
>             if (MySession.get().getName() != null) {
>                 Session.get().invalidateNow();
>                 throw new RestartResponseException(getClass());
>             }
>         }
>     }
>     @Test
>     public void wicketTest() {
>         WicketTester wicket = new WicketTester(new MyApp());
>         wicket.processRequestCycle();
>         MySession.get().setName("foo");
>         wicket.processRequestCycle();
>     }
> }
> {code}
> {code:title=TinyTests$MyPage.html}
> <html>
> </html>
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to