• Post Reply Bookmark Topic Watch Topic
  • New Topic

ClassCastException with PortableRemoteObject.narrow  RSS feed

 
doni klauz
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm try to do a lookup to bean:
mySessionBeanHome home = (mySessionBeanHome )
javax.rmi.PortableRemoteObject.narrow(
ctx.lookup "ejb/myPackage/mySessionBeanHome" ),
mySessionBeanHome.class );

And I'm getting the following error:

Exception in thread "P=549438 =0:CT" java.lang.ClassCastException: cannot cast class org.omg.stub.java.rmi._Remote_Stub to interface myPackage.mySessionBeanHome
at com.ibm.rmi.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:409)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:156)
at myPackage.MyClient.main(MyClient.java:59)

Does anyone has any idea?
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi doni,

I know it sounds odd, but I remember someone else having a similar problem. The way he solved it was to refactor the code like this:

Regards.
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doni,
You asked:

Does anyone has any idea?

No, but if it would be me, I would start by using the java reflection API to interrogate the object returned by the "lookup()" method.

Of-course, it could also be that your client -- the one invoking the "lookup()" method -- does not have access to the "mySessionBeanHome" interface. Have you verified that it does?

Good Luck,
Avi.
 
doni klauz
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've done as you both suggested:

Object obj = ctx.lookup( "ejb/myPackage/mySessionBeanHome" );
javax.rmi.PortableRemoteObject.narrow( obj, mySessionBeanHome.class );


And I'm getting the same exception.

when I investigate the returned object from the lookup:
Class c = obj.getClass();
System.out.println(c.getName());
System.out.println(c.getDeclaredMethods().length);
System.out.println(c.getDeclaredMethods()[0].getName());
System.out.println(c.getDeclaredFields().length);
System.out.println(c.getDeclaredFields()[0].getName());
System.out.println(c.getDeclaredClasses().length);
System.out.println(c.getDeclaredConstructors().length);
System.out.println(c.getDeclaredConstructors()[0].getName());

I'm getting the following info:
org.omg.stub.java.rmi._Remote_Stub
1
_ids
1
_type_ids
0
1
org.omg.stub.java.rmi._Remote_Stub

I didn't succeed to understand from this info which object was retuned by the look up...
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tryed also the following, I hope it is more informative:

Object obj = ctx.lookup( "ejb/myPackage/mySessionBeanHome" );
Class c = obj.getClass();

System.out.println("Methods:");
for (int i=0; i<c.getMethods().length; i++)
System.out.println(i+ ")"+ c.getMethods()[i].getName());

System.out.println("Fields:");
for (int i=0; i<c.getFields().length; i++)
System.out.println(i+ ")"+ c.getFields()[i].getName());

System.out.println("Constructors:");
for (int i=0; i<c.getConstructors().length; i++)
System.out.println(i+ ")"+ c.getConstructors()[i].getName());
javax.rmi.PortableRemoteObject.narrow( obj, mySessionBeanHome.class );


And I get the following result:

Methods:
0)_ids
1)hashCode
2)equals
3)toString
4)connect
5)_get_codebase
6)_get_delegate
7)_set_delegate
8)_duplicate
9)_release
10)_is_a
11)_is_equivalent
12)_non_existent
13)_hash
14)_request
15)_create_request
16)_create_request
17)_get_interface_def
18)_orb
19)_get_policy
20)_get_domain_managers
21)_set_policy_override
22)_is_local
23)_servant_preinvoke
24)_servant_postinvoke
25)_request
26)_invoke
27)_releaseReply
28)getClass
29)notify
30)notifyAll
31)wait
32)wait
33)wait
Fields:
Constructors:
0)org.omg.stub.java.rmi._Remote_Stub

Exception in thread "P=874250 =0:CT" java.lang.ClassCastException: cannot cast class org.omg.stub.java.rmi._Remote_Stub to interface myPackage.mySessionBeanHome
at com.ibm.rmi.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:409)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:156)
at myPackage.MyClient.main(MyClient.java:73)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!