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

Page.isPageStateless() returning true in regular run but false in WicketTester



    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 6.8.0, 6.12.0
    • Fix Version/s: 6.13.0
    • Component/s: None
    • Labels:


      Healthcheck/heartbeat pages must always be stateless to prevent significant amounts of session creation and storage.
      Also each anonymously accessed page in a public site should be stateless due to the same reason (otherwise the site could easily be DoSsed down).
      It would be nice to verify these requirements by tests.

      If I create an ought-to-be-stateless page with an AjaxLink which is hidden by a behavior:

      public class MyPage extends WebPage {
      public MyPage() {
      add(new AjaxLink<Void>("link") {
      public void onClick(AjaxRequestTarget target)

      { // }

      }.add(new Behavior() {
      public void onConfigure(Component c)

      { c.setVisible(false); }

      add(new Label("isPageStateless", new AbstractReadOnlyModel<Boolean>() {
      public Boolean getObject()

      { return MyPage.this.isPageStateless(); }


      then checking through a web server the page correctly prints "true", and no HttpSessions are created.

      However, when I try to verify statelessness through WicketTester, the following test passes:

      public void testName() throws Exception {
      WicketTester tester = new WicketTester(new WebApplication() {
      public Class<? extends Page> getHomePage()

      { return MyPage.class; }

      tester.assertLabel("isPageStateless", "false");

      It seems that somehow due to WicketTester, isPageStateless() is being invoked before any behaviors are run (and thus the AjaxLink is still visible), and since stateless-flag for the page is cached, it remains false.

      If it's by design that isPageStateless should always return the same result during each request, then I guess that the statelessness resolution process must not depend on anything happening after the page constructor? I assume it's not by design.


      A) Obvious fix would be to remove stateless-flag caching, since apparently it is causing problems, as also suggested by a hackish comment in Page.init(). In general, caching should always be used sparingly.

      B) Or maybe whoever is invoking isPageStateless() at an early stage should actually be using Page.peekPageStateless()? But this doesn't really seem like a real fix, more like a temporary hack.

      C) All caching could also be disabled during test runs, but this would not be a good thing since tests should reproduce the actual behavior as closely as possible.

      D) In case this is a known issue without a proper fix, how then could I verify page statelessness through WicketTester? Currently I'm clearing the stateless-cache by reflection, which feels kind of bad...


        1. WICKET-5424-tester.patch
          2 kB
          Sven Meier
        2. wicket-bug-test.zip
          5 kB
          Jyri-Matti Lähteenmäki

          Issue Links



              • Assignee:
                svenmeier Sven Meier
                jyrimatti Jyri-Matti Lähteenmäki
              • Votes:
                0 Vote for this issue
                3 Start watching this issue


                • Created: