1 2 Previous Next 20 Replies Latest reply on Apr 8, 2009 11:11 AM by Pete Muir

    JSR-299 servlet injection

    Pete Muir Master

      Section 5.12.3 of the JSR-299 specification requires that JSR-299 DI occurs for Servlets. As there are no specified hooks in Servlet to perform a post construct lifecycle callback, I have exposed an API in Web Beans which allows the server to request a servlet is injected.

      This API is

      http://anonsvn.jboss.org/repos/webbeans/ri/trunk/webbeans-ri-spi/src/main/java/org/jboss/webbeans/manager/api/WebBeansManager.java

      and is documented in the Web Beans documentation

      http://docs.jboss.org/webbeans/reference/snapshot/en-US/html/ri-spi.html#d0e3691

      We now need to get JBoss AS to perform servlet injection, and I would like guidance on the best way to hook this in.

        • 2. Re: JSR-299 servlet injection
          Scott Stark Master

          jbossweb already calls out to the org.jboss.web.tomcat.service.TomcatInjectionContainer to process a servlet class, and this handles the current javaee5 annotations. That would need to be updated to recognize the jsr299 annotations, or just call out to a WebBeansManager if that is what should be done.

          • 3. Re: JSR-299 servlet injection
            Pete Muir Master

            I think the simplest way to do this is to delegate injection to the JSR-299 implementaton (Web Beans) rathen than replicate a load of binding discovery code in JBoss AS, and then calling out to Web Beans to find the value. However, we can do this work in JBoss AS if preferred.

            From looking at org.jboss.injection, I assume we need a WebBeansInjector extends Injector whose inject method knows how to connect to Web Beans and perform the injection. So far we've managed to keep Web Beans much more out of the core of JBoss than this and it would be better to keep it that way if possible.

            • 4. Re: JSR-299 servlet injection
              Scott Stark Master

              The TomcatInjectionContainer could simply have a WebBeansManager injected into it when in a jsr299 env, and its injectServlet(Servlet) is called from TomcatInjectionContainer.newInstance method if the instance is a Servlet. That's about 10 lines of code.

              • 5. Re: JSR-299 servlet injection
                Ales Justin Master

                Moving this to forum.

                "pete.muir@jboss.org" wrote:

                In my simple world view of JBoss AS I would like to be able to listen to a "servlet created" event which has the servlet as the payload (does MC have such a concept?)


                If the Servlet was instantiated by MC this would be trivial to support
                as you would simply glue a MC callback on it.

                But I doubt we instantiate Servlets via MC, or do we?

                • 6. Re: JSR-299 servlet injection
                  Pete Muir Master

                   

                  "scott.stark@jboss.org" wrote:
                  The TomcatInjectionContainer could simply have a WebBeansManager injected into it when in a jsr299 env, and its injectServlet(Servlet) is called from TomcatInjectionContainer.newInstance method if the instance is a Servlet. That's about 10 lines of code.


                  My concern is that this introduces a hard dependency on the webbeans-spi from the tomcat module of JBoss AS. Atm, the only hard dependencies on webbeans-spi (or any other webbeans stuff) is inside webbeans.deployer.

                  • 7. Re: JSR-299 servlet injection
                    Scott Stark Master

                    Shouldn't there be a standard integration spi so that a jsr299 provider can be integrated into a javaee container?

                    Short of that, someone has to depend on someone else's injection spi. There server modules are about integration and the jsr299 dependency already exists, so I don't see an issue with adding it to the jbossweb deployer layer (which the TomcatInjectionContainer is part of).

                    • 8. Re: JSR-299 servlet injection
                      Scott Stark Master

                       

                      "alesj" wrote:

                      If the Servlet was instantiated by MC this would be trivial to support
                      as you would simply glue a MC callback on it.

                      But I doubt we instantiate Servlets via MC, or do we?

                      We don't at the moment, and I'm not sure how easy we could do this at the moment. The jbossweb layer calls out to the server integration layer when it needs to instantiate a Servlet instance so that injection and be performed on the instance. I think this can be as late as on demand when there is a request for the Servlet, but I'm not sure of that.


                      • 9. Re: JSR-299 servlet injection
                        Pete Muir Master

                        I still think a context callback of some sort is best here. The ServletContext is propagated to the TomcatInjectionContainer, can we use the vdf connector to access the MC and fire some event?

                        • 10. Re: JSR-299 servlet injection
                          Ales Justin Master

                           

                          "pete.muir@jboss.org" wrote:
                          I still think a context callback of some sort is best here.

                          I had diff callback in mind.
                          This is something we do similar to OSGi's services tracking/callback.
                          See MainDeployer and add/removeDeployer use case in deployers.xml.

                          "pete.muir@jboss.org" wrote:

                          The ServletContext is propagated to the TomcatInjectionContainer, can we use the vdf connector to access the MC and fire some event?

                          I guess we could have some servlet listener
                          which would via vdf connector code get access to WB's Bootstrap
                          and invoke it's WBManager::injectServlet.

                          btw, this looks deprecated in ServletContext.
                           /**
                           * @deprecated
                           */
                           javax.servlet.Servlet getServlet(java.lang.String s) throws javax.servlet.ServletException;
                          


                          • 11. Re: JSR-299 servlet injection
                            Carlo de Wolf Master

                            Isn't there a way to unify the injection frameworks we currently have?
                            I don't like the InjectionContainer SPI right now, because it ended up with too much stuff in it. So the current EJB3 model is not sufficient.

                            The main issue I predict will be the explicit dependencies to be setup, while injecting via JNDI lookups (JavaEE requirement), while I would like to use MC injection features, although the same semantics do not apply (visibility of injectees and JavaEE scoping).

                            So if we're going for this we need something that works on top of MC & VDF (needed for scoping), which works for all JavaEE components.

                            • 12. Re: JSR-299 servlet injection
                              Pete Muir Master

                               

                              "wolfc" wrote:
                              I don't like the InjectionContainer SPI right now, because it ended up with too much stuff in it. So the current EJB3 model is not sufficient.


                              It also seems deeply bound to EJB3 to me - IMO all that should be needed is the ability to register injection providers which are called for each possible injection point on a bean, with metadata on the injection point passed to the injection provider.

                              • 13. Re: JSR-299 servlet injection
                                Ales Justin Master

                                 

                                "pete.muir@jboss.org" wrote:

                                It also seems deeply bound to EJB3 to me - IMO all that should be needed is the ability to register injection providers which are called for each possible injection point on a bean, with metadata on the injection point passed to the injection provider.

                                I'll see if I can re-factor this into integration project:
                                - http://anonsvn.jboss.org/repos/jbossas/projects/integration/trunk/

                                What exactly would you both need on Injector?
                                Or is there anything else that we need?


                                • 14. Re: JSR-299 servlet injection
                                  Ales Justin Master

                                  Actually, Emanuel mentioned an existing component factory project:
                                  - http://anonsvn.jboss.org/repos/jbossas/projects/component-factory/trunk

                                  Scott, what's the status of this?
                                  Should I rather work on this instead of integration?

                                  1 2 Previous Next