在执行 jndi 查找时,如何找出应该使用什么 SerialContextProvider?

发布于 2024-09-14 21:01:43 字数 1189 浏览 2 评论 0原文

今天我遇到了这个异常,

Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext  [Root exception is java.lang.NullPointerException]
        at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:276)
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
        ... 23 more

我试图远程访问一个 ejb,有问题的代码是

Context c = new InitialContext();

我之前见过这个异常并修复了它,但不记得我是如何做到的。我知道我必须为初始、上下文 url 和服务提供商或类似的东西设置一些环境变量。

事实上,我设法找到了上次用来解决这个问题的代码,如下所示。

Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
env.put(Context.PROVIDER_URL, "localhost:1099");
Context c = new InitialContext(env);

我的问题是,如何找出要使用的初始上下文工厂?我已经为在 glassfish v3 上运行的数据库编写了一个 ejb 模块,但我没有得到任何提示,我当然应该使用 com.sun.enterprise.naming.SerialInitContextFactory,我的意思是就像它如此明显一样。谁制造了这些上下文工厂?谁决定我必须使用哪一个以及为什么?为什么没有一个列表来显示不同目的需要哪一个?似乎有人不遗余力地创造了最难以理解和最神秘的方法来访问人类可能实现的资源。或者我完全误解了这里的某些内容或者缺乏大量知识。

我非常感谢有关这个主题的一些启发。

谢谢大家。

Today I was presented with this exception

Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext  [Root exception is java.lang.NullPointerException]
        at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:276)
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
        ... 23 more

I was trying to remotely access an ejb, the offending code was

Context c = new InitialContext();

Ive seen this exception before and fixed it but couldn't remember exactly how I did it. I knew that I had to set some environment variables for the initial ,context url and service provider or some such stuff.

In fact I managed to find the code I used to fix this issue last time i had it, it is as follows.

Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
env.put(Context.PROVIDER_URL, "localhost:1099");
Context c = new InitialContext(env);

My question is this how can you find out what initial context factory to use? I've written an ejb module for our database that runs on glassfish v3, at no point did I get any hint that of course I should use the com.sun.enterprise.naming.SerialInitContextFactory, I mean like its so obvious. Who makes these context factories? Who decides which one I have to use and why? Why isn't there a list showing which one is required for different purposes? It seems like someone's gone out of their way to make the most impenetrable and cryptic method of accessing a resource that is humanly possible. Or I have completely misunderstood something here or am lacking a huge chunk of knowledge.

I would very much appreciate some enlightenment on this subject.

Thank you all.

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

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

发布评论

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

评论(3

_蜘蛛 2024-09-21 21:01:43

jndi.properties 的 glassfish 设置供参考:

java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory
java.naming.factory.url.pkgs=com.sun.enterprise.naming
java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
Context.SECURITY_PRINCIPAL=user1
Context.SECURITY_CREDENTIALS=pass123
org.omg.CORBA.ORBInitialHost=localhost
org.omg.CORBA.ORBInitialPort=3700

1.) 当调用默认的 InitialContext 构造函数时,会加载 jndi.properties 文件。在我看来,这比对这些值进行硬编码、创建 Properties 对象等更可取

。2.) 这些连接参数适用于本地运行的 Glassfish。我从各种来源拼凑了这个。

3.) 我同意以下问题的精神:这些内容在精美手册中的何处指定?我在手册中看到过一些关于它们的提及,但它们并不都集中在一个位置——至少对于玻璃鱼来说是这样。 4.x glassfish 手册仅以 PDF 形式提供,这也无济于事。

glassfish settings for jndi.properties for reference:

java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory
java.naming.factory.url.pkgs=com.sun.enterprise.naming
java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
Context.SECURITY_PRINCIPAL=user1
Context.SECURITY_CREDENTIALS=pass123
org.omg.CORBA.ORBInitialHost=localhost
org.omg.CORBA.ORBInitialPort=3700

1.) The jndi.properties file is loaded when the default InitialContext constructor is invoked. To my mind, this is preferable from hard-coding these values, creating a Properties object, etc.

2.) These connection parameters work for me with Glassfish running locally. I cobbled this together from various sources.

3.) I concur with the spirit the question: where in the fine manual are these specified? I've seen some mention of them in the manual, but they're not all in one location -- at least for glassfish. It doesn't help that the 4.x glassfish manual is only available via PDF.

灯角 2024-09-21 21:01:43

通常,JNDI 在类路径中的 jndi.properties 文件中查找其配置。

也许有一个流氓 jndi.properties 文件误导了您。

有关更多详细信息,请参阅 https://glassfish.dev.java.net/ javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB

Normally JNDI looks for its configuration in a jndi.properties file in the class path.

Meybe there is a rogue jndi.properties file misdirecting you.

For more details see https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB

病毒体 2024-09-21 21:01:43

检查 jndiContext.lookup(???) 是否指定正确。

Chk if the jndiContext.lookup(???) is specified correctly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文