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 不能在 EJBStandaloneClient.main(EJBStandaloneClient.java:27) 中转换为 .SearchServicesRemoteBusiness

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

4

2 回答 2

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);
于 2013-09-23T14:24:13.137 回答
0

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

我纠正了这个,它工作正常:)

于 2013-09-24T11:37:48.060 回答