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 bca04a493eee9e9f922a19541cd9fdb7bfe69930 Author: James Netherton <jamesnether...@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 | 11 +- extensions/mongodb/runtime/pom.xml | 4 +- .../component/mongodb/CamelMongoClient.java | 124 --------------------- .../mongodb/CamelMongoClientRecorder.java | 29 ----- .../graal/SubstituteMongoClientOptions.java | 43 ------- .../component/mongodb/it/MongoDbResource.java | 10 -- .../component/mongodb/it/MongoDbTestResource.java | 4 +- pom.xml | 8 ++ poms/bom/pom.xml | 25 +++++ 9 files changed, 39 insertions(+), 219 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 f14c0c9..8f5a378 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 @@ -18,11 +18,8 @@ package org.apache.camel.quarkus.component.mongodb.deployment; import com.mongodb.MongoClient; 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 org.apache.camel.quarkus.component.mongodb.CamelMongoClientRecorder; import org.apache.camel.quarkus.core.deployment.CamelRuntimeBeanBuildItem; class MongoDbProcessor { @@ -35,11 +32,7 @@ class MongoDbProcessor { } @BuildStep - @Record(ExecutionTime.RUNTIME_INIT) - CamelRuntimeBeanBuildItem registerCamelMongoClientProducer(MongoClientBuildItem mongoClientBuildItem, - CamelMongoClientRecorder recorder) { - - return new CamelRuntimeBeanBuildItem("camelMongoClient", MongoClient.class.getName(), - recorder.createCamelMongoClient(mongoClientBuildItem.getClient())); + CamelRuntimeBeanBuildItem registerCamelMongoClientProducer(MongoClientBuildItem mongoClientBuildItem) { + return new CamelRuntimeBeanBuildItem("camelMongoClient", MongoClient.class.getName(), mongoClientBuildItem.getClient()); } } diff --git a/extensions/mongodb/runtime/pom.xml b/extensions/mongodb/runtime/pom.xml index 1216122..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>com.oracle.substratevm</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..c859969 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 @@ -21,7 +21,6 @@ import java.net.URISyntaxException; 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 +34,6 @@ 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.MongoCursor; import com.mongodb.client.MongoIterable; import org.apache.camel.ProducerTemplate; @@ -84,12 +82,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 7a4d214..ab3a66f 100644 --- a/pom.xml +++ b/pom.xml @@ -54,6 +54,14 @@ <retrofit.version>2.5.0</retrofit.version> <consul-client.version>1.3.3</consul-client.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 02f9fb0..d009459 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -997,6 +997,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>