[英]AssertionError “Context may not be null” when looking up remote EJB from standalone client
我正在運行WebLogic 12c,並已將多個bean部署為EAR文件的一部分。 我還有一個獨立的客戶端,該客戶端從Eclipse運行,試圖訪問遠程EJB。 我正在使用注釋,因此使用的是EJB 3.1中的全局可移植JNDI名稱(例如,java:global / ifactory / ifactory-ejb-4.0.0 / BomServiceBean!com.icumed.ifactory3.service.BomServiceRemote)。
但是,當遠程客戶端嘗試調用EBJ時,出現以下異常:
11:45:03,400 ERROR [com.icumed.ifactory3.service.RemoteServiceFactoryImpl] [getService('java:global/ifactory/ifactory-ejb-4.0.0/BomServiceBean!com.icumed.ifactory3.service.BomServiceRemote')] Context may not be null
java.lang.AssertionError: Context may not be null
at weblogic.j2eeclient.SimpleContext.checkForNameUnderRemoteNode(SimpleContext.java:103)
at weblogic.j2eeclient.SimpleContext.internalLookup(SimpleContext.java:68)
at weblogic.j2eeclient.SimpleContext.lookup(SimpleContext.java:39)
at weblogic.jndi.SimpleContext.lookup(SimpleContext.java:86)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at com.icumed.ifactory3.service.RemoteServiceFactoryImpl.getService(RemoteServiceFactoryImpl.java:323)
Bean看起來像這樣:
@Stateless
public class BomServiceBean extends AbstractSessionBean implements LocalBomService, BomServiceRemote
{
...
}
進一步的信息:當wlthint3client.jar和wlclient.jar位於類路徑時,將發生此錯誤。
當僅wlthint3client.jar位於類路徑上時,例外是
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long
at weblogic.rmi.internal.StubInfo.getEnvQueriedJNDITimeout(StubInfo.java:256)
at weblogic.rmi.internal.StubInfo.setEnvQueriedJNDITimeout(StubInfo.java:242)
at weblogic.rmi.internal.StubInfo.readObject(StubInfo.java:238)
當wlclient.jar和wlthint3client.jar位於類路徑上時,WebLogic將輸出以下日志消息:
The connection attempt was rejected because the incoming protocol iiop is not enabled on channel Default[iiop][12]
我該如何糾正?
首先,確保您僅在類路徑中包含wlthint3client.jar,而沒有wlclient.jar。 那將擺脫AssertionError並只留下ClassCastException。
其次,ClassCastException問題在wlthint3client.jar(StubInfo.java)的代碼中。 如果在jndi.properties文件中指定以下兩個屬性,則不能正確地將它們從String轉換為Long。
Long o = (Long)props.get("weblogic.jndi.responseReadTimeout");
if (o == null) {
o = (Long)props.get("weblogic.rmi.clientTimeout");
}
如果需要設置這些屬性,則必須在代碼中創建一個Hashtable並將其傳遞給InitialContext。
Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put("weblogic.jndi.responseReadTimeout", 15000L);
env.put("weblogic.rmi.clientTimeout", 15000L);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.