user3932685
user3932685

Reputation: 11

How to bypass default aries jndi lookup in karaf

I am trying to lookup for a connectionFactory in a code which is deployed as part of osgi bundle in servicemix (karaf)

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

The issue I am facing is -

  1. when I do a ctx.lookup("xyz") - It gives me a object of javax.naming.Reference instead of MQconnectionFactory. (The same code works perfectly fine as standalone java application)
  2. Also, ctx = new InitialContext(jndiContext) gives me an object of InitialContext with defaultInitContext as - org.apache.aries.jndi.DelegateContext. Ideally it should give me defaultInitiContext as LdapCtx (as my provider url is a Ldap server)

I have the following dependency in my 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>

and the same com.ibm dependency has been installed as part of karaf bundles.

So, therefore w.r.t abouve point 2, how can I bypass default jndi aries lookup in Karaf (org.apache.aries.jndi.DelegateContext), so that it gives me LdapContextFactory Object instead of DelegateContext. Am I missing any jars as part of mq in karaf.

Upvotes: 0

Views: 517

Answers (2)

niken
niken

Reputation: 2611

While I don't know how to bypass default jndi look up in karaf , something I myself am struggling with at the moment, trying to figure out how to get it to use an initial context factory that i need , i was able to get a MQ connection factory working by instantiating it directly via a bean in a blueprint, then you can name it and reference it from jndi as a normal service , like this:

 <bean id="wmqcf"  class="com.ibm.mq.jms.MQQueueConnectionFactory">
     <property name="hostname" value="my.host">
     ...port, channel, queue manager, etc ...
</bean>

<service interface="javax.jms.ConnectionFactory" ref="wmqcf">
    <service-properties>
       <entry key="osgi.jndi.service.name" value="jms/wmqcf">
    </service-properties>
</srevice>

This way you don't need to worry about any bridges, pools, etc. Just a quick way to get a connection factory in your application for wmq.

Upvotes: 0

Neil Bartlett
Neil Bartlett

Reputation: 23948

This is the key part of the error:

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

This says that the bundle named org.apache.qpid.jms.client cannot be resolved because it imports the package javax.jms but there is no other bundle that exports the package javax.jms. In OSGi, every import must be matched by an export of that package. Additionally there is a version constraint: you need version [1.1.0, 2.0.0), i.e at least 1.1.0 but less than 2.0.0.

I would suggest using the following bundle from Maven Central: https://search.maven.org/#artifactdetails%7Corg.jboss.spec.javax.jms%7Cjboss-jms-api_1.1_spec%7C1.0.1.Final%7Cjar.

Upvotes: 1

Related Questions