【发布时间】:2018-08-06 21:06:06
【问题描述】:
我正在尝试在作为 osgi 包的一部分部署在 servicemix (karaf) 中的代码中查找 connectionFactory
final Hashtable<String, Object> jndiContext = new Hashtable<String, Object>();
jndiContext.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
jndiContext.put(Context.SECURITY_AUTHENTICATION, "none");
jndiContext.put(Context.PROVIDER_URL, pJndiLDAPserver);
ctx = new InitialContext(jndiContext);
ConnectionFactory lResult = (ConnectionFactory) ctx.lookup(pJndiCFname);
我面临的问题是-
- 当我执行 ctx.lookup("xyz") 时 - 它给了我一个 javax.naming.Reference 对象,而不是 MQconnectionFactory。 (同样的代码可以作为独立的 Java 应用程序完美运行)
- 另外,ctx = new InitialContext(jndiContext) 给了我一个 InitialContext 对象,其中 defaultInitContext 为 - org.apache.aries.jndi.DelegateContext。理想情况下,它应该给我 defaultInitiContext 作为 LdapCtx(因为我的提供程序 url 是一个 Ldap 服务器)
我的 pom.xml 中有以下依赖项 -
<dependency>
<groupId>javax.jms</groupId>
<artifactId>javax.jms-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.ibm.mq.osgi</groupId>
<artifactId>java</artifactId>
<version>9.0.0.0</version>
</dependency>
<dependency>
<groupId>com.ibm.msg.client.osgi.jms</groupId>
<artifactId>prereq</artifactId>
<version>9.0.0.0</version>
</dependency>
<dependency>
<groupId>com.ibm.msg.client.osgi</groupId>
<artifactId>jms</artifactId>
<version>9.0.0.0</version>
</dependency>
<dependency>
<groupId>com.ibm.msg.client.osgi.commonservices</groupId>
<artifactId>j2se</artifactId>
<version>9.0.0.0</version>
</dependency>
<dependency>
<groupId>com.ibm.mq.osgi</groupId>
<artifactId>allclient</artifactId>
<version>9.0.0.0</version>
</dependency>
<dependency>
<groupId>com.ibm.mq.osgi</groupId>
<artifactId>allclientprereqs</artifactId>
<version>9.0.0.0</version>
</dependency>
<dependency>
<groupId>com.ibm.msg.client.osgi</groupId>
<artifactId>nls</artifactId>
<version>9.0.0.0</version>
</dependency>
<dependency>
<groupId>com.ibm.msg.client.osgi.wmq</groupId>
<artifactId>nls</artifactId>
<version>9.0.0.0</version>
</dependency>
<dependency>
<groupId>com.ibm.msg.client.osgi.wmq</groupId>
<artifactId>prereq</artifactId>
<version>9.0.0.0</version>
</dependency>
<dependency>
<groupId>com.ibm.msg.client.osgi</groupId>
<artifactId>wmq</artifactId>
<version>9.0.0.0</version>
</dependency>
<dependency>
<groupId>com.csg.npms.pilatus</groupId>
<artifactId>pilatus-common</artifactId>
<version>0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-api</artifactId>
<version>1.8.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0-m09</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.1.4</version>
<scope>provided</scope>
</dependency>
并且相同的 com.ibm 依赖项已作为 karaf 包的一部分安装。
因此,关于第 2 点,我如何绕过 Karaf (org.apache.aries.jndi.DelegateContext) 中的默认 jndi aries 查找,以便它给我 LdapContextFactory 对象而不是 DelegateContext。作为 karaf 中 mq 的一部分,我是否缺少任何罐子。
【问题讨论】:
-
您在 karaf 中安装了哪些功能?该错误表明您尚未安装 jms api。通常,当您安装 ActiveMQ 等 jms 客户端时会安装此 API。
-
@rollstuhlfahrer ..您将 Q 推为“需要编辑”...您能否帮助 OP 指出正确的方向缺少什么或自己更改? (ps:不需要回复我因为/我什至不是这个话题的初学者)。
-
@ChristianSchneider - 我已经在 karaf 中安装了 jndi 和 jms 功能。主要问题是 osgi 包无法在其路径上找到 ibm mq 和 javax 类。
-
IBM MQ 可能有点难以开始工作。我最后一次尝试它花了我相当大的努力。我读到 IBM 在某个时候开始生产捆绑软件 .. 所以我希望现在更容易,但我没有更新的经验。
标签: java osgi ibm-mq apache-karaf apache-servicemix