我正在设置一个访问已部署的 EJB 的 servlet 客户端。 EJB 在 WebSphere 8.5
上以 2 节点设置进行部署。在每台服务器上,我将部署访问 EJB 的 Servlet。人们将连接到 Servlet,其内部将连接到 EJB 并返回响应。
要访问 EJB,我需要初始化上下文。我相信代码看起来像下面几行。
private void doSomething() {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(Context.PROVIDER_URL,"iiop//host:port");
Object obj;
try{
InitialContext ctx = new InitialContext(env);
obj = ctx.lookup("EjbSample");
} catch(Exception ne){ ... }
}
我的问题是:
在哪里可以找到
iiop//host:port
主机和端口来连接 EJB。 WebSphere 管理控制台中的某个位置?有配置文件吗?因为我有 3 个节点设置。我在每个节点中有 2 个名为 ClusterServlet 和 ClusterEJB 的集群。 IIOP 主机和端口会因节点而异,还是在两个节点之间保持一致?
[编辑 1]:当我尝试从运行 WAS 的同一主机访问 EJB 时,出现以下错误
javax.naming.NameNotFoundException: Name "EjbSample" not found in context "serverlocal:CELLROOT/SERVERROOT
最佳答案
以下知识中心页面讨论通过 ProviderURL 获取 InitialContext: https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/rnam_example_prop2.html
它指出“提供程序 URL 包含初始上下文工厂可用于获取初始上下文的引导服务器信息。”
可以通过管理控制台或 serverindex.xml
文件找到特定服务器的引导端口信息。这些端口值可能因节点而异,具体取决于在单元中安装或添加节点和/或服务器期间使用的设置。
管理控制台:
- 参见https://www.ibm.com/support/knowledgecenter/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/urun_rendpoint_inst.html
遵循路径服务器 > 服务器类型 > WebSphere 应用程序服务器 > server_name> 端口
BOOTSTRAP_ADDRESS
端口是在提供程序 URL 中使用的端口。
serverindex.xml:
在每个服务器节点上找到:WAS_HOME/profiles/serverProfile/config/cells/cellName/nodes/节点名称
包含节点上的每个服务器及其服务器端口的列表。
endPointName="BOOTSTRAP_ADDRESS"
包含所需的端口
关于ejb - 如何在WebSphere 中查找InitialContext 详细信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57258775/