I'm using was 9.0, EJB 3.0 and I written a RMI class to call the remote's EJB. When I run, the console shows me this error:
Exception in thread "P=69052:O=0:CT" java.lang.ClassCastException: org.omg.stub.java.rmi._Remote_Stub
The RMI call:
MyEjbRemote ejb = (MyEjbRemote) ctx.lookup(JNDI_NAME_EJB);
The remote class has the @Statless and @Remote tags. Does anyone could help me?
WebSphere uses RMI/IIOP to provide support for EJB remote interfaces, which requires a client side
_Stubclass that implements the EJB remote interface. When thectx.lookup()occurs in a managed thread, the_Stubclass would normally be generated for you automatically by the container and returned from the lookup, which could then be cast to the remote interface.Unfortunately, there are a variety of reasons this may not occur. For example, the lookup is performed from a thin client. For those scenarios, you will need to do one or both of the following:
1 - Perform a
PortableRemoteObject.narrow():This typically solves issues where the Naming service may have cached a value that has not been narrowed, or perhaps has been narrowed using a different classloader.
2 - Generate the
_Stubclass for the remote interface and package it with the application code that is performing the lookup. ThecreateEJBStubs.sh/.batcommand provided by WebSphere may be used to generate the_Stubclass. Also, if the remote interface extendsjava.rmi.Remote, then you may instead use the RMIC command from the JDK with the-iiopoption. Information aboutcreateEJBStubsmay be found here:https://www.ibm.com/docs/en/was/9.0.5?topic=beans-create-stubs-command
This solves issues where the thread performing the lookup is not a managed thread. A managed thread is a thread created by the container specifically for running an application. Managed threads contain application context information and have the ability to dynamically generate EJB artifacts, such as
_Stubclasses as needed.