8 Replies Latest reply on Jan 8, 2008 6:26 AM by pmuir

    Injecting Remote EJBs

    starf666

      Hello Seam community,

      I am just starting a new project and want to use the seam framework. The system architecture demands that parts of the application are on a different machine than the main web-system. How can I inject (with @EJB annotation) remote EJBs into Beans located on the main machine. I guess I have to give the address of the remote machine somewhere, maybe jndi.properties? Or am I heading in the completely wrong direction. I looked through a lot of EJB tutorials, docs and books but they only describe injection in simple java clients or plain local injection.

      Thanks in advance,
      Martin

        • 1. Re: Injecting Remote EJBs
          cavani

          I am using this:

          Properties env = new Properties();
          env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
          env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
          env.put(Context.PROVIDER_URL, "jnp://192.168.1.1:1099");
          
          Context ctx = new InitialContext(env);
          
          return (ManagementService) ctx.lookup("tlon/ManagementServiceBean/remote");
          


          where there is two ears on different AS instance (and machines). "tlon" is the name of second EAR. "ManagementService" interface is deployed in both. Both application are Seam basead.

          I think (but don't tryed) tou could use factory or unwrap annotation to encapsulate and use in annotation for injection.

          Thanks,



          • 2. Re: Injecting Remote EJBs
            cavani

            Something like this:

            @Name("managedRemoteServer")
            @Scope(ScopeType.STATELESS)
            public class ManagedRemoteServer
            {
            
             @Unwrap
             public ManagementService getRemoteServer()
             {
             try
             {
             Properties env = new Properties();
             env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
             env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
             env.put(Context.PROVIDER_URL, "jnp://192.168.1.1:1099");
            
             Context ctx = new InitialContext(env);
            
             return (ManagementService) ctx.lookup("tlon/ManagementServiceBean/remote");
             }
             catch (Exception e)
             {
             e.printStackTrace();
             }
            
             return null;
             }
            
            }
            


            And:

            
             @In
             private ManagementService remoteServer;
            
            


            Obs.: I didn't test this...

            • 3. Re: Injecting Remote EJBs
              cavani

              [sorry... I will stop....]

              I think that this is your answer:


              In addition, EJB 3.0 dependency injection only works in the local JNDI. Hence you cannot inject objects from remote servers.


              from:

              http://trailblazer.demo.jboss.com/EJB3Trail/serviceobjects/injection/index.html

              Thanks,

              • 4. Re: Injecting Remote EJBs
                andyd

                You may be able to acheive what you want to using the web services support, but it isn't something I have experience using.

                • 5. Re: Injecting Remote EJBs
                  starf666

                  Thanks for the answers so far.

                  [sorry... I will stop....]
                  
                  I think that this is your answer:
                  
                  Quote:
                  
                  In addition, EJB 3.0 dependency injection only works in the local JNDI. Hence you cannot inject objects from remote servers.
                  
                  
                  from:
                  
                  http://trailblazer.demo.jboss.com/EJB3Trail/serviceobjects/injection/index.html


                  I guess that's the answer albeit I hoped it wouldn't. Would clustering get me anywhere? I don't know much about it. I am not sure I could use different resources on different cluster nodes. A part of the whole application must run on a Windows server while the web part should be able to run on linux. Else I will have to do the lookup manually, what would mess up my code a bit.

                  P.S.: Is injection of remote EJBs not possible in JBoss (4.2) or is it not possible in EJB3 in general? Wouldn't it be a cool feature?


                  • 6. Re: Injecting Remote EJBs
                    pmuir

                    Ask about remote EJB injection on the EJB3 forum ;)

                    Cavani's second answer is the right way to expose a remote ejb to Seam.

                    • 7. Re: Injecting Remote EJBs
                      starf666

                      So this has nothing to do with seam? I didn't expect this to be so unlikely in the development of enterprise (web) systems.

                      • 8. Re: Injecting Remote EJBs
                        pmuir

                        Injection of EJB3s using @EJB is not Seam, no. I suspect you will get a better informed response on the EJB3 forum.