Mongo Driver (mongo-driver-sync) with OSGi support: Unable to resolve

Hi there

I am new here with a specific question about OSGi support of mongo db driver. I posted the same question on Stackobverflow (Cannot use MongoDB driver "mongodb-driver-sync" in OSGi Project: Unable to resolve - Stack Overflow) but I hope to get better support here.

The way I see it, OSGi isn’t very popular anymore, at least judging by the posts and documentation on the web. Nevertheless, Apache Karaf and OSGi is exactly the right tool for our purposes.

Our application uses Apache Camel and MongoDB.

First we successfully used a quite old version of “mongo-java-driver” (3.12.11): By adding this dependency to the modules pom.xml and to the osgi feature repository we were able to start our application and connect to MongoDB:

pom.xml (maven module1)

        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
            <version>3.12.11</version>
        </dependency>

feature.xml:

    <repository>mvn:org.apache.camel.karaf/apache-camel/3.18.4/xml/features</repository>

    <feature name="module1" description="An OSGi module" version="1.0.1-SNAPSHOT">
        <feature>scr</feature>
        <feature prerequisite="true">aries-blueprint</feature>
        <feature>camel-core</feature>
        <feature>camel-blueprint</feature>
        <feature>camel-cxf</feature>
        <feature>camel-xslt-saxon</feature>
        <feature>camel-jetty</feature>
        <feature>camel-rabbitmq</feature>
        <feature>camel-openapi-java</feature>
        <feature>camel-jackson</feature>
        <capability>osgi.service;objectClass=org.apache.aries.blueprint.NamespaceHandler;osgi.service.blueprint.namespace=http://camel.apache.org/schema/blueprint;effective:=active;
        </capability>

        <bundle dependency="true">mvn:org.mongodb/mongo-java-driver/3.12.11</bundle>

        <bundle>mvn:my.own.project/module1/1.0.1-SNAPSHOT</bundle>
    </feature>

But that driver is legacy, quite old and missing important features, so we would like to use a modern driver, namely mongodb-driver-sync (version 4.8.2).

We replaced the previous driver with “mongodb-driver-sync”:

pom.xml (maven module1)

        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongodb-driver-sync</artifactId>
            <version>4.8.2</version>
        </dependency>

feature.xml:

    <repository>mvn:org.apache.camel.karaf/apache-camel/3.18.4/xml/features</repository>

    <feature name="module1" description="An OSGI module" version="1.0.1-SNAPSHOT">
        <feature>scr</feature>
        <feature prerequisite="true">aries-blueprint</feature>
        <feature>camel-core</feature>
        ...
        <!-- <bundle dependency="true">mvn:org.mongodb/mongo-java-driver/3.12.11</bundle>-->

        <bundle dependency="true">mvn:org.mongodb/mongodb-driver-sync/4.8.1</bundle>

        <bundle>mvn:my.own.project/module1/1.0.1-SNAPSHOT</bundle>
    </feature>

This fails when starting the feature in Karaf:

Error executing command: Unable to resolve root: missing requirement [root] osgi.identity;
osgi.identity=mesh; type=karaf.feature; version="[1.0.1.SNAPSHOT,1.0.1.SNAPSHOT]";
filter:="(&(osgi.identity=mesh)(type=karaf.feature)(version>=1.0.1.SNAPSHOT)(version<=1.0.1.SNAPSHOT))" 
[caused by: Unable to resolve mesh/1.0.1.SNAPSHOT: missing requirement [mesh/1.0.1.SNAPSHOT] osgi.identity; osgi.identity=mesh-vms-tso01; type=karaf.feature 
[caused by: Unable to resolve mesh-vms-tso01/1.0.1.SNAPSHOT: missing requirement [mesh-vms-tso01/1.0.1.SNAPSHOT] osgi.identity; osgi.identity=mesh-vms-tso01; type=osgi.bundle; version="[1.0.1.SNAPSHOT,1.0.1.SNAPSHOT]"; resolution:=mandatory 
[caused by: Unable to resolve mesh-vms-tso01/1.0.1.SNAPSHOT: missing requirement [mesh-vms-tso01/1.0.1.SNAPSHOT] osgi.wiring.package; filter:="(&(osgi.wiring.package=com.btc.mesh.core.camel)(version>=1.0.0)(!(version>=2.0.0)))" 
[caused by: Unable to resolve mesh-core/1.0.1.SNAPSHOT: 
missing requirement [mesh-core/1.0.1.SNAPSHOT] osgi.wiring.package; filter:="(&(osgi.wiring.package=com.mongodb)(version>=4.8.0)(!(version>=5.0.0)))"]]]]

I also tried version 4.1.0 because an older documentation mentioned that it is a valid OSGI bundle:

The mongodb-driver-sync artifact is a valid OSGi bundle whose symbolic
name is org.mongodb.driver-sync."

But we also had no luck. Does the symbolic name help in any way?

After version 4.3.x the documentation moved from mongodb.github.io to www.mongodb.com and the reference to OSGi has been removed. The MANIFEST file of all mentioned drivers looks quite similar including the bundle information. So, AFAIK , OSGi should work. Very confusing.

So, we need your help

  • Has anyone more information about a modern MongoDB driver which is ready for OSGI?
  • Or maybe we are doing something wrong when integrating the driver into our OSGI module?

Thanx

Hi @Bert_Speckels

We’ve had occasional bug reports over the years about the driver not working properly in an OSGi environment, but they all have been related to missing or mis-configured dependencies in the Import-Package entry in the manifest. The most recent report is https://jira.mongodb.org/browse/JAVA-4836, which showed up in 4.8.0 and was fixed in 4.8.2. In all cases I can recall, the reporter of the issue was able to successfully use the driver in OSGi after the fix, so I have some confidence that the driver does work with OSGi, in particular 4.8.2.

Nothing in the error message that you posted looks familiar, or at all similar to ones previously reported, so I am unsure how to proceed.

First of all @Jeffrey_Yemin: Thank your for your quick reply and for confirming that version 4.8.2 should run successfully with OSGi. I am very relieved.

Actually I found a solution myself this afternoon but encountered another error concerning com.amazonaws.auth. Apparently that was the error you are describing. I had tested with version 4.8.1!

I found the solution somewhere in a note and it works well with version 4.8.2: If integrating the drivers JAR file directly into a project, then you should also add the JARs of bson and mondodb.driver.core. Apparently this is also necessary when defining the dependency for OSGi:

<feature name="sample version="1.0.1-SNAPSHOT">
    ...
   <bundle dependency="true">mvn:org.mongodb/bson/4.8.2</bundle>
   <bundle dependency="true">mvn:org.mongodb/mongodb-driver-core/4.8.2</bundle>
   <bundle dependency="true">mvn:org.mongodb/mongodb-driver-sync/4.8.2</bundle>
</feature>

I’m wondering if this is really the right way. Maybe someone can confirm that for me.

Of course it would be great if everyone could find the solution in the documentation. Maybe that can be integrated?!

Overall OSGi doesn’t seem to be very common anymore, especially in documentation. IMHO, OSGi is still a wonderful technology that represents a great compromise between microservices and monoliths!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.