NameNotFoundException while using Local interfaces.

Discussions

EJB programming & troubleshooting: NameNotFoundException while using Local interfaces.

  1. Hello friends,sir, madam

    I am getting NameNotFoundException while doing lookup using local interface. I verfied that the JNDI name and lookup name are the same and also verified the META-INF is a proper directory. I am using Reference Implementation (RI) which is provided by SUN as an application server. I undeployed all my application and only deployed my application that uses local interface but still I am getting the same exception. Can anyone please help me how do I get rid of this exception ?

    Waiting for your valuable suggestions..

    Thanks and Regards
    Rohit.
  2. Hello,

    "In Application Server 8.2, EJBs are systematically mapped to the JNDI sub-context ejb/. If you attribute the JNDI name Account to an EJB, theApplication Server 8.2 automatically creates the reference ejb/Account in the global JNDI context. The clients of this EJB therefore have to look up ejb/Account to retrieve the corresponding home interface."

    Are u appending ejb/ before retriving the home interface?
  3. No I am not appending "ejb" to my lookup name. In RI I dont need to write the deployment descriptor.The only thing I did was in the deploytool of RI I made sure that the name I am specifying for JNDI name is the same I use for lookup.The next thing I ensured that my interfaces are extending EJBLocalHome and EJBLocalObject.

    ~Rohit.
  4. Its me again......
       Try the following link
         Expert Exchange
  5. Hello all,
    Just want to conform , in one of the forum I read that the client program should run within the same JVM as that of EJB in case you are implementing local clients.
    Uptill now I was doing the following steps
    1. Deploy EJB using local interface in RI
    2. Launch a new cmd prompt and run the client program which in my case was a standalone program with a main method

    So this will create a new instance of JVM and will run my program. That means this is a different instance of JVM as compared to one in which my J2EE RI server is running. So does this cause a problem for lookup as I am still getting NameNotFoundException while implementing local interface.

    Please correct me if I am wrong.
    Waiting for your replies.


    Thanks and Regards
    Rohit.
  6. I also did tried suffixing the word "ejb" to form a string "ejb/Local" for lookup. Still it is giving exception. Also I learnt from the sun site that in case you are using local interface then the client program should be in the same JVM as the local EJB. I also tried that but still not getting rid of exception.

    I wrote one more business method in my EJB that extends remote interface and in that business method I wrote the following business method in my EJB tht using remote interface

    public String getGreetingFromLocalBean() throws RemoteException
    {
            Object o = null;
    LocalComponent component = null;
    try
    {
    Context c = new InitialContext();
    o = c.lookup("ejb/LocalEJB");
    LocalHome home = (LocalHome)o;
    component = home.create();
    }catch(NamingException ne)
    {
    ne.printStackTrace();
    } catch (CreateException e)
    {
    e.printStackTrace();
    }

            String str = component.getGreetings();
    System.out.println("str = "+str);
    return str;
    }

    I am not able to get rid of this problem.Can anyone please help me out ?

    Thanks and Regards
    Rohit
  7. Try printing all the names that are bound to your application..try using this code...


    void printTree(Context c,Context subContext, String contextName, JspWriter out, String prefix) throws NamingException, IOException {
        System.out.println(contextName);
       
        NamingEnumeration ne = c.listBindings(contextName);
         
        while (ne.hasMore()) {
          Binding b = (Binding)ne.next();

          if (b.getObject() instanceof Context) {
            out.println(prefix + b.getName() );
            printTree(subContext,(Context)b.getObject(),b.getName(),out,"--
    " + prefix);
          } else {
            out.println(prefix + b.getName());
          }
        }
      }


    main() {
      InitialContext ic = new InitialContext();

      printTree(ic,ic,"",out, "");
    }


    This will print all the jndi names....
    See if ur resource is available in the list......

    Peace,
    Sanket Raut
  8. Hi Sanket

    Thanks for the program for printing the JNDI names. Since I am new to EJB,I had to struggle a lot as I was getting exception while running your program.
    Here's what I did. In all the following cases my J2EE server is running.

    1. Wrote the method given by you in my bean class. Declared it in component interface and invoked it from the remote client program using the EJBObject stub reference. I got exceptions.

    2. Wrote a standalone client with the main method. Created an InitialContext object and called your method which I wrote in the same client program.Still got exceptions.

    3. Wrote your method in the bean class and invoked it from other remote method present in the bean class.Called this remote method from the remote client. Didnt declared your method in the component interface. This time it worked. I got all the names from the JNDI.

    I dont know why it failed in the first two cases.
    Ok coming back to main problem, when I saw the names printed, I noticed that I am not able to see the JNDI names for any of my beans that implements Local interfaces ? I saw the JNDI names for the beans that implement the remote interface.Atleast from your program I came to know that JNDI name for the bean that implements the local interface is not getting registered. Thanks very much for your program.I dont know how to come out of this problem. I am using J2EE RI server.I dont know why the JNDI names for the bean implementing local interface is not getting registered using RI ?

    Can you please help me. I tried to explain what all I have did. Please let me know if you need any other details or if I have missed anything to specify.

    Waiting for your reply

    Thanks and Regards
    Rohit.
  9. Hello friends
     
    I forgot to mention the ejb-ref parameter while using local interface thats why my jndi name for local client was not getting registered using Sun' Reference Implementation server.
     
    I just made a note that
    a. I made entry for ejb-local-ref parameter using RI's deploytool.
    b. Ensured that my client and my EJB are working in the same JVM.
     
    By taking care of the above points, I am able to invoke methods on my ejb that is implementing local interface.
     
    Thanks and Regards
    Rohit.