I have an Enterprise application which has a Stateless
EJB and a JAX-WS based web service. Web service when invoked will internally invoke the
EJB. lib
folder contains the common libraries needed for both EJB and WAR.
I'm facing two issues while accessing EJB in different ways. It works fine when I access it through the web service
This is deployed on IBM WAS v7 This is the structure of the EAR
MyProject.EAR
webservice.war
ejb.jar
lib
abc.jar
xyz.jar
Now in the EJB I have a class which is exposed as Remote
and Local
.
@Stateless
public class MyAccountBean implements AccountLocal,AccountRemote{
}
As mentioned above, in the web project we are invoking the EJB using a local reference.
AccountLocal accLocal=(AccountLocal)ctx.lookup("ejblocal:com.my.test.account.AccountLocal");
This works fine.
First Issue:-
We have another EAR application deployed on the same JVM of WAS. From this application we are trying to access the EJB available in MyProject.EAR
. Is it possible to get this information using a JNDI lookup since they are both on the same JVM? We tried with the below code,
AccountLocal accLocal=(AccountLocal)ctx.lookup("jndiOfAccountLocal");
But it gives Class cast exception.
Error 500: java.lang.ClassCastException: com.my.test.account.EJSLocal0SLDAccount_e303bda3 incompatible with com.my.test.account.AccountLocal
Second Issue:-
Second problem that we have is with the Remote EJB lookup. Below is the code that we are usign to get the Remote EJB reference from a web application deployed on a different server.
Properties props = new Properties();
props.put( Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory" );
props.put( javax.naming.Context.PROVIDER_URL, "iiop://localhost:2809" );
AccountRemote remote = null;
try{
InitialContext ctx = new InitialContext( props );
lobj = ctx.lookup( "dcpejbsvc" );
AccountRemote remoteObj = (AccountRemote)PortableRemoteObject.narrow( lobj, AccountRemote.class );
InputVO input = constructInput();
OutputVO output = remoteObj.getAccountInfo( input );
}
catch( NamingException e ){
// TODO Auto-generated catch block
e.printStackTrace();
}
This gives class cast exception that Error 500: java.lang.ClassCastException: cannot cast class org.omg.stub.java.rmi._Remote_Stub to interface com.my.test.account.AccountRemote
Could you please guide me to fix these issues?
Updated: I got a detailed response from the post in coderanch. Similar to the first answer
For the first problem, see the "Local client views" section of the EJB modules topic in the InfoCenter. Specifically, the same local interface Class needs to be visible (from a ClassLoader perspective) to both applications. This is typically done by using a server-scoped shared library.
For the second problem, my guess is that your "different server" does not have _AccountRemote_Stub. Is the other server WebSphere Application Server v7 or later? If no, you likely need to generate stubs using the WAS_HOME/bin/createEJBStubs
command. Otherwise, please update your answer to show the full stack trace of the ClassCastException (WebSphere Application Server v7 or later should automatically generate stubs, and perhaps the full stack trace will give a hint).