Invoke a remote object form EJB

Hi,I want to invoke a remote object ( exposed by RMI on a different host ) from my EJB container. Is there some preferred way or design pattern for doing this, or should I directly lookup the RMI registry and invoke the methods.
[242 byte] By [anand_nalyaa] at [2007-11-27 8:08:06]
# 1
If your EJB is a client of a plain Java SE RMI object, there is no special programming model definedby Java EE.You would just use the same RMI client programming model that would be used froma Java SE client. --ken
ksaksa at 2007-7-12 19:50:55 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

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

yogendra_ga at 2007-7-12 19:50:55 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...