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

    bean to bean connection

    p. bod. Newbie

      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.provider.url", "jnp://" + serverID+ ":1099");
      Context ctx;
      ctx = new InitialContext(properties);
      sbServer1 = (SBServerRemote) ctx.lookup("SongRankerServer/SBServer/remote");
      } catch (NamingException e)
      throw new RuntimeException(e);
      return sbServer1;

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

      Thank you in advance for any help!