java.lang.ClassCastException:org.omg.stub.java.rmi._Remote_Stub无法强制转换为<remote business =“”interface =“”name =“”> </remote>

时间:2013-09-23 11:19:15

标签: java-ee websphere ejb-3.0

我正在使用WAS服务器,我编写了一个java客户端,通过业务接口调用一个EJB,如下所示:

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);

错误:

java.lang.ClassCastException:org.omg.stub.java.rmi._Remote_Stub无法强制转换为.SearchServicesRemoteBusiness         在EJBStandaloneClient.main(EJBStandaloneClient.java:27)

我尝试过:我使用createEJBStubs.sh为这个远程业务接口创建存根,并在运行时将此存根放在客户端类路径中,但错误仍然存​​在。 欢迎提出任何建议。

2 个答案:

答案 0 :(得分:1)

致电PortableRemoteObject.narrow

SearchServicesRemoteBusiness remoteBusiness = (SearchServicesRemoteBusiness)
    PortableRemoteObject.narrow(initialCtx.lookup("amdocs-RM-Billing/CM-L1/SearchServicesBean!amdocs.csm3g.sessions.views.business.remote.SearchServicesRemoteBusiness"),
    SearchServicesRemoteBusiness.class);

答案 1 :(得分:0)

问题出现在我的类路径中,我给出了存根的完整类位置,而不应该在类路径中包含包结构。例如,我在目录x / y / z // stub.class中创建了存根。所以我们应该在类路径中使用x / y / z而不是x / y / z // stub.class。

我纠正了这个并且工作正常:)