Hi
I have exactly similar requirement.
I have registered an RMI object in the JNDI tree of the Weblogic server.
This RMI object is supposed to be acessed by multiple Session Beans.
I lookup the RMI object and get the instance.
But when I try to narrow it , it thorws the ClassCastException.
Following is my code :
Object obj = ctx.lookup("RemoteServiceJNDI");
RemoteService sing = (RemoteService) PortableRemoteObject.narrow(obj,RemoteService.class);
The exception thrown is :
java.lang.ClassCastException: Cannot narrow remote object to com.poc.three.RemoteService
at weblogic.iiop.PortableRemoteObjectDelegateImpl.narrow(PortableRemoteObjectDelegateImpl.java:242)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
at com.poc.three.server.MySessionBean.getSingleton(MySessionBean.java:165)
at com.poc.three.server.MySessionBean.appLogin(MySessionBean.java:87)
at com.poc.three.server.MySession_ylxi4w_EOImpl.appLogin(MySession_ylxi4w_EOImpl.java:46)
at com.poc.three.server.MySession_ylxi4w_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:477)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:108)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:420)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:353)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:144)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:415)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
I write the same code in another class's main method , it works fine.
Means I cannot type cast the object in EJB container but outside of the server I can type cast it.
If i write SOPs as follows :
System.out.println(obj.getClass().getName()+" .......................... ");
System.out.println(RemoteService.class.getName()+"......./////////////////");
System.out.println(obj instanceof RemoteService);
then it gives me outpout as :
com.poc.three.RemoteServiceImpl_812_WLStub ..........................
com.poc.three.RemoteService......./////////////////
false
But out side of the EJB container same code invocation gives output as :
com.poc.three.RemoteServiceImpl_812_WLStub ..........................
com.poc.three.RemoteService......./////////////////
true
This problem is with Weblogic only.
When deployed on JBOSS it works fine.
What could be the problem ?
Message was edited by:
yogendra_g