Search code examples
jakarta-eewebsphereejb-3.0

java.lang.ClassCastException: org.omg.stub.java.rmi._Remote_Stub cannot be cast to <Remote Business interface name>


I am using WAS server and I have written a java client to call one EJB through business interface as follows:

Hashtable<String, String> envJNDIProperties = new Hashtable<String, String>();
                        envJNDIProperties.put("javax.naming.factory.initial", "com.ibm.websphere.naming.WsnInitialContextFactory");
                        envJNDIProperties.put("java.naming.provider.url", "iiop://indmtx981:24121");
                        envJNDIProperties.put("java.naming.security.principal", myTicket);
                        envJNDIProperties.put("java.naming.security.credentials", "NA");
                        envJNDIProperties.put("org.omg.CORBA.ORBClass", "com.ibm.CORBA.iiop.ORB");

                        InitialContext initialCtx = new InitialContext(envJNDIProperties);

                        Object ejbObject = null;

/*
* Giving me error in following line
*/                         
SearchServicesRemoteBusiness remoteBusiness = (SearchServicesRemoteBusiness) initialCtx.lookup("amdocs-RM-Billing/CM-L1/SearchServicesBean!amdocs.csm3g.sessions.views.business.remote.SearchServicesRemoteBusiness");

                        System.out.println("Got referencve for: "+ ejbObject.getClass().getName());
//                      SearchServicesRemoteBusiness remoteBusiness = (SearchServicesRemoteBusiness) PortableRemoteObject.narrow(ejbObject,amdocs.csm3g.sessions.views.business.remote.SearchServicesRemoteBusiness.class);

                        AccountIdInfo accountId = new AccountIdInfo();

                        remoteBusiness.searchAccountById(accountId);

Error:

java.lang.ClassCastException: org.omg.stub.java.rmi._Remote_Stub cannot be cast to .SearchServicesRemoteBusiness at EJBStandaloneClient.main(EJBStandaloneClient.java:27)

what i have tried: I use createEJBStubs.sh to create stub for this remote business interface and while running put this stub in client classpath, but error still exists. Any suggestion is welcome.


Solution

  • Problem was in my class path, i was giving the full class location of stub, rather i should not include package structure in the class path. For e.g i have created stub in directory x/y/z//stub.class . So we should use x/y/z in class path not x/y/z//stub.class .

    i corrected this and it is working fine :)