0
votes

I am trying to implement a JavaScript Adapter that uses the mongodb java driver. I've downloaded the mongodb driver.

The dependency in my pom.xml looks like this:

    <dependency>
     <groupId>org.mongodb</groupId>
     <artifactId>mongo-java-driver</artifactId>
     <version>3.2.2</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/lib/mongo-java-driver-3.2.2.jar</systemPath>
   </dependency>

In the implementation, I am trying to instantiate MongoClient:

    var mongoClient = new com.mongodb.MongoClient();

If I try to call the adapter, I am getting an error:

25.05.16 14:13:45:301 MESZ] 0000bb8c com.ibm.mfp.server.js.adapter.internal.JavascriptManagerImpl E FWLST0904E: Exception was thrown while invoking procedure: getFeed in adapter: MongoAdapter org.mozilla.javascript.EcmaError: TypeError: [JavaPackage com.mongodb.MongoClient] is not a function, it is object. (MongoAdapter-impl.js#20)

Seems like, the jar is not loaded properly, even though the adapter builds without errors.

I've uploaded a small sample adapter project here.

1

1 Answers

1
votes

I took the sample adapter and built & deployed it to MobileFirst Server 8.0 beta. I then tested it using Swagger from the MobileFirst Console -> the adapter -> Resources. Running the getFeed procedure successfully worked.

I see that the MongoDB .jar that you're using was built using Java 8. It could be that locally you are running Java 7 and this may account for the failure.

Verify that you are using Java 8 and try again.