You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Maarten Billemont (JIRA)" <ji...@apache.org> on 2009/01/09 12:06:59 UTC

[jira] Created: (WICKET-2013) Session doesn't get invalidated when using RestartResponseException.

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.


[jira] Resolved: (WICKET-2013) Session doesn't get invalidated when using RestartResponseException.

Posted by "Juergen Donnerstag (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Juergen Donnerstag resolved WICKET-2013.
----------------------------------------

       Resolution: Fixed
    Fix Version/s: 1.4-RC2
         Assignee: Juergen Donnerstag

fixed

> 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
>            Assignee: Juergen Donnerstag
>             Fix For: 1.4-RC2
>
>
> 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.


[jira] Commented: (WICKET-2013) Session doesn't get invalidated when using RestartResponseException.

Posted by "Maarten Billemont (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12662794#action_12662794 ] 

Maarten Billemont commented on WICKET-2013:
-------------------------------------------

I understand that within the same request you can still access the Session.  Though, I expect that after restarting the request or aborting it; using respectively a RestartResponseException or AbortException, the Session will get cleaned up and the next response will be generated based off a session-less request.

Especially so with the AbortException; which causes the next request to a wicket page to come from a new HTTP request, where the HTTP session cookie should not be present anymore.

Correct me if I'm mistaken.

If this functionality is not currently as is intended, then perhaps we should considder making this the intended behaviour for the reasons explained in the bug description.  Mainly, that when I want to invalidate my session, I want to stop the current request processing (because it relies on an active session, and I clearly have the intent to get rid of it, eg, for the purpose of a logout -- I don't want the user's login details to show on the logout page; or run the risk of somebody else implementing my code getting access to that data after having issued a logout).

> 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.


[jira] Commented: (WICKET-2013) Session doesn't get invalidated when using RestartResponseException.

Posted by "Juergen Donnerstag (JIRA)" <ji...@apache.org>.
    [ 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.


[jira] Commented: (WICKET-2013) Session doesn't get invalidated when using RestartResponseException.

Posted by "Maarten Billemont (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12662322#action_12662322 ] 

Maarten Billemont commented on WICKET-2013:
-------------------------------------------

Okay, my formatting wasn't applied, that kind of sucked.

In any case; the above code causes the following exception; because the MyPage constructor can't get rid of the active session which has a name set in it:

java.lang.IllegalStateException: Request processing executed 100 steps, which means it is probably in an infinite loop.
	at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1361)
	at org.apache.wicket.RequestCycle.request(RequestCycle.java:498)
	at org.apache.wicket.protocol.http.MockWebApplication.processRequestCycle(MockWebApplication.java:484)
	at org.apache.wicket.protocol.http.MockWebApplication.processRequestCycle(MockWebApplication.java:472)
	at test.spike.net.link.safeonline.TinyTests.wicketTest(TinyTests.java:111)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
	at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
	at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
	at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
	at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
	at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
	at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
	at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
	at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
	at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
	at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)



> 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.