| Author |
JNDI name not found error!!
|
Puneet Vashisht
Ranch Hand
Joined: Jul 30, 2005
Posts: 44
|
|
Hii guyz, I've started preparing for SCBCD exam, n i'm facing problems at each step n that's makin the progress real slow. Somehow i managed to solve to the AdviceGuy problem. Now the next prob is when i'm making local interfaces for my bean class. Here's the component interface: package headfirst; import javax.ejb.*; public interface AdviceLocal extends EJBLocalObject{ public String getTheMessage(); } The home Interface: package headfirst; import javax.ejb.*; public interface AdviceHomeLocal extends EJBLocalHome{ public AdviceLocal create() throws CreateException; } The bean class package headfirst; import javax.ejb.*; public class AdviceBeanLocal implements SessionBean{ private String[] adviceStrings = {"One word in appropriate.","You might want to rethink that haircut.","Your boss will repect you if you tell him what you really think of him.","Visualize yourself with better clothes.","Ofcourse you dont have to go to work today","Do you really think you should be leaving the hose like that?","Read a book, once a year whether you need to or not"}; public void ejbActivate(){ System.out.println("Ejb Activate"); } public void ejbPassivate(){ System.out.println("Ejb Passivate"); } public void ejbRemove(){ System.out.println("Ejb Remove"); } public void setSessionContext(SessionContext ctx){ System.out.println("Session Context"); } public String getTheMessage(){ System.out.println("In Get Advice"); int random = (int)(Math.random() * adviceStrings.length); return adviceStrings[random]; } public void ejbCreate(){ System.out.println("In Ejb Create"); } } and finally the Client : import javax.naming.*; import headfirst.*; import javax.ejb.*; public class AdviceClientLocal{ public static void main(String args[]){ new AdviceClientLocal().go(); } public void go(){ Object ob = null; try{ Context ic = new InitialContext(); ob = ic.lookup("local"); } catch(NamingException nex){ nex.printStackTrace(); } AdviceHomeLocal home = (AdviceHomeLocal) ob; AdviceLocal advisor = null; try{ advisor = home.create(); } catch(CreateException ce){ ce.printStackTrace(); } System.out.println(advisor.getTheMessage()); } } now when i deploy and run this code i'm getting this error javax.naming.NameNotFoundException: local not found at com.sun.enterprise.naming.TransientContext.doLookup(TransientContext. java:174) at com.sun.enterprise.naming.TransientContext.lookup(TransientContext.ja va:146) at com.sun.enterprise.naming.SerialContextProviderImpl.lookup(SerialCont extProviderImpl.java:63) at org.omg.stub.com.sun.enterprise.naming._SerialContextProviderImpl_Tie ._invoke(Unknown Source) at com.sun.corba.ee.internal.corba.ServerDelegate.dispatch(ServerDelegat e.java:355) at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:255) at com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProces sor.java:84) at com.sun.corba.ee.internal.orbutil.ThreadPool$PooledThread.run(ThreadP ool.java:99) Exception in thread "main" java.lang.NullPointerException at AdviceClientLocal.go(AdviceClientLocal.java:25) at AdviceClientLocal.main(AdviceClientLocal.java:7) Please help somebody!!. i dont know y i'm gettin all these errors, n this is really frustatin me boz i've already worked a lot to get the AdviceGuy example running. And now when AdviceGuy didnt have any problems in looking up the JNDI name, how come this crop up with this application.. Plz,plz help me out somebody. Thankz, Puneet SCJP 1.4 (95%)
|
 |
Sylvain Bouchard
Ranch Hand
Joined: Dec 06, 2005
Posts: 41
|
|
I'm facing the same pbm. Here's the trace. I'm using JBoss 4.0. -------------------------------------------------------------------- 10:32:09,203 WARN [verifier] EJB spec violation: Bean : AdviceBeanLocal Section: 7.10.5 Warning: The remote interface must extend the javax.ejb.EJBObject interface. 10:32:09,203 WARN [verifier] EJB spec violation: Bean : AdviceBeanLocal Method : public abstract String getAdvice() throws EJBException Section: 7.10.5 Warning: The methods in the remote interface must include java.rmi.RemoteException in their throws clause. 10:32:09,203 WARN [verifier] EJB spec violation: Bean : AdviceBeanLocal Method : public abstract void remove() throws RemoveException, EJBException Section: 7.10.5 Warning: The methods in the remote interface must include java.rmi.RemoteException in their throws clause. 10:32:09,203 WARN [verifier] EJB spec violation: Bean : AdviceBeanLocal Method : public abstract boolean isIdentical(EJBLocalObject) throws EJBException Section: 7.10.5 Warning: The methods in the remote interface must include java.rmi.RemoteException in their throws clause. 10:32:09,203 WARN [verifier] EJB spec violation: Bean : AdviceBeanLocal Method : public abstract EJBLocalHome getEJBLocalHome() throws EJBException Section: 7.10.5 Warning: The methods in the remote interface must include java.rmi.RemoteException in their throws clause. 10:32:09,203 WARN [verifier] EJB spec violation: Bean : AdviceBeanLocal Method : public abstract Object getPrimaryKey() throws EJBException Section: 7.10.5 Warning: The methods in the remote interface must include java.rmi.RemoteException in their throws clause. 10:32:09,203 ERROR [MainDeployer] Could not create deployment: file:/D:/App/jboss-4.0.3SP1/server/default/tmp/deploy/tmp47314HeadFirstEAR.ear-content /headfirst-ejb.jar org.jboss.deployment.DeploymentException: Verification of Enterprise Beans failed, see above for error messages. at org.jboss.ejb.EJBDeployer.create(EJBDeployer.java:575) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) -------------------------------------------------------------------- Thanks Sylvain ------------------------------ SCJP 1.4 SCWCD 1.3
|
Sylvain Bouchard
SCJP - SCWCD - SCBCD - OCPJP(5) - OCPJP(6)
|
 |
Devender Thareja
Ranch Hand
Joined: Jul 14, 2005
Posts: 187
|
|
|
Make sure that while deploying you are using JNDI name "local".
|
Devender Thareja
SCEA, SCBCD, SCJP
|
 |
Devender Thareja
Ranch Hand
Joined: Jul 14, 2005
Posts: 187
|
|
Sylvain, It looks like you are trying to deploye your local interface as remote interface. Make sure while deployign you are using correct fields to enter your interface names. Hope it helps.
Originally posted by Sylvain Bouchard: I'm facing the same pbm. Here's the trace. I'm using JBoss 4.0. -------------------------------------------------------------------- 10:32:09,203 WARN [verifier] EJB spec violation: Bean : AdviceBeanLocal Section: 7.10.5 Warning: The remote interface must extend the javax.ejb.EJBObject interface. 10:32:09,203 WARN [verifier] EJB spec violation: Bean : AdviceBeanLocal Method : public abstract String getAdvice() throws EJBException Section: 7.10.5 Warning: The methods in the remote interface must include java.rmi.RemoteException in their throws clause. 10:32:09,203 WARN [verifier] EJB spec violation: Bean : AdviceBeanLocal Method : public abstract void remove() throws RemoveException, EJBException Section: 7.10.5 Warning: The methods in the remote interface must include java.rmi.RemoteException in their throws clause. 10:32:09,203 WARN [verifier] EJB spec violation: Bean : AdviceBeanLocal Method : public abstract boolean isIdentical( EJBLocalObject) throws EJBException Section: 7.10.5 Warning: The methods in the remote interface must include java.rmi.RemoteException in their throws clause. 10:32:09,203 WARN [verifier] EJB spec violation: Bean : AdviceBeanLocal Method : public abstract EJBLocalHome getEJBLocalHome() throws EJBException Section: 7.10.5 Warning: The methods in the remote interface must include java.rmi.RemoteException in their throws clause. 10:32:09,203 WARN [verifier] EJB spec violation: Bean : AdviceBeanLocal Method : public abstract Object getPrimaryKey() throws EJBException Section: 7.10.5 Warning: The methods in the remote interface must include java.rmi.RemoteException in their throws clause. 10:32:09,203 ERROR [MainDeployer] Could not create deployment: file:/D:/App/jboss-4.0.3SP1/server/default/tmp/deploy/tmp47314HeadFirstEAR.ear-content /headfirst-ejb.jar org.jboss.deployment.DeploymentException: Verification of Enterprise Beans failed, see above for error messages. at org.jboss.ejb.EJBDeployer.create(EJBDeployer.java:575) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) -------------------------------------------------------------------- Thanks Sylvain ------------------------------ SCJP 1.4 SCWCD 1.3
|
 |
Sylvain Bouchard
Ranch Hand
Joined: Dec 06, 2005
Posts: 41
|
|
Thanks a lot, Devender You're absoltly right. My mistake was in the ejb-jar.xml I was using this configuration: <session> <ejb-name>AdviceBean</ejb-name> <home>headfirst.AdviceHome</home> <remote>headfirst.Advice</remote> <ejb-class>headfirst.AdviceBean</ejb-class> <session-type>Stateful</session-type> <transaction-type>Bean</transaction-type> </session> Instead of: <session> <ejb-name>AdviceBean</ejb-name> <local-home>headfirst.AdviceHome</local-home> <local>headfirst.Advice</local> <ejb-class>headfirst.AdviceBean</ejb-class> <session-type>Stateful</session-type> <transaction-type>Bean</transaction-type> </session> You must do the same in the web.xml and in the jboss-web.xml. <ejb-local-ref> I'm reading HFEJB, and there's not mention of this subtle change in the bean's configuration xml file. Maybe it's explain later in the book. --------------------------------------------------------------------------- After all these change, everything deployed, but I get a "javax.naming.NameNotFoundException: AdviceBeanLocal not bound". Did I miss something? Thanks a lot Sylvain
|
 |
Puneet Vashisht
Ranch Hand
Joined: Jul 30, 2005
Posts: 44
|
|
Hi, I've already crosschecked that the JNDI name is "local", and i'm makin local interfaces for my bean class. Can anybody tell me or give an idea of wat could b the potential problem in this case.
|
 |
Devender Thareja
Ranch Hand
Joined: Jul 14, 2005
Posts: 187
|
|
|
I tried Puneet's code and I am getting the same error. Could it be a RI bug?
|
 |
Puneet Vashisht
Ranch Hand
Joined: Jul 30, 2005
Posts: 44
|
|
Thankz Devender for tryin this code, but that's exactly my question wat could b the potential error here. i think if v r preparing for a certification, v cant afford to leave everything that vague. so lets work together n find it out wat is the error here. Plzz help us!! Puneet SCJP 1.4
|
 |
Sylvain Bouchard
Ranch Hand
Joined: Dec 06, 2005
Posts: 41
|
|
Puneet, On which server you're trying to run your code? Sylvain
|
 |
Devender Thareja
Ranch Hand
Joined: Jul 14, 2005
Posts: 187
|
|
I tried it on SUN's j2EE RI. Used their deploytool to deploy and generate configuration files. Sylvain, It's the same problem you have reported in Jboss too. Can you try to use Puneet's code. We must be doing something wrong, if the same error happens in Jboss. [ December 08, 2005: Message edited by: Devender Thareja ]
|
 |
Sylvain Bouchard
Ranch Hand
Joined: Dec 06, 2005
Posts: 41
|
|
Hi all, Finally, I've tried your code and i got the same pbm as you. But, I wrote a servlet client, deployed in the same application. And everthing works well. After reading a lot, and asking question. I think it's the correct result. [B}Possible explanation[\B]: The local EJB use to run on the same JVM as the client. Servlet deploy on the same app, run under the same JVM as the EJB. The local client run under a different JVM. Maybe that explain that the context lookup didn't find the component. This is my personal point of view, maybe I'm wrong. Sylvain
|
 |
Puneet Vashisht
Ranch Hand
Joined: Jul 30, 2005
Posts: 44
|
|
hii Sylvain, I agree wid you on this, infact when i got the problem, this is the first thought that came to my mind. Maybe that the context lookup didn't find the component. But then how far are we right about this. Somehow we need to find wats the exact problem. May b wat we may be thinking is just right. In that also v need to know wat to use with a local client instead of lookup. Thankz, Puneet
|
 |
Devender Thareja
Ranch Hand
Joined: Jul 14, 2005
Posts: 187
|
|
|
It makes sense to me. I think Sylvain got it right. Thanks.
|
 |
Rohit Bhagwat
Ranch Hand
Joined: Dec 19, 2004
Posts: 205
|
|
Hi Puneet Well I have also tried it using RI and this time I ensured the following 1. Made sure that my lookup name is the same as the JNDI name I gave during deploytime. 2. Ensured that my client is running in the same JVM as the local bean. But still I am not able to get rid of NameNotFoundException while dealing with Local interface. Are you able to come across any solution ? I have also posted the same question on other forum. Some of them have replied to my questions. You can refer to the following thread for more details that I have tried. http://www.theserverside.com/tss?service=direct/0/PostDiscussionReply/postReply&sp=l39614&sp=F&sp=l204851 Can you please help me ? Waiting for your reply Thanks and Regards Rohit.
|
 |
 |
|
|
subject: JNDI name not found error!!
|
|
|