gpt4 book ai didi

java - 如何绕过 karaf 中的默认 aries jndi 查找

转载 作者:行者123 更新时间:2023-12-02 11:35:02 25 4
gpt4 key购买 nike

我正在尝试在代码中查找connectionFactory,该代码作为servicemix(karaf)中osgi bundle 的一部分部署

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);

我面临的问题是 -

  1. 当我执行 ctx.lookup("xyz") 时 - 它为我提供了 javax.naming.Reference 对象而不是 MQconnectionFactory。 (相同的代码作为独立的 java 应用程序运行得非常好)
  2. 此外, 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 bundle 的一部分安装。

因此,关于第 2 点,如何绕过 Karaf (org.apache.aries.jndi.DelegateContext) 中的默认 jndi aries 查找,以便它为我提供 LdapContextFactory 对象而不是 DelegateContext。我是否缺少任何 jars 作为 karaf 中 mq 的一部分。

最佳答案

这是错误的关键部分:

Unresolved requirements: [[org.apache.qpid.jms.client [464](R 464.8)] osgi.wiring.package; (&(osgi.wiring.package=javax.jms (version>=1.1.0)(!(version>=2.0.0)))

这表示名为 org.apache.qpid.jms.client 的包无法解析,因为它导入了包 javax.jms 但没有其他包可以解析导出包javax.jms。在 OSGi 中,每个导入都必须与该包的导出相匹配。此外,还有一个版本限制:您需要版本 [1.1.0, 2.0.0),即至少 1.1.0 但小于 2.0.0。

我建议使用 Maven Central 中的以下 bundle :https://search.maven.org/#artifactdetails%7Corg.jboss.spec.javax.jms%7Cjboss-jms-api_1.1_spec%7C1.0.1.Final%7Cjar .

关于java - 如何绕过 karaf 中的默认 aries jndi 查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49004933/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com