Wicket
  1. Wicket
  2. WICKET-2887

Bootstraping wicket with GuiceWebApplicationFactory fails with exception

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.4.8, 1.4.9
    • Fix Version/s: None
    • Component/s: wicket-guice
    • Labels:
      None

      Description

      There seems to be some sort of chicken-egg problem:
      org.apache.wicket.WicketRuntimeException: There is no application attached to current thread main
      at org.apache.wicket.Application.get(Application.java:179) [wicket-1.4.9.jar:1.4.9]
      at org.apache.wicket.injection.web.InjectorHolder.setInjector(InjectorHolder.java:88) [wicket-ioc-1.4.9.jar:1.4.9]
      at org.apache.wicket.guice.GuiceComponentInjector.<init>(GuiceComponentInjector.java:102) [wicket-guice-1.4.9.jar:1.4.9]
      at org.apache.wicket.guice.GuiceWebApplicationFactory.createApplication(GuiceWebApplicationFactory.java:177) [wicket-guice-1.4.9.jar:1.4.9]
      at org.apache.wicket.protocol.http.WicketFilter.init(WicketFilter.java:701) [wicket-1.4.9.jar:1.4.9]

      After some digging i found that it is actually a regression made by this issue fix - WICKET-2761.
      If I rollback wicket-guice to 1.4.7, everything starts to work just fine.

      1. WICKET-2887-1.4.9.patch
        3 kB
        Zilvinas Kybartas

        Activity

        Hide
        Juergen Donnerstag added a comment -

        Could you please provide a quickstart and/or test case. Thanks a lot.

        Show
        Juergen Donnerstag added a comment - Could you please provide a quickstart and/or test case. Thanks a lot.
        Hide
        Zilvinas Kybartas added a comment -

        Attaching unit test patch. I've made it with git, so hope that it will be ok.

        Show
        Zilvinas Kybartas added a comment - Attaching unit test patch. I've made it with git, so hope that it will be ok.
        Hide
        Martin Grigorov added a comment - - edited

        I have a question about the design of org.apache.wicket.protocol.http.IWebApplicationFactory:
        Is it needed to use addComponentInstantiationListener(...) in MyApp#init() if I use an implementation of org.apache.wicket.protocol.http.IWebApplicationFactory ?

        org.apache.wicket.guice.GuiceWebApplicationFactory installs GuiceComponentInjector automatically. org.apache.wicket.spring.SpringWebApplicationFactory don't do that and the user still has to install the listener explicitly.
        I believe Guice approach is the better one.

        Show
        Martin Grigorov added a comment - - edited I have a question about the design of org.apache.wicket.protocol.http.IWebApplicationFactory: Is it needed to use addComponentInstantiationListener(...) in MyApp#init() if I use an implementation of org.apache.wicket.protocol.http.IWebApplicationFactory ? org.apache.wicket.guice.GuiceWebApplicationFactory installs GuiceComponentInjector automatically. org.apache.wicket.spring.SpringWebApplicationFactory don't do that and the user still has to install the listener explicitly. I believe Guice approach is the better one.
        Hide
        Michael Mosmann added a comment -

        Workaround:

        public class MyWebApplication extends WebApplication
        {
        public MyWebApplication()

        { // HACK Application.set(this); }

        ...
        }

        Show
        Michael Mosmann added a comment - Workaround: public class MyWebApplication extends WebApplication { public MyWebApplication() { // HACK Application.set(this); } ... }
        Hide
        Martin Grigorov added a comment -

        And the fix looks pretty much the same:

        Index: GuiceWebApplicationFactory.java
        ===================================================================
        — GuiceWebApplicationFactory.java (revision 955869)
        +++ GuiceWebApplicationFactory.java (working copy)
        @@ -174,6 +174,7 @@
        "To use GuiceWebApplicationFactory, you must specify either an 'injectorContextAttribute' or a 'module' init-param.");
        }
        WebApplication app = injector.getInstance(WebApplication.class);
        + Application.set(app);
        app.addComponentInstantiationListener(new GuiceComponentInjector(app, injector));
        return app;
        }

        No one responded to my earlier comment/question in this ticket...
        I think this is the right fix because otherwise the user will not have benefit of using org.apache.wicket.protocol.http.IWebApplicationFactory - (s)he could just register the ComponentInstantiationListener in MyApplication#init().

        Wicket-Spring implementation of IWebApplicationFactory is even more "broken" in this context because it doesn't register the listener for you. It just prepares the Spring's ApplicationContext and Wicket's WebApplication but then you (the user) have to add addComponentInstantiationListener(new SpringComponentInjector(this)); in MyApplication#init()

        Show
        Martin Grigorov added a comment - And the fix looks pretty much the same: Index: GuiceWebApplicationFactory.java =================================================================== — GuiceWebApplicationFactory.java (revision 955869) +++ GuiceWebApplicationFactory.java (working copy) @@ -174,6 +174,7 @@ "To use GuiceWebApplicationFactory, you must specify either an 'injectorContextAttribute' or a 'module' init-param."); } WebApplication app = injector.getInstance(WebApplication.class); + Application.set(app); app.addComponentInstantiationListener(new GuiceComponentInjector(app, injector)); return app; } No one responded to my earlier comment/question in this ticket... I think this is the right fix because otherwise the user will not have benefit of using org.apache.wicket.protocol.http.IWebApplicationFactory - (s)he could just register the ComponentInstantiationListener in MyApplication#init(). Wicket-Spring implementation of IWebApplicationFactory is even more "broken" in this context because it doesn't register the listener for you. It just prepares the Spring's ApplicationContext and Wicket's WebApplication but then you (the user) have to add addComponentInstantiationListener(new SpringComponentInjector(this)); in MyApplication#init()
        Hide
        Igor Vaynberg added a comment -

        well, i ran the test from the patch and it passed so i am assuming everything is good.

        springwebapplicationfactory is "worse" because it is deprecated. i dont much see the point of using the ioc container to create the application object. if you are going to go that far then you may as well use the container's filter-forwarding infrastructure and create the entire wicket filter inside the container.

        -igor

        Show
        Igor Vaynberg added a comment - well, i ran the test from the patch and it passed so i am assuming everything is good. springwebapplicationfactory is "worse" because it is deprecated. i dont much see the point of using the ioc container to create the application object. if you are going to go that far then you may as well use the container's filter-forwarding infrastructure and create the entire wicket filter inside the container. -igor

          People

          • Assignee:
            Igor Vaynberg
            Reporter:
            Zilvinas Kybartas
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development