7 Replies Latest reply on Jun 18, 2008 1:59 PM by aloubyansky

    ClientContainer injection

    aloubyansky

      Looks very confusing to me. This is what I see:

      this is what happens in the ctor of ClientContainer: first it calls processMetaData() which populates the list of injectors and then inject() is called on each injector:

      ...
       processMetadata(null);
      
       for(Injector injector : injectors)
       {
       log.debug("injector: " + injector);
       injector.inject((Object) null);
       }
      ...


      How can anything be injected into null? (except static)

      processMetaData does the following:
      handlers.add(new ClientEJBHandler<RemoteEnvironment>());
       handlers.add(new DependsHandler<RemoteEnvironment>());
       handlers.add(new JndiInjectHandler<RemoteEnvironment>());
       handlers.add(new PersistenceUnitHandler<RemoteEnvironment>());
       handlers.add(new ClientResourceHandler<RemoteEnvironment>(this.mainClass));
       handlers.add(new WebServiceRefHandler<RemoteEnvironment>());
      
       for (InjectionHandler<RemoteEnvironment> handler : handlers)
       handler.loadXml(xml, this);
      


      In loadXml(), a handler adds itself to the ClientContainer's list of handlers (so, later it gets inject call, see above). But this is true only for the handlers that are in the jbossas/trunk, i.e. ClientEJBHandler and ClientResourceHandle. Other handlers (in the ejb3 project) add injectors to ClientContainer's encInjections which I don't see being used after that.
      Map<String, Map<AccessibleObject, Injector>> getEncInjections()


      Further, the following handlers in their loadXml() call ClientContainer.getEncInjectors() which is
      public Map<String, EncInjector> getEncInjectors()
       {
       throw new IllegalStateException("ENC setup happens on the server");
       }

      - JndiInjectHandler
      - PersistenceUnitHandler

      So, these are not going to work.

        • 1. Re: ClientContainer injection
          aloubyansky

          Correction for the following:

          alexey wrote:

          In loadXml(), a handler adds itself to the ClientContainer's list of handlers (so, later it gets inject call, see above).


          Of course, it doesn't add itself. Each handler creates the corresponding injector and adds it to the ClientContainer's list of injectors.

          • 2. Re: ClientContainer injection
            starksm64

            Injectors are not used on the client. Any handler using the EncInjectors needs to be replaced on the client with one that does not. I'm going to remove all of the injector usage in the client and add exceptions to catch where it might be called.

            The enc setup happens on the server and the client simply references that prebuilt context through its java: url handler.

            • 3. Re: ClientContainer injection
              starksm64

              Ok, I'm wrong in that the handlers still populate the injectors for the static field/method usage. There is no BeanContainer on the client side, so there never is an instance to inject into.

              The EncInjectors should not be used however.

              • 4. Re: ClientContainer injection
                aloubyansky

                Ok, thanks. So should the handlers add injectors they create to the container's List getInjectors() or Map<String, Map<AccessibleObject, Injector>> getEncInjections()?

                • 5. Re: ClientContainer injection
                  starksm64

                  Only the server side handlers should be using the encInjections Map as this is for Class level annotations that go into the container enc. They should not be used in the client side ClientContaner environment. I have removed the encInjections from ClientContainer and am testing this.

                  • 6. Re: ClientContainer injection
                    starksm64

                    There is a server side org.jboss.injection.InjectionUtil from ejb3 that uses the classInjectors. There is also a client side org.jboss.ejb3.client.Utils that is what should be used in place of InjectionUtil to avoid mixing server side behavior in the client container. I see that the InjectionUtil is still being used in places in the client handlers, so I'll have to clean this up as well.

                    • 7. Re: ClientContainer injection
                      aloubyansky

                      I've modified the WebServiceRefHandler to add injectors to the container. http://jira.jboss.com/jira/browse/EJBTHREE-1424 So, the JBCTS-797 now passes with the latest not yet released EJB3 and metadata versions.