从托管在 WebSphere App Server 中的 Eclipse OSGI 包中访问 JNDI
托管在 WebSphere Application Server (WAS) 中的 OSGI 包中访问 JNDI 资源时遇到问题
我在使用 servlet 桥接
。创建 JNDI 初始上下文失败。我的代码是:
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, “com.ibm.websphere.naming.WsnInitialContextFactory”);
InitialContext ctx = new InitialContext(env);
失败并显示:
javax.naming.NoInitialContextException: 无法使用哈希表 {java.naming.provider.url=corbaloc:rir:/NameServiceServerRoot, java.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory, java.naming.factory.url 中指定的工厂创建 InitialContext .pkgs=com.ibm.ws.naming:com.ibm.ws.runtime:com.ibm.iscportal.jndi} [根异常是 java.lang.NullPointerException]
当我直接在 WAR 模块中运行相同的代码时(不是使用OSGI),它是成功的。因此我认为问题出在从 OSGI 内部访问 JNDI 上。
当从 OSGI 中访问 JNDI 时,我看到了一些对类加载器问题的引用...不确定这是否是我的问题,因为上面的异常没有明确与类加载相关,但也许确实如此。无论如何,如果这是问题,我不知道如何解决它!
实际上是否可以从我的 OSGI 模块中访问 WAS 中设置的 JNDI 和 JDBC 条目?
我的应用程序是一个 Eclipse RAP(丰富的 Ajax 插件),使用 Eclipse WAR 产品工具打包到 WAR 文件中,所述工具如下:
http://eclipsesource.com/blogs/2010/08/17/equinoxrap-war-deployment-an-end-to-the- pain/
到目前为止,除了 JNDI 访问之外,它工作正常。
非常感谢
大卫
I have a problem accessing JNDI resources from within an OSGI bundle, hosted in
WebSphere Application Server (WAS) using a servlet bridge.
It is failing on creating the JNDI initial context. My code is:
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
InitialContext ctx = new InitialContext(env);
This fails with:
javax.naming.NoInitialContextException:
Failed to create InitialContext using factory specified in hashtable {java.naming.provider.url=corbaloc:rir:/NameServiceServerRoot, java.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory, java.naming.factory.url.pkgs=com.ibm.ws.naming:com.ibm.ws.runtime:com.ibm.iscportal.jndi} [Root exception is java.lang.NullPointerException]
When I run the same code directly within a WAR module (not using OSGI), it is successful. I assume therefore the problem is something about accessing JNDI from within OSGI.
I have seen some references to Class Loader problems when accessing JNDI from within OSGI ... not sure if this is my problem, since the above exception does not explicitly relate to class loading, but maybe it is. Anyhow, if this is the problem, I am not sure how to fix it!
Is it in fact possible to access JNDI and JDBC entries set up within WAS, from within my OSGI module?
My application is an Eclipse RAP (Rich Ajax Plugin), packaged into a WAR file using the Eclipse WAR Product Tooling described at:
http://eclipsesource.com/blogs/2010/08/17/equinoxrap-war-deployment-an-end-to-the-pain/
This works successfully so far, apart from the JNDI access.
Many thanks
David
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,线程上下文类加载器将用于加载InitialContextFactory。这可能是(但不能保证)你的包的类加载器。您有几个选项:
两者都可以。
祝你好运。
By default the thread context classloader will be used to load the InitialContextFactory. This is probably (but no guarantee) your bundle's classloader. You have a couple of options:
Either should work.
Good luck.