File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes EJB lookup not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB lookup not working" Watch "EJB lookup not working" New topic
Author

EJB lookup not working

Priya Sri
Ranch Hand

Joined: Mar 30, 2004
Posts: 84
Hi all,

I created a web project and EJB project in WSAD 5.0. In web project , i created a plain java class which does a lookup to session bean present in EJB project.

public static void main(String[] args) {

InitialContext initContext;
Object ref=null;
Properties p = new Properties();

try {

p.put("java.naming.factory.initial","com.sun.jndi.cosnaming.CNCtxFactory");
p.put("java.naming.provider.url","iiop://localhost:2809");
initContext = new javax.naming.InitialContext(p);
ref = initContext.lookup("ejb/FinanceSession"); // Gives error here

} catch (NamingException e) {
e.printStackTrace();
System.out.println("Error is ***"+e.getMessage());
}


FinanceSessionHome finHome =(FinanceSessionHome)PortableRemoteObject.narrow(ref,FinanceSessionHome.class);
FinanceSession fin;
try {
fin = finHome.create();
System.out.println("*****I created bean********");
fin.doWhatever();
} catch (RemoteException e) {
} catch (CreateException e) {
}

When i run the above java class using Run as Java Application, it shows the below error. Can any one help me to solve this.

javax.naming.NameNotFoundException. Root exception is org.omg.CosNaming.NamingContextPackage.NotFound
at org.omg.CosNaming.NamingContextPackage.NotFoundHelper.read(NotFoundHelper.java:48)
at com.ibm.WsnOptimizedNaming._NamingContextStub.resolve(_NamingContextStub.java:1291)
at com.sun.jndi.cosnaming.CNCtx.callResolve(CNCtx.java:414)
at com.sun.jndi.cosnaming.CNCtx.lookup(CNCtx.java:463)
at com.sun.jndi.cosnaming.CNCtx.lookup(CNCtx.java:441)
at javax.naming.InitialContext.lookup(InitialContext.java:359)
at SampleClass.main(SampleClass.java:42)
Error is ***null
java.lang.NullPointerException
at SampleClass.main(SampleClass.java:52)

Aurelian Tutuianu
Ranch Hand

Joined: May 13, 2004
Posts: 86
If you use a Sun container and you have a local interface for the session bean, the Sun container don't create JNDI binding for local sessions. If that's the case you must add a ejb reference into web application to point to your session bean.
Something like <ejb-ref>... you manage it.


http://javasign.blogspot.com/
Priya Sri
Ranch Hand

Joined: Mar 30, 2004
Posts: 84
Hi

I tried giving EJB referece in my WEB project. Still it did not work.

If i remove the below line, it is giving this error. I dont want to use sun container. then how to do ?

//p.put("java.naming.factory.initial",
//"com.sun.jndi.cosnaming.CNCtxFactory");

java.lang.IncompatibleClassChangeError: com.ibm.CORBA.iiop.ORB method createObjectURL(Ljava/lang/String;)Lcom/ibm/CORBA/iiop/ObjectURL;
at com.ibm.ws.naming.util.WsnInitCtxFactory.parseIiopUrl(WsnInitCtxFactory.java:1668)
at com.ibm.ws.naming.util.WsnInitCtxFactory.parseBootstrapURL(WsnInitCtxFactory.java:1427)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:368)
at com.ibm.ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:102)
at com.ibm.ws.naming.util.WsnInitCtx.getContextIfNull(WsnInitCtx.java:408)
at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:131)
at javax.naming.InitialContext.lookup(InitialContext.java:359)
at SampleClass.main(SampleClass.java:42)
Exception in thread "P=980284:O=0:CT"
Aurelian Tutuianu
Ranch Hand

Joined: May 13, 2004
Posts: 86
Thought one question more. You said you have created an web project which contains the code you have shown us.
But do you have a main inside a web app? It seems more that you created a desktop client of ejb, in which case you have to use @Remote interface not @Local.
Priya Sri
Ranch Hand

Joined: Mar 30, 2004
Posts: 84
Hi

In my web project, written a java class which has main() and trying to lookup an EJB present in EJB project.

This EJB has remote interface only not local.

Am I going wrong anywhere ??

bye
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Which container are you using ? WebSphere?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Priya Sri
Ranch Hand

Joined: Mar 30, 2004
Posts: 84
Iam using WSAD 5.0
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

OK. That is an IDE. What EJB container are you using? (e.g. WebSphere, JBoss, GlassFish etc. )
Priya Sri
Ranch Hand

Joined: Mar 30, 2004
Posts: 84
Using EJB container as Websphere
Aurelian Tutuianu
Ranch Hand

Joined: May 13, 2004
Posts: 86
You use com.sun.jndi.cosnaming.CNCtxFactory as JNDI implementation. I am not sure but I think that every server has it's own implementation on JNDI. So you probably should look for your JNDI provider of your server. I am not sure about, but I know that ENC is not standardized (yet!).
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

In which case you will need to correctly set the provider URL and so on. Have a read through the WAS examples that come with the documentaiton. They are fairly comprehensive.
 
Don't get me started about those stupid light bulbs.
 
subject: EJB lookup not working
 
Similar Threads
PLEASE, I need help with this..............
Unhandled exception in lookup [Root exception is org.omg.CORBA.NO_PERMISSION
error while running Client in Eclipse helios
Dependency INjection through Annotations
Session facade