ClassCastException while using narrow() on a Remote EJB

Discussions

EJB programming & troubleshooting: ClassCastException while using narrow() on a Remote EJB

  1. Hi, I have created a Standalone Java application client using WSAD 5.0.1. The ear file is deployed into WAS 5.0 server. The application contains a Java file which uses local EJB (EJB1) to connect to a remote EJB (EJB2) running on Weblogic, and which updates the database. Now, the problem I'm facing is that, the lookup appears to have been done properly. But I'm getting the error attached below : com.o2.registration.adapter.CompanionAdapterBean_hlbf8t_HomeImpl_WLStubjava.lang.ClassCastException: com.o2.registration.adapter.CompanionAdapterBean_hlbf8t_HomeImpl_WLStub at com.ibm.rmi.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:328) at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:146) at com.ibm.o2c.common.adapters.horizon.HorizonAdapterEJBBean.getRemoteInterface(HorizonAdapterEJBBean.java:417) at com.ibm.o2c.common.adapters.horizon.HorizonAdapterEJBBean.getSearchCount(HorizonAdapterEJBBean.java:725) at com.ibm.o2c.horizon.bulkretrieve.BulkRetrieve.searchByMsisdn(BulkRetrieve.java:466) at com.ibm.o2c.horizon.bulkretrieve.BulkRetrieve.process(BulkRetrieve.java:233) at com.ibm.o2c.horizon.bulkretrieve.BulkRetrieve.main(BulkRetrieve.java:208) It'd appear that the object returned is of type HomeImpl_WLStub and it cannot be casted into the home interface type (which my code is trying to do). The code snippet goes like this....... // lookup of IIOP host Properties env = new Properties(); env.put(Context.PROVIDER_URL, provider_url); env.put(Context.INITIAL_CONTEXT_FACTORY, initial_context_factory); initialCtx = null; initialCtx = new InitialContext(env); //Get home interface Object objHome = initialCtx.lookup(jndi_name); stubHome = (com.ibm.test.horizon.CompanionAdapterHome) PortableRemoteObject.narrow( objHome, com.ibm.test.horizon.CompanionAdapterHome.class); retVal = stubHome.create(); I have the correct lookup details ( I know this because there's another application running on the same WAS machine which is using the same details as my EJB and is able to connect without any issues). I've tried to run the client using 'java' command and also 'launchclient' script. Both of them show me the same error. Could someone please help me? This is really urgent and I've wasted 2 weeks investigating this issue.
  2. It looks very bizzare problem. Can you please send out your complete Local bean class code. I assume you are not using any WebSphere specific imports in your local bean class. If Weblogic Bean is correctly deploed I dont see any other problems except the Java Versions on which both the Weblogic and the WebSphere is running. Have you tried looking up up your Weblogic Bean from standalone Java code by Using the same VM on which your WebSphere runs. If not I suggest to try that out. Biswaranjan Das SCJP,SCWCD,SCBCD
  3. EJB Code[ Go to top ]

    I have included weblogic.jar in the classpath. Every other jar file that's required is in the classpath. The Weblogic EJB has been deployed properly. The other application is able to access it fine. I'm sorry, I could not paste the entire code here, because of contractual issues. But, all I can say is that, the EJB is similar to what the other application is using to connect to the remote EJB. The part of the code that is connecting to the EJB, has been pasted in the original message itself. Here's the list of libraries that I've imported: package com.ibm.o2c.common.adapters.horizon; import java.io.IOException; import java.util.HashMap; import java.util.MissingResourceException; import java.util.Properties; import java.util.ResourceBundle; import javax.ejb.CreateException; import javax.ejb.EJBException; import javax.ejb.SessionBean; import javax.ejb.SessionContext; import javax.naming.Binding; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingEnumeration; import javax.naming.NamingException; import javax.rmi.PortableRemoteObject; import javax.servlet.jsp.JspWriter; import com.ibm.o2c.common.adapters.horizon.exceptions.HorizonException; import com.ibm.o2c.common.adapters.horizon.teststub.HorizonAdapterTestStubEJB; import com.ibm.o2c.common.adapters.horizon.teststub.HorizonAdapterTestStubEJBHome; import com.ibm.o2c.horizon.utilities.Messenger; import com.o2.registration.adapter.CompanionAdapterHome; import com.ibm.websphere.naming.WsnInitialContextFactory; Hope this was what you asked for. Do you think I need to add any specific VM arguments while launching the client? Please help!!! Thanks, Jyotsna
  4. Re: EJB Code[ Go to top ]

    Do not put weblogic.jar in websphere classpath (remove it if you have put it)instead bundle wl_client.jar (250 kb size jar file) in the EAR you are trying to deploy in WebSphere. weblogic.jar shares lot of same package defined classes which will conflict with Websphere ones & make sure you are using right context factory which is bundled in client jar of weblogic.
  5. Where do I find wl_client.jar?[ Go to top ]

    Hi, I am unable to find this jar file wl_client.jar. Where can I download a copy. Or does it come installed with the Weblogic? The machine on which WebLogic is installed is out of bounds for us. Are there any version dependencies for this jar file? If you have a copy of the jar file, could you please mail it to me at jyotsna_bk at yahoo dot com. Thanks very much. Cheers, Jyotsna
  6. Re: Where do I find wl_client.jar?[ Go to top ]

    You can download this wlclient.jar. It is usually in the same folder from where you can find weblogic.jar. Google "download wlclient.jar" if you could not then download the evaluation version of weblogic and you are there.
  7. Hi, That comes with weblogic server. Thank you.
  8. Hi, See the following link, http://edocs.bea.com/wls/docs81/programming/concepts.html
  9. Hi, See the following link http://edocs.bea.com/wls/docs81/programming/concepts.html Thanks
  10. Hi, The problem , is you are trying to access a bean in different JVM from your call making JVM. That time the other JVM must be aware of your bean stub. That is the problem as I see. As you told you are getting the JNDI reference perfectly. Then iterate through your JNDI tree and print all entries, see whether the OBJECT you are trying to access is present or not. Please make sure that the Stub must be present of that remote interface in the JNDI tree, If not it will not run. Thank you.