1 Reply Latest reply on Aug 12, 2011 5:05 AM by Christoph Hirte

    how to call ejb from another server/jvm

    everson . Newbie


       

      How can I do a remote call to ejb from another server/jvm ? I'm using jboss 5.1

       

      //I use the code below to call ejb in the same jvm

      Context ctx = new InitialContext();

      MyEJBRemote ejb = (MyEJBRemote) ctx.lookup("MyEJB/remote"); 

        • 1. Re: how to call ejb from another server/jvm
          Christoph Hirte Newbie

          Hello everson,

           

          assuming you try to call a ejb from a remote machine (a jvm other that the one JBoss uses), the following should work:

           

          [01] InitialContext ctx = null;

          [02] Properties props = new Properties();

          [03] props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");

          [04] props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");

          [05] props.put("java.naming.provider.url", "jnp://192.168.0.100:1099");

          [06]

          [07] try {

          [08]      ctx = new InitialContext(props);

          [09]      MyEJBRemote ejb = (MyEJBRemote) ctx.lookup("YourEARArchiveName/MyEJB/remote");

          [10] } catch (NamingException e) {

          [11]      e.printStackTrace();

          [12] }

           

          You have to adjust the IP-Address in Line 5 that needs to point to your JBoss Server.

          In Line 9 you can omit "YourEARArchiveName" in the lookup string of the ctx.lookup() method, if you did not deployed your ejb archive within a ear archive.

           

          Regards

          Christoph Hirte