5 Replies Latest reply on Aug 7, 2007 8:52 AM by pmuir

    Third-party EJBs as seam components

    patrickr

      Hi there,

      Consider an EAR file containing a seam application and a third-party ejb-jar. Now, can I just use components.xml to give these EJBs a name and seam scope and then use them as usual seam components?

      And what happens if I deploy the ejb-jar by itself? Would this work:

      @Name("myRemoteEJB")
      public class RemoteEJBManager
      {
       private RemoteInterface ejb;
      
       @Create
       public void create() throws NamingException {
       InitialContext ic = new InitialContext();
       RemoteInterface ejb = (RemoteInterface)
       ic.lookup(RemoteInterface.class.getName());
       }
      
       @Unwrap
       public RemoteInterface getEjb() {
       return ejb;
       }
      
      }


      Thank your very much!

        • 1. Re: Third-party EJBs as seam components
          pmuir

          As long as Seam can look up the bean in jndi then it should be fine. so use jndiName.

          • 2. Re: Third-party EJBs as seam components
            pmuir

            The manager pattern you mention should work as well.

            • 3. Re: Third-party EJBs as seam components
              patrickr

              Thanks for your answers, Pete! And sorry for responding so late. However, I can't get the jndi-name lookup working. Since I didn't find any information in the docs, could you please tell me what exactly jndi-name expects?

              I supposed that this would work.

              <core:init jndi-pattern="wct-example/#{ejbName}/local" debug="true"/>
              
              <component name="shoppingCart" jndi-name="wct-example/ShoppingCartBean/local" scope="session" auto-create="true" />


              But when I use this for injection, shoppingCart is always null.

              Also, while I see
              19:22:35,199 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:ear=wct-example.ear,jar=wct-commerce.jar,name=ShoppingCartBean,service=EJB3 with dependencies:
              19:22:35,199 INFO [JmxKernelAbstraction] jboss.j2ee:ear=wct-example.ear,jar=wct-commerce.jar,name=OrderManagerBean,service=EJB3
              19:22:35,349 INFO [EJBContainer] STARTED EJB: de.wct.commerce.service.ShoppingCartBean ejbName: ShoppingCartBean


              ...I don't see a seam component log message for shoppingCart.



              • 4. Re: Third-party EJBs as seam components
                patrickr

                Doing it programmatically works:

                @Name("shoppingCart")
                @Scope(ScopeType.SESSION)
                public class ShoppingCartManager
                {
                 private ShoppingCart shoppingCart;
                
                 @Create
                 public void create() throws NamingException
                 {
                 InitialContext ic = new InitialContext();
                 //shoppingCart = (ShoppingCart) ic.lookup(ShoppingCart.class.getName());
                 shoppingCart = (ShoppingCart) ic.lookup("wct-example/ShoppingCartBean/local");
                 }
                
                 @Unwrap
                 public ShoppingCart getShoppingCart() {
                 return shoppingCart;
                 }
                }


                But why not with the components.xml? Is this a bug?

                • 5. Re: Third-party EJBs as seam components
                  pmuir

                  You need to specify the class as well.