• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

EJB lookup not working

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Priya Sri
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which container are you using ? WebSphere?
 
Priya Sri
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Iam using WSAD 5.0
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. That is an IDE. What EJB container are you using? (e.g. WebSphere, JBoss, GlassFish etc. )
 
Priya Sri
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using EJB container as Websphere
 
Aurelian Tutuianu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic