You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2020/02/27 11:20:18 UTC

[camel-quarkus] 01/04: Fix incompatibilities between Quarkus and Camel MongoDB dependencies

This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch camel-master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 8b760e66892a9fa007782bc501111d3be56ece27
Author: James Netherton <ja...@gmail.com>
AuthorDate: Thu Jan 23 15:11:07 2020 +0000

    Fix incompatibilities between Quarkus and Camel MongoDB dependencies
    
    fixes #544, #649
---
 .../mongodb/deployment/MongoDbProcessor.java       |  12 +-
 extensions/mongodb/runtime/pom.xml                 |   4 +-
 .../component/mongodb/CamelMongoClient.java        | 124 ---------------------
 .../mongodb/CamelMongoClientRecorder.java          |  29 -----
 .../graal/SubstituteMongoClientOptions.java        |  43 -------
 .../component/mongodb/it/MongoDbResource.java      |  20 ++--
 .../component/mongodb/it/MongoDbTestResource.java  |   4 +-
 pom.xml                                            |   8 ++
 poms/bom/pom.xml                                   |  25 +++++
 9 files changed, 51 insertions(+), 218 deletions(-)

diff --git a/extensions/mongodb/deployment/src/main/java/org/apache/camel/quarkus/component/mongodb/deployment/MongoDbProcessor.java b/extensions/mongodb/deployment/src/main/java/org/apache/camel/quarkus/component/mongodb/deployment/MongoDbProcessor.java
index 00abff7..55051fb 100644
--- a/extensions/mongodb/deployment/src/main/java/org/apache/camel/quarkus/component/mongodb/deployment/MongoDbProcessor.java
+++ b/extensions/mongodb/deployment/src/main/java/org/apache/camel/quarkus/component/mongodb/deployment/MongoDbProcessor.java
@@ -1,3 +1,4 @@
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -20,12 +21,9 @@ import java.util.List;
 
 import io.quarkus.deployment.annotations.BuildProducer;
 import io.quarkus.deployment.annotations.BuildStep;
-import io.quarkus.deployment.annotations.ExecutionTime;
-import io.quarkus.deployment.annotations.Record;
 import io.quarkus.deployment.builditem.FeatureBuildItem;
 import io.quarkus.mongodb.deployment.MongoClientBuildItem;
 import io.quarkus.mongodb.runtime.MongoClientRecorder;
-import org.apache.camel.quarkus.component.mongodb.CamelMongoClientRecorder;
 import org.apache.camel.quarkus.core.deployment.CamelRuntimeBeanBuildItem;
 
 class MongoDbProcessor {
@@ -38,11 +36,9 @@ class MongoDbProcessor {
     }
 
     @BuildStep
-    @Record(ExecutionTime.RUNTIME_INIT)
     void registerCamelMongoClientProducer(
             List<MongoClientBuildItem> mongoClients,
-            BuildProducer<CamelRuntimeBeanBuildItem> runtimeBeans,
-            CamelMongoClientRecorder recorder) {
+            BuildProducer<CamelRuntimeBeanBuildItem> runtimeBeans) {
 
         for (MongoClientBuildItem mongoClient : mongoClients) {
             // If there is a default mongo client instance, then bind it to the camel registry
@@ -51,8 +47,8 @@ class MongoDbProcessor {
                 runtimeBeans.produce(
                         new CamelRuntimeBeanBuildItem(
                                 "camelMongoClient",
-                                "com.mongodb.MongoClient",
-                                recorder.createCamelMongoClient(mongoClients.get(0).getClient())));
+                                "com.mongodb.client.MongoClient",
+                                mongoClients.get(0).getClient()));
             }
         }
     }
diff --git a/extensions/mongodb/runtime/pom.xml b/extensions/mongodb/runtime/pom.xml
index 8cf892f..2517e80 100644
--- a/extensions/mongodb/runtime/pom.xml
+++ b/extensions/mongodb/runtime/pom.xml
@@ -63,8 +63,8 @@
             <artifactId>mongodb-driver-legacy</artifactId>
         </dependency>
         <dependency>
-            <groupId>org.graalvm.nativeimage</groupId>
-            <artifactId>svm</artifactId>
+            <groupId>org.mongodb</groupId>
+            <artifactId>mongodb-crypt</artifactId>
         </dependency>
     </dependencies>
 
diff --git a/extensions/mongodb/runtime/src/main/java/org/apache/camel/quarkus/component/mongodb/CamelMongoClient.java b/extensions/mongodb/runtime/src/main/java/org/apache/camel/quarkus/component/mongodb/CamelMongoClient.java
deleted file mode 100644
index a2f515f..0000000
--- a/extensions/mongodb/runtime/src/main/java/org/apache/camel/quarkus/component/mongodb/CamelMongoClient.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.quarkus.component.mongodb;
-
-import java.util.List;
-
-import com.mongodb.ClientSessionOptions;
-import com.mongodb.client.ChangeStreamIterable;
-import com.mongodb.client.ClientSession;
-import com.mongodb.client.ListDatabasesIterable;
-import com.mongodb.client.MongoClient;
-import com.mongodb.client.MongoDatabase;
-import com.mongodb.client.MongoIterable;
-import org.bson.Document;
-import org.bson.conversions.Bson;
-
-/**
- * Bridges Mongo client types {@link com.mongodb.MongoClient} and {@link com.mongodb.client.MongoClient} used by the
- * Quarkus Mongo extension and the Camel MongoDB component, so that it can be looked up and used via the
- * connectionBean URI endpoint path parameter
- */
-public final class CamelMongoClient extends com.mongodb.MongoClient {
-
-    private final MongoClient delegate;
-
-    public CamelMongoClient(MongoClient delegate) {
-        this.delegate = delegate;
-    }
-
-    @Override
-    public MongoDatabase getDatabase(String databaseName) {
-        return delegate.getDatabase(databaseName);
-    }
-
-    @Override
-    public ClientSession startSession() {
-        return delegate.startSession();
-    }
-
-    @Override
-    public ClientSession startSession(ClientSessionOptions options) {
-        return delegate.startSession(options);
-    }
-
-    @Override
-    public void close() {
-        delegate.close();
-    }
-
-    @Override
-    public MongoIterable<String> listDatabaseNames() {
-        return delegate.listDatabaseNames();
-    }
-
-    @Override
-    public ListDatabasesIterable<Document> listDatabases(ClientSession clientSession) {
-        return delegate.listDatabases(clientSession);
-    }
-
-    @Override
-    public <T> ListDatabasesIterable<T> listDatabases(ClientSession clientSession, Class<T> clazz) {
-        return delegate.listDatabases(clientSession, clazz);
-    }
-
-    @Override
-    public <T> ListDatabasesIterable<T> listDatabases(Class<T> clazz) {
-        return delegate.listDatabases(clazz);
-    }
-
-    @Override
-    public ChangeStreamIterable<Document> watch() {
-        return delegate.watch();
-    }
-
-    @Override
-    public ChangeStreamIterable<Document> watch(List<? extends Bson> pipeline) {
-        return delegate.watch(pipeline);
-    }
-
-    @Override
-    public ChangeStreamIterable<Document> watch(ClientSession clientSession) {
-        return delegate.watch(clientSession);
-    }
-
-    @Override
-    public ChangeStreamIterable<Document> watch(ClientSession clientSession, List<? extends Bson> pipeline) {
-        return delegate.watch(clientSession, pipeline);
-    }
-
-    @Override
-    public <TResult> ChangeStreamIterable<TResult> watch(Class<TResult> resultClass) {
-        return delegate.watch(resultClass);
-    }
-
-    @Override
-    public <TResult> ChangeStreamIterable<TResult> watch(List<? extends Bson> pipeline, Class<TResult> resultClass) {
-        return delegate.watch(pipeline, resultClass);
-    }
-
-    @Override
-    public <TResult> ChangeStreamIterable<TResult> watch(ClientSession clientSession, Class<TResult> resultClass) {
-        return delegate.watch(clientSession, resultClass);
-    }
-
-    @Override
-    public <TResult> ChangeStreamIterable<TResult> watch(ClientSession clientSession, List<? extends Bson> pipeline,
-            Class<TResult> resultClass) {
-        return delegate.watch(clientSession, pipeline, resultClass);
-    }
-}
diff --git a/extensions/mongodb/runtime/src/main/java/org/apache/camel/quarkus/component/mongodb/CamelMongoClientRecorder.java b/extensions/mongodb/runtime/src/main/java/org/apache/camel/quarkus/component/mongodb/CamelMongoClientRecorder.java
deleted file mode 100644
index 371f72a..0000000
--- a/extensions/mongodb/runtime/src/main/java/org/apache/camel/quarkus/component/mongodb/CamelMongoClientRecorder.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.quarkus.component.mongodb;
-
-import com.mongodb.client.MongoClient;
-import io.quarkus.runtime.RuntimeValue;
-import io.quarkus.runtime.annotations.Recorder;
-
-@Recorder
-public class CamelMongoClientRecorder {
-
-    public RuntimeValue<CamelMongoClient> createCamelMongoClient(RuntimeValue<MongoClient> client) {
-        return new RuntimeValue<>(new CamelMongoClient(client.getValue()));
-    }
-}
diff --git a/extensions/mongodb/runtime/src/main/java/org/apache/camel/quarkus/component/mongodb/graal/SubstituteMongoClientOptions.java b/extensions/mongodb/runtime/src/main/java/org/apache/camel/quarkus/component/mongodb/graal/SubstituteMongoClientOptions.java
deleted file mode 100644
index fbbc855..0000000
--- a/extensions/mongodb/runtime/src/main/java/org/apache/camel/quarkus/component/mongodb/graal/SubstituteMongoClientOptions.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.quarkus.component.mongodb.graal;
-
-import javax.net.SocketFactory;
-
-import com.mongodb.MongoClientOptions;
-import com.oracle.svm.core.annotate.Alias;
-import com.oracle.svm.core.annotate.Substitute;
-import com.oracle.svm.core.annotate.TargetClass;
-
-@TargetClass(MongoClientOptions.class)
-final class SubstituteMongoClientOptions {
-
-    @Alias
-    private SocketFactory socketFactory;
-
-    @Alias
-    private static SocketFactory DEFAULT_SOCKET_FACTORY;
-
-    @Substitute
-    public SocketFactory getSocketFactory() {
-        if (this.socketFactory != null) {
-            return this.socketFactory;
-        } else {
-            return DEFAULT_SOCKET_FACTORY;
-        }
-    }
-}
diff --git a/integration-tests/mongodb/src/main/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbResource.java b/integration-tests/mongodb/src/main/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbResource.java
index dbde877..4e11a93 100644
--- a/integration-tests/mongodb/src/main/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbResource.java
+++ b/integration-tests/mongodb/src/main/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbResource.java
@@ -19,9 +19,9 @@ package org.apache.camel.quarkus.component.mongodb.it;
 import java.net.URI;
 import java.net.URISyntaxException;
 
+import javax.annotation.PostConstruct;
 import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
-import javax.inject.Named;
 import javax.json.Json;
 import javax.json.JsonArray;
 import javax.json.JsonArrayBuilder;
@@ -35,7 +35,7 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
-import com.mongodb.MongoClient;
+import com.mongodb.client.MongoClient;
 import com.mongodb.client.MongoCursor;
 import com.mongodb.client.MongoIterable;
 import org.apache.camel.ProducerTemplate;
@@ -47,6 +47,14 @@ public class MongoDbResource {
     @Inject
     ProducerTemplate producerTemplate;
 
+    @Inject
+    MongoClient client;
+
+    @PostConstruct
+    public void init() {
+        producerTemplate.getCamelContext().getRegistry().bind("camelMongoClient", client);
+    }
+
     @POST
     @Path("/collection/{collectionName}")
     @Consumes(MediaType.APPLICATION_JSON)
@@ -84,12 +92,4 @@ public class MongoDbResource {
 
         return arrayBuilder.build();
     }
-
-    @javax.enterprise.inject.Produces
-    @Named("camelMongoClient")
-    public MongoClient camelMongoClient() {
-        return new MongoClient(
-                System.getProperty("camel.mongodb.test-host"),
-                Integer.getInteger("camel.mongodb.test-port"));
-    }
 }
diff --git a/integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbTestResource.java b/integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbTestResource.java
index b7a915f..cbbf45d 100644
--- a/integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbTestResource.java
+++ b/integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbTestResource.java
@@ -46,8 +46,8 @@ public class MongoDbTestResource implements ContainerResourceLifecycleManager {
             container.start();
 
             return CollectionHelper.mapOf(
-                    "camel.mongodb.test-port", container.getMappedPort(MONGODB_PORT).toString(),
-                    "camel.mongodb.test-host", container.getContainerIpAddress());
+                    "quarkus.mongodb.hosts",
+                    container.getContainerIpAddress() + ":" + container.getMappedPort(MONGODB_PORT).toString());
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
diff --git a/pom.xml b/pom.xml
index 5a6a812..fca3dcc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -58,6 +58,14 @@
         <consul-client.version>1.3.3</consul-client.version>
         <stax2.version>4.2</stax2.version>
 
+        <!-- These mongodb version properties should align with the Mongo client version used in Camel
+            TODO: Remove when Quarkus has upgraded its MongoDB client dependencies
+                - https://github.com/quarkusio/quarkus/issues/6418
+                - https://github.com/quarkusio/quarkus/pull/6347
+        -->
+        <mongodb.version>3.12.1</mongodb.version>
+        <mongodb-crypt.version>1.0.1</mongodb-crypt.version>
+
         <maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
         <maven.compiler.target>1.8</maven.compiler.target>
         <maven.compiler.source>1.8</maven.compiler.source>
diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml
index de617c9..a1948c1 100644
--- a/poms/bom/pom.xml
+++ b/poms/bom/pom.xml
@@ -1105,6 +1105,31 @@
                 <version>${kotlin.version}</version>
             </dependency>
             <dependency>
+                <groupId>org.mongodb</groupId>
+                <artifactId>mongodb-crypt</artifactId>
+                <version>${mongodb-crypt.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.mongodb</groupId>
+                <artifactId>mongodb-driver-async</artifactId>
+                <version>${mongodb.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.mongodb</groupId>
+                <artifactId>mongodb-driver-core</artifactId>
+                <version>${mongodb.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.mongodb</groupId>
+                <artifactId>mongodb-driver-legacy</artifactId>
+                <version>${mongodb.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.mongodb</groupId>
+                <artifactId>mongodb-driver-sync</artifactId>
+                <version>${mongodb.version}</version>
+            </dependency>
+            <dependency>
                 <groupId>org.springframework</groupId>
                 <artifactId>spring-core</artifactId>
                 <version>${spring.version}</version>