Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-2013

Session doesn't get invalidated when using RestartResponseException.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.4-RC1
    • 1.4-RC2
    • wicket
    • None

    Description

      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:

      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();
          }
      }
      
      TinyTests$MyPage.html
      <html>
      </html>
      

      Attachments

        Activity

          People

            jdonnerstag Juegen Donnerstag
            lhunath Maarten Billemont
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: