jboss jndi 上下文为空

发布于 2024-12-07 09:14:43 字数 693 浏览 0 评论 0原文

部署到 jboss 7 的 ejb-jar 具有 jdni 绑定“java:global/foo!IFoo”。 Jboss 管理控制台显示此绑定。 jndi 端口默认为 1099。 jboss 上的客户端获取该绑定的对象,但在同一台计算机上运行的独立客户端则无法获取该对象。

Properties properties = new Properties();  
properties.put("java.naming.factory.initial",
               "org.jboss.as.naming.InitialContextFactory");    
properties.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
properties.put("java.naming.provider.url","jnp://localhost:1099");
Context ctx = new InitialContext(properties);
NamingEnumeration<NameClassPair> list = ctx.list("");
while (list.hasMore()) {
    System.out.println(list.next().getName());
}

没有结果。对上面名称的查找也失败。 问题出在哪里?

An ejb-jar deployed to jboss 7 has a jdni binding "java:global/foo!IFoo".
Jboss management console shows this binding.
The jndi port is 1099 as by default.
A client on jboss gets an object to that binding but a standalone client running on the same machine does not.

Properties properties = new Properties();  
properties.put("java.naming.factory.initial",
               "org.jboss.as.naming.InitialContextFactory");    
properties.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
properties.put("java.naming.provider.url","jnp://localhost:1099");
Context ctx = new InitialContext(properties);
NamingEnumeration<NameClassPair> list = ctx.list("");
while (list.hasMore()) {
    System.out.println(list.next().getName());
}

produces no results. Also the lookup to the name above fails.
Where is the problem ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦断已成空 2024-12-14 09:14:43

看来远程 JNDI 查找支持仅在 JBoss AS 7.1.0.Final 上实现(AS7-1338)。

用于执行远程查找的 JNDI 属性也已更改。您可以尝试使用这些 JNDI 属性实例化 InitialContext 吗?

properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
properties.put(Context.PROVIDER_URL, "remote://localhost:4447");
properties.put(Context.SECURITY_PRINCIPAL, "user");
properties.put(Context.SECURITY_CREDENTIALS, "password");

对 JNDI 树的远程访问是安全的,因此您需要提供用户和密码(通过 add-user.sh/add-user.bat 脚本)。

我在自己的本地服务器上执行了此操作,但 InitialContext.list() 返回的 NamingEnumeration 仍然为空,即使下面的查找工作正常。我在 JBoss 论坛 上发布了答案,但到目前为止还没有运气。

// This lookup works fine
System.out.println(ctx.lookup("jms/RemoteConnectionFactory").getClass().getName());
// ... but this list doesn't (empty enumeration)
NamingEnumeration<NameClassPair> list = ctx.list("");

It seems remote JNDI lookup support was implemented only on JBoss AS 7.1.0.Final (AS7-1338).

The JNDI properties to perform remote lookups has also changed. Could you try to instantiate the InitialContext with these JNDI properties?

properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
properties.put(Context.PROVIDER_URL, "remote://localhost:4447");
properties.put(Context.SECURITY_PRINCIPAL, "user");
properties.put(Context.SECURITY_CREDENTIALS, "password");

The remote access to the JNDI tree is secured, so you need to provide a user and a password (add an Application User via add-user.sh/add-user.bat script).

I did this on my own local server, but the NamingEnumeration returned by InitialContext.list() is still empty, even though the lookup below works fine. I posted an answer on JBoss forum, but no luck so far.

// This lookup works fine
System.out.println(ctx.lookup("jms/RemoteConnectionFactory").getClass().getName());
// ... but this list doesn't (empty enumeration)
NamingEnumeration<NameClassPair> list = ctx.list("");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文