Problem with binding Remote Object (JNDI/WebSphere)

I am having a problem trying to bind a remote object to the WebSphere 3.5 JNDI name service (com.ibm.ejs.ns.jndi.CNInitialContextFactory). When I use ctx.bind(name, object), I am getting a java.lang.ClassCastException.

Would be really grateful for any help as it is driving me mad!

Lyndsey

[315 byte] By [hairsinl] at [2007-9-26 2:54:32]
# 1
Hello Lyndsey,where your problem? Can you run the application in the workbench? When yes, then check, if the application run under IBM JDK.Best regards Roland
rkunzke at 2007-6-29 10:44:05 > top of Java-index,Core,Core APIs...
# 2
HiHave been away for a few days. Thanks for your reply. No, it doesn't run from the Visual Age Workbench - I get a ClassCastException.Any ideas? Thanks for your help.Lyndsey
hairsinl at 2007-6-29 10:44:05 > top of Java-index,Core,Core APIs...
# 3

Hi

i can no retrace this problem. I can use in my example ctx.bind(String, object) and also ctx.bind(CompositeName, object). Have you test the first? and yuo are sure, that the ClassCastException() thrown by this method? Try to debug it step by step. Sorry, i have no more ideas.

Good Luck Roland

rkunzke at 2007-6-29 10:44:05 > top of Java-index,Core,Core APIs...
# 4

Hi

This is the code where the exception is occuring. If you can spot any mistakes please let me know.

Many thanks, Lyndsey.

try

{

//CurveGenRemote is the Remote interface, CurveGenImpl implements CurveGenRemote

//I have used the VAJ function Tools>>Generate RMI>>JDK1.2 Stubs & Skeletons to generate

//the remote stub for CurveGenImpl

CurveGenRemote c = new CurveGenImpl();

//bind remote object using JNDI

Hashtable env = new Hashtable();

System.out.println("trying to bind to the JNDI naming service");

env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.ibm.ejs.ns.jndi.CNInitialContextFactory");

env.put(javax.naming.Context.PROVIDER_URL, "iiop://localhost:900");

InitialContext ctx = new InitialContext(env);

System.out.println(c);

//this is where the ClassCastException is thrown - it doesn't want to bind the object c

ctx.bind("CurveGenService", c);

}catch(Exception e)

{

System.out.println("problem binding server " + e);

}

hairsinl at 2007-6-29 10:44:05 > top of Java-index,Core,Core APIs...
# 5

Hi Lyndsey,

i cann't find mistakes, but i also cann't test it, why i have the tool "Generate RMI" not installed. I generate the stubs for my EJBs over the EJB-pane.

But test follow, edit your code:

} catch (Exception e) {

e.printStackTrace();

}

Then you see more details to the exception, or set a breakpoint for the debugger and use there "F5" or "Step Into" to see where the exception throwed.

Goo luck Roland

rkunzke at 2007-6-29 10:44:05 > top of Java-index,Core,Core APIs...
# 6

Hi Roland

Thanks for your tip. My stack trace is as below. It looks like it is a problem with the bind() as expected. By the way, I am not writing this in an EJB, this code is in a standard Java program - I am just trying to use the naming service supplied by WebSphere. I can get it working using standard RMI, but I cannot seem to use the WebSphere naming service...

Thanks for your help, Lyndsey.

problem binding server javax.naming.NamingException: CurveGenService [Root exception is java.lang.ClassCastException]

javax.naming.NamingException: CurveGenService. Root exception is java.lang.ClassCastException

java.lang.Throwable()

java.lang.Exception()

java.lang.RuntimeException()

java.lang.ClassCastException()

org.omg.CORBA.Object com.ibm.ejs.ns.jndi.CNContextImpl.connectRemoteCORBA(java.lang.Object)

org.omg.CORBA.Object com.ibm.ejs.ns.jndi.CNContextImpl.connectRemoteCORBA(java.lang.Object)

void com.ibm.ejs.ns.jndi.CNContextImpl.doBind(org.omg.CosNaming.NameComponent [], java.lang.Object)

void com.ibm.ejs.ns.jndi.CNContextImpl.bind(java.lang.String, java.lang.Object)

void javax.naming.InitialContext.bind(java.lang.String, java.lang.Object)

com.chase.irfe.chasetools.poc.curvegen.CurveGenServer()

void com.chase.irfe.chasetools.poc.curvegen.CurveGenServer.main(java.lang.String [])

hairsinl at 2007-6-29 10:44:05 > top of Java-index,Core,Core APIs...
# 7
Good morning,i thnik your problem is not the object o, but is it the name. What is "CurveGenService"? Use the getter-methows from the NamingException to find details.Good Luck Roland
rkunzke at 2007-6-29 10:44:05 > top of Java-index,Core,Core APIs...
# 8

Hi

Thanks for your continued help!

Not sure why it should matter what name I give it, as long as it is a String? I have tried giving it other names such as CurveGenRemote (the remote interface), and CurveGenImpl (the implementation of the remote interface), but it still doesn't work. Do you think it has anything to do with the fact that I am using the persistent name service with the WebSphere test environment?

Thanks again, Lyndsey

hairsinl at 2007-6-29 10:44:05 > top of Java-index,Core,Core APIs...
# 9
I have use a String. Sorry, but i hava no more ideas and i goes in holidays today. Last tip, see under http://www-105.ibm.com/developerworks/java_df.nsf/AllDiscussionsByTitle?OpenForm, there are new forums from IBM.Good luckRoland
rkunzke at 2007-6-29 10:44:05 > top of Java-index,Core,Core APIs...
# 10
Thanks for your help, an have a good holiday!
hairsinl at 2007-6-29 10:44:05 > top of Java-index,Core,Core APIs...
# 11
Just for future reference for other people struggling with this problem, in order to bind to the WebSphere JNDI naming service, you need to generate iiop stubs for your remote object i.e. rmic -iiop MyRemoteImpl. It will not work if you are just generating rmi stubs.
hairsinl at 2007-6-29 10:44:05 > top of Java-index,Core,Core APIs...
# 12
Hi hairsinl,I'm facing a similar problem here, except I'm using WebSphere 5.1 and trying to access a LDAP server and bind it.Did you manage to solve yours, would appreciate if you could share some info !!Thanks Koen
koen_canada at 2007-6-29 10:44:05 > top of Java-index,Core,Core APIs...