• Post Reply Bookmark Topic Watch Topic
  • New Topic

RemotePortableObject.narrow throws ClassCastException

 
Douglas Kent
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Doing a very simple HelloWorld app, trying to contact the EJB on Sun One Server. Following Sun's directions in the code, as follows:

InitialContext ctx = new InitialContext();
java.lang.Object ref = ctx.lookup("MySessionEJB");
MySessionEJBHome mySessionEJBHome = (MySessionEJBHome) PortableRemoteObject.narrow(ref,
MySessionEJBHome.class);

Exception is:

java.lang.ClassCastException
at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:294)
at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
at MySessionEJBClient.main(MySessionEJBClient.java:16)

Ideas?
 
Ramakrishnan thiyagarajan
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
U should import javax.rmi.* bcos in EJB1.1 supports rmi-iiop protocol it does not allow casting.actually corba supports rmi-iiop protocol.
 
Dan Johnsson
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Douglas Kent:
InitialContext ctx = new InitialContext();
java.lang.Object ref = ctx.lookup("MySessionEJB");

java.lang.ClassCastException

Ideas?[/QB]


Obvoiusly 'ref' referred to an object of some other type. It could be that your home is deployed under another name (doublecheck deployment descriptor) or that your app-server throws on a prefix (such things are not unheard of).

Check out the class of the 'ref' object (ref.getClass().getName()), it might give a clue.
 
Dan Johnsson
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ramakrishnan thiyagarajan:
Hi,
U should import javax.rmi.* bcos in EJB1.1 supports rmi-iiop protocol it does not allow casting.actually corba supports rmi-iiop protocol.


1) I do not see how the code could have worked without importing javax.rmi.PortableRemoteObject: it have obviously compiled.

2) What difference should importing or not make a difference during runtime? Import is a pure compile-time feature.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!