4 Replies Latest reply on Jun 30, 2003 1:21 PM by rkbeach

    JNDI Problem - Confusing....

    rkbeach Newbie

      Hi All,

      I am confronted with a puzzling problem...

      Environment:

      Weblogic 7
      JBoss 3.0.4
      Solaris 2.8

      What I am trying to do:

      An MDB running in the Weblogic context (running on machine A) looks up a Session Bean deployed under JBoss (running on machine B). This reference (home reference) is stored in a HashMap for re-use,
      since JNDI lookups can be expensive. This Home Reference is used to create a remote reference.

      Now, the problem I am running into:

      The above mechanism works fine when I first start the WL Server,the JBoss server, and lookup the Session Bean (this is stored in the HashMap, for re-use) using JNDI (see below for code). So long as the JBoss
      App Server is up and running, everything works fine.

      When I bounce the JBoss App Server, and try to use the SessionBean Home reference (stored in the HashMap) to create a remote reference,
      I get a java.rmi.NoSuchObjectException -- which is understandable, since the JBoss App Server is bounced.

      After I catch the java.rmi.NoSuchObjectException, I am trying to lookup the Session Bean deployed under Jboss (using the same piece of code that I used initially to perform the lookup) from the MDB running in Weblogic context, and all I get is a 'null' object. NO EXCEPTIONS ARE THROWN EITHER. Until I bounce
      the Weblogic Server, I am not able to lookup the Session Bean deployed in JBoss App Server.

      What am I doing wrong? Can you please help?


      Code that I am using to perform the lookup:


      public InitialContext getJBContext() {

      Properties props = null;
      InitialContext initCtx = null;

      try {
      props = new Properties();
      props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");

      props.put("java.naming.provider.url", "jnp://:");

      initCtx = new InitialContext(props);

      } catch (Exception ex) {
      e.printStackTrace();
      }
      }

      When I use the above obtained InitialContext, and do a lookup like "Object obj = getJBContext().lookup("invoiceBean");" the returned Object is 'null'. As I mentioned above, this happens after I bounce the JBoss App Server, and wouldn't go away until I bounce the Weblogic App Server as well.

      Thanks much,
      Srini

        • 1. Re: JNDI Problem - Confusing....
          Jon Barnett Master

          This is the expected behaviour. Your reference to the session bean home is no longer valid - this is a reference to a physical instance. That instance was destroyed as soon as you destroyed the container in which it was manifested.

          You'll get the same issue if you redeployed the EJB as the old physical instance is destroyed and the new instance is created.

          • 2. Re: JNDI Problem - Confusing....
            rkbeach Newbie


            Hi jonlee,

            Thanks much for your reply...

            I understand that, when once the JBoss App Server was bounced, I will no longer have a valid reference to the Session Bean's Home....

            But, what I don't understand is, why can't I lookup the Session Bean again, by creating a new InitialContext Object (just as I did at the very beginning -- when both servers have just been started)....

            After I catch the NoSuchObjectException, I am creating a brand new InitialContext object, but
            all I get back in return when I lookup the SessionBean, using this freshly created InitialObject is
            'null'....why do you think that's happening?

            Thanks again,
            Srini

            • 3. Re: JNDI Problem - Confusing....
              Jon Barnett Master

              My bad. OK. When do you get the reference in the MDB lifecycle? Do you set the url pkgs as well?

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

              I'm just trying to figure out if you get to the second lookup at all.

              How about killing the JBoss server and trying to get a reference? In theory, you should get a problem connecting to the JNDI service. That would show that you're not going for a second lookup. And we could go from there.

              • 4. Re: JNDI Problem - Confusing....
                rkbeach Newbie


                Hi jonlee,

                After 4 days of seemingly endless frustration, I was able to resolve this problem...thought that I would share this info with you...and to let you know how stupid I was...

                While going thru the EJB Spec, I saw the following 3 lines as regards to an MDB...

                ************
                A message-driven bean instance has no state for a specific client. However, the instance variables of the
                message-driven bean instance can contain state across the handling of client messages. Examples of
                such state include an open database connection and an object reference to an EJB object.
                *************

                And in my MDB, I have declared the remote bean I am trying to lookup, as an instance variable. And also the Context object in my ServiceLocator (which I invoke from my MDB) is declared as an instance variable. So, what's happening is, when once the initialcontext lookup returns a 'null' object (since the remote JBoss app server is bounced), that state isn't getting changed when other MDB instances try to process messages. When I saw the above info in the EJB 2.0 spec, I changed my remote object reference and the context object reference to method variables, instead of instance variables...after I made those changes, how many ever times I bounced the JBoss App Server, I was able to consistently lookup the beans deployed there from the Weblogic Server (the first lookup fails though...since the container was destroyed...but, when I catch the 'NoSuchObjectException' and re-try, it works fine)

                Thanks much for your help and efforts,
                Srini