File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassCastException using Naming.lookup()

 
Matt Senecal
Ranch Hand
Posts: 255
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My client is trying to connect (via RMI) to a server that resides on another machine. The server is an implementation of the interface MyServer, Class MyServerImpl. During the Naming.lookup I'm getting a ClassCastException:
java.lang.ClassCastException: MyServerImpl_Stub

I've checked, and there *is* a stub being returned. The server is up and running, and was compiled from the same code that the client is referencing. From what I can tell, this should work. Anyone have any ideas why it's not?
[This message has been edited by Matt Senecal (edited October 05, 2001).]
[This message has been edited by Matt Senecal (edited October 05, 2001).]
[This message has been edited by Matt Senecal (edited October 05, 2001).]
[This message has been edited by Matt Senecal (edited October 05, 2001).]
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the client have a copy of the interface that the stub implements?
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
Matt Senecal
Ranch Hand
Posts: 255
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. That's what's so confusing. Same code. Same Java environment. The only thing that's different is that the server resides on a Solaris 8 machine, and the client on Win 2000.
Originally posted by Michael Ernest:
Does the client have a copy of the interface that the stub implements?

 
saryu mehta
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ClassCastExceptions using CXS process in iPlanet 6.0 SP3.
Topic: EJB
Luke Potter, Oct 30, 2001 [replies:4]
Does anyone know how to eliminate the error pasted below? I am accessing an EJB running in iPlanet AppServer 6.0 SP3 from a Rich Client using the CXS process. Both are running on Solaris. This error is generated repeatedly after first attempted access.
java.lang.ClassCastException
at java.lang.Throwable.fillInStackTrace(Native Method)
at java.lang.Throwable.<init>(Throwable.java:82)
at java.lang.Exception.<init>(Exception.java:33)
at java.lang.RuntimeException.<init>(RuntimeException.java:37)
at java.lang.ClassCastException.<init>(ClassCastException.java:36)
at com.sun.corba.ee.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:296)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
at com.netscape.ejb.KivaToCorbaObjectInputStream.resolveObject(Unknown Source)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:383)
at java.io.ObjectInputStream.inputArray(ObjectInputStream.java:951)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:357)
at java.io.ObjectInputStream.inputClassFields(ObjectInputStream.java:1831)
at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:502)
at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1166)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:232)
at com.kivasoft.ebfp.FPSerializable.unserialize(Unknown Source)
at com.kivasoft.ebfp.FPReply.getPayloadObjnative(Native Method)
at com.kivasoft.ebfp.FPReply.getPayloadObjnative(Native Method)
at com.kivasoft.ebfp.FPReply.getPayloadObj(Unknown Source)
at com.kivasoft.eb.boot.ejb_kcp_stub_IEBBootstrap.getHome(ejb_kcp_stub_IEBBootstrap.java:331)
at com.kivasoft.eb.boot.ejb_stub_IEBBootstrap.getHome(ejb_stub_IEBBootstrap.java:73)
at com.netscape.server.ejb.EjbContext.createHomeRef(Unknown Source)
at com.netscape.server.ejb.EjbContext.getHomeRef(Unknown Source)
at com.netscape.server.ejb.EjbContext.lookup(Unknown Source)
at com.netscape.server.jndi.RootContext.lookup(Unknown Source)
at com.netscape.server.jndi.RootContext.lookup(Unknown Source)
at javax.naming.InitialContext.lookup(InitialContext.java:357)
at com.netscape.ejb.CorbaHomeFactoryImpl.ConstructEJBHome(Unknown Source)
at com.netscape.CosNaming.NamingContextImpl.resolve(Unknown Source)
at org.omg.CosNaming._NamingContextImplBase.invoke(_NamingContextImplBase.java:233)
at com.sun.corba.ee.internal.corba.ServerDelegate.dispatch(ServerDelegate.java:236)
at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:227)
at com.sun.corba.ee.internal.iiop.CachedWorkerThread.doWork(IIOPConnection.java:262)
at com.sun.corba.ee.internal.iiop.CachedWorkerThread.run(IIOPConnection.java:230)


Re: ClassCastExceptions using CXS process in iPlanet 6.0 SP3.
Topic: EJB
Bozidar Dangubic, Oct 30, 2001 [replies:3]
need the source. you are casting to a wrong type but what the actual problems is cannot be determined from the stack trace alone. send the source.

Re: Re: ClassCastExceptions using CXS process in iPlanet 6.0 SP3.
Topic: EJB
Luke Potter, Oct 30, 2001 [replies:2]
Here is the source that I believe is responsible, but I can't tell since there is no application-level call in the stack trace. It might also be worth saying that the same deployed ear file doesn't seem to cause the error on an NT machine.
try{

this.sIPAddress = sIPAddress.trim();
this.sPortNumber = sPortNumber.trim();

user = new User();

Properties env = new Properties();
env.put("java.naming.factory.initial",
"com.sun.jndi.cosnaming.CNCtxFactory");

env.put("java.naming.provider.url", "iiop://" +sIPAddress +":"
+ sPortNumber);

Context jndiContext = new javax.naming.InitialContext(env);

cvHome = (CustViewsHome)jndiContext.lookup("ejb/CustViewsSB");
uHome =(UserHome)jndiContext.lookup("ejb/UserSB");
cvRemote = cvHome.create();
uRemote = uHome.create();

user = uRemote.getAuthorizedUser(sUserID);
user.setUserLangPref(AccEnums.EN);
}catch(AccuiException ee){
System.out.println("Accui Exception :"+ee.getMessage());
ee.printStackTrace() ;
}catch(Exception ed){
System.out.println("General Exception :"+ed.getMessage());
ed.printStackTrace() ;
}

Re: Re: Re: ClassCastExceptions using CXS process in iPlanet 6.0 SP3.
Topic: EJB
Bozidar Dangubic, Oct 30, 2001 [replies:1]
here is where the problem is (unless you are still working with EJB 1.0 which I doubt since you are using iPlanet 6).
cvHome = (CustViewsHome)jndiContext.lookup("ejb/CustViewsSB");
uHome =(UserHome)jndiContext.lookup("ejb/UserSB");
you have to use PortableRemoteObject to cast. you cannot cast directly as you are doing using java cast. so change the code to
Object ref = jndiContext.lookup("ejb/CustViewsSB");
cvHome = (CustViewsHome) PortableRemoteObject.narrow(ref,CustViewsHome.class);
ref =jndiContext.lookup("ejb/UserSB");
uHome = (UserHome) PortableRemoteObject.narrow(ref,UserHome.class);

Re: Re: Re: Re: ClassCastExceptions using CXS process in iPlanet 6.0 SP3.
Topic: EJB
Luke Potter, Oct 30, 2001
Thanks Bozidar. We made the suggested code change, as well as added lines of output that would help us trace how far the client app was getting. It is still getting hung up in this code, and the server is still throwing the same exceptions. It is also still working on the Application Server installed on the NT machine. Any other thoughts?


 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm transferring this to our new iPlanet forum...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic