3 Replies Latest reply on Jun 14, 2006 7:35 AM by abl

    bean to bean connection

    pbod

      We have an .ear file with a .jar inside and with ejbs in it, deployed on a jboss server.
      We are trying to connect with a stateless session bean to the same bean on another server.
      But we are unable to get a reference of the other bean(on the other server).
      Instead of that, the object that has been looked up is an instance of the session bean on the connecting server(and not from the other server).

      Note: remote-lookup works, if the client is a standalone application or a jsp.
      We also tried it with ?java:comp/env/ejb/jndi-name?, but it doesn?t work, the jboss server always throws an exception(name ?env? is not bind).

      Our questions:
      Would it work with a lookup like this: ?java:comp/env/ejb/....?, if we can bind the name?
      If it would work, how can we bind the name(which config files needed, how should they look like, where are they located)?

      Our Code:
      public SBServerRemote connect(String serverID){
      SBServerRemote sbServer1 = null;

      Properties properties = new Properties();
      properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
      properties.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
      properties.put("java.naming.provider.url", "jnp://" + serverID+ ":1099");
      Context ctx;
      try
      {
      ctx = new InitialContext(properties);
      sbServer1 = (SBServerRemote) ctx.lookup("SongRankerServer/SBServer/remote");
      } catch (NamingException e)
      {
      e.printStackTrace();
      throw new RuntimeException(e);
      }
      return sbServer1;
      }


      the calling method:
      public List getAllSongs(String serverID) {
      SBServerRemote sbServer1 = null;
      List songs = new ArrayList();
      if (!serverID.equals("127.0.0.1")) {
      //get reference of another bean(on another server)
      sbServer1 = connect(serverID);
      //get songlist from other server
      songs = sbServer1.getAllSongs("127.0.0.1");
      }
      else {
      //get the songlist from this server
      Ranker ranker1 = new Ranker();
      songs = ranker1.getAllSongs(readSongDirectory());
      }
      return songs;
      }


      Thank you in advance for any help!

        • 1. Re: bean to bean connection
          bdecoste

          Are the 2 JBoss instances in a cluster or two independent instances?

          Your method of looking up the remote bean via JNDI properties looks correct - that is how any remote client, ejb or not, would access the remote bean.

          Using "java:comp/env" to look up remote beans will not work, since that is the local jndi space.

          • 2. Re: bean to bean connection
            pbod

            The JBoss instances are two independent instances.
            Is there any other thing that could be wrong?

            • 3. Re: bean to bean connection
              abl

              Any news to that? We have the same problem.

              This has been a problem earlier, but was fixed in JB4.0.2 for Non-EJB3 Beans.

              If I remember it correct, this was different if calling from a client (worked) or from inside a bean (always called local instance of other bean)