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 2023/01/17 11:03:52 UTC
[camel-quarkus] branch main updated: Ref #4392: Kotlin DSL native support
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new 71fc9a815a Ref #4392: Kotlin DSL native support
71fc9a815a is described below
commit 71fc9a815a7ebb974e419edca950d7910605fba2
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Thu Jan 12 19:57:35 2023 +0100
Ref #4392: Kotlin DSL native support
---
docs/modules/ROOT/examples/others/kotlin-dsl.yml | 6 +-
.../pages/reference/extensions/kotlin-dsl.adoc | 14 +-
extensions-jvm/pom.xml | 1 -
.../kotlin-dsl/deployment/pom.xml | 0
.../dsl/kotlin/deployment/KotlinDslProcessor.java | 227 +++++++++++++++++++++
.../deployment/KotlinGeneratedClassBuildItem.java | 27 +--
{extensions-jvm => extensions}/kotlin-dsl/pom.xml | 2 +-
.../kotlin-dsl/runtime/pom.xml | 13 +-
.../quarkus/dsl/kotlin/runtime/Configurer.java | 17 +-
.../dsl/kotlin/runtime/KotlinDslRecorder.java | 50 +++++
.../graal/SubstituteKotlinRoutesBuilderLoader.java | 20 +-
.../main/resources/META-INF/quarkus-extension.yaml | 3 +-
extensions/pom.xml | 1 +
.../quarkus/dsl/kotlin/KotlinDslResource.java | 60 ------
.../camel/quarkus/dsl/kotlin/KotlinDslTest.java | 49 -----
integration-tests-jvm/pom.xml | 1 -
.../kotlin-dsl/pom.xml | 95 +++++++++
.../quarkus/dsl/kotlin/KotlinDslResource.java | 101 +++++++++
.../src/main/resources/application.properties | 3 +-
.../src/main/resources/routes/my-routes.kts | 4 +-
.../routes-with-components-configuration.kts | 36 ++--
.../routes-with-dataformats-configuration.kts | 24 ++-
.../resources/routes/routes-with-endpoint-dsl.kts | 10 +-
.../resources/routes/routes-with-error-handler.kts | 14 +-
.../routes/routes-with-languages-configuration.kts | 22 +-
.../src/main/resources/routes/routes-with-rest.kts | 52 +++++
.../src/main/resources/routes/routes.kts | 10 +-
.../camel/quarkus/dsl/kotlin/KotlinDslIT.java | 11 +-
.../camel/quarkus/dsl/kotlin/KotlinDslTest.java | 80 ++++++++
integration-tests/pom.xml | 1 +
tooling/scripts/test-categories.yaml | 1 +
31 files changed, 766 insertions(+), 189 deletions(-)
diff --git a/docs/modules/ROOT/examples/others/kotlin-dsl.yml b/docs/modules/ROOT/examples/others/kotlin-dsl.yml
index 0ceeb26750..032388d0ab 100644
--- a/docs/modules/ROOT/examples/others/kotlin-dsl.yml
+++ b/docs/modules/ROOT/examples/others/kotlin-dsl.yml
@@ -2,11 +2,11 @@
# This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
cqArtifactId: camel-quarkus-kotlin-dsl
cqArtifactIdBase: kotlin-dsl
-cqNativeSupported: false
-cqStatus: Preview
+cqNativeSupported: true
+cqStatus: Stable
cqDeprecated: false
cqJvmSince: 1.8.0
-cqNativeSince: n/a
+cqNativeSince: 2.16.0
cqCamelPartName: kotlin-dsl
cqCamelPartTitle: Kotlin DSL
cqCamelPartDescription: Camel DSL with Kotlin
diff --git a/docs/modules/ROOT/pages/reference/extensions/kotlin-dsl.adoc b/docs/modules/ROOT/pages/reference/extensions/kotlin-dsl.adoc
index 37283c9d1d..4b940a1441 100644
--- a/docs/modules/ROOT/pages/reference/extensions/kotlin-dsl.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/kotlin-dsl.adoc
@@ -4,17 +4,17 @@
= Kotlin DSL
:linkattrs:
:cq-artifact-id: camel-quarkus-kotlin-dsl
-:cq-native-supported: false
-:cq-status: Preview
-:cq-status-deprecation: Preview
+:cq-native-supported: true
+:cq-status: Stable
+:cq-status-deprecation: Stable
:cq-description: Support for parsing Kotlin route definitions at runtime
:cq-deprecated: false
:cq-jvm-since: 1.8.0
-:cq-native-since: n/a
+:cq-native-since: 2.16.0
ifeval::[{doc-show-badges} == true]
[.badges]
-[.badge-key]##JVM since##[.badge-supported]##1.8.0## [.badge-key]##Native##[.badge-unsupported]##unsupported##
+[.badge-key]##JVM since##[.badge-supported]##1.8.0## [.badge-key]##Native since##[.badge-supported]##2.16.0##
endif::[]
Support for parsing Kotlin route definitions at runtime
@@ -29,6 +29,10 @@ Please refer to the above link for usage and configuration details.
[id="extensions-kotlin-dsl-maven-coordinates"]
== Maven coordinates
+https://{link-quarkus-code-generator}/?extension-search=camel-quarkus-kotlin-dsl[Create a new project with this extension on {link-quarkus-code-generator}, window="_blank"]
+
+Or add the coordinates to your existing project:
+
[source,xml]
----
<dependency>
diff --git a/extensions-jvm/pom.xml b/extensions-jvm/pom.xml
index 01ff26c757..edf23af344 100644
--- a/extensions-jvm/pom.xml
+++ b/extensions-jvm/pom.xml
@@ -87,7 +87,6 @@
<module>json-patch</module>
<module>jsonapi</module>
<module>jt400</module>
- <module>kotlin-dsl</module>
<module>ldap</module>
<module>ldif</module>
<module>lucene</module>
diff --git a/extensions-jvm/kotlin-dsl/deployment/pom.xml b/extensions/kotlin-dsl/deployment/pom.xml
similarity index 100%
rename from extensions-jvm/kotlin-dsl/deployment/pom.xml
rename to extensions/kotlin-dsl/deployment/pom.xml
diff --git a/extensions/kotlin-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/kotlin/deployment/KotlinDslProcessor.java b/extensions/kotlin-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/kotlin/deployment/KotlinDslProcessor.java
new file mode 100644
index 0000000000..6a9e71d172
--- /dev/null
+++ b/extensions/kotlin-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/kotlin/deployment/KotlinDslProcessor.java
@@ -0,0 +1,227 @@
+/*
+ * 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.dsl.kotlin.deployment;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+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.deployment.builditem.GeneratedClassBuildItem;
+import io.quarkus.deployment.builditem.GeneratedResourceBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+import io.quarkus.deployment.dev.CompilationProvider;
+import io.quarkus.deployment.pkg.builditem.BuildSystemTargetBuildItem;
+import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
+import io.quarkus.deployment.pkg.steps.NativeBuild;
+import io.quarkus.kotlin.deployment.KotlinCompilationProvider;
+import io.quarkus.maven.dependency.ResolvedDependency;
+import io.quarkus.paths.PathCollection;
+import io.quarkus.runtime.RuntimeValue;
+import org.apache.camel.CamelContext;
+import org.apache.camel.dsl.kotlin.KotlinConstantsKt;
+import org.apache.camel.quarkus.core.deployment.main.CamelMainHelper;
+import org.apache.camel.quarkus.core.deployment.spi.CamelContextBuildItem;
+import org.apache.camel.quarkus.dsl.kotlin.runtime.Configurer;
+import org.apache.camel.quarkus.dsl.kotlin.runtime.KotlinDslRecorder;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.IOHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+class KotlinDslProcessor {
+
+ private static final Logger LOG = LoggerFactory.getLogger(KotlinDslProcessor.class);
+ private static final String PACKAGE_NAME = "org.apache.camel.quarkus.dsl.kotlin.generated";
+ private static final Pattern IMPORT_PATTERN = Pattern.compile("import .*");
+ private static final String FILE_FORMAT = "package %s\n" +
+ "%s\n" +
+ "class %s(builder: org.apache.camel.builder.endpoint.EndpointRouteBuilder) :\n" +
+ " %s(builder) { \n" +
+ " override fun configure() { \n" +
+ " %s\n" +
+ " }\n" +
+ "}";
+ private static final String FEATURE = "camel-kotlin-dsl";
+ public static final String CLASS_EXT = ".class";
+
+ @BuildStep
+ FeatureBuildItem feature() {
+ return new FeatureBuildItem(FEATURE);
+ }
+
+ @BuildStep(onlyIf = NativeBuild.class)
+ void compileScriptsAOT(BuildProducer<GeneratedClassBuildItem> generatedClass,
+ BuildProducer<GeneratedResourceBuildItem> generatedResource,
+ BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
+ BuildProducer<KotlinGeneratedClassBuildItem> generatedKotlinClass,
+ BuildSystemTargetBuildItem buildSystemTargetBuildItem,
+ CurateOutcomeBuildItem curateOutcomeBuildItem) throws Exception {
+ LOG.debug("Loading .kts resources");
+ final Path projectDir = Paths.get(".").toAbsolutePath().normalize();
+ Path outputDirectory = buildSystemTargetBuildItem.getOutputDirectory();
+ final Path generatedSourceDir = outputDirectory.resolve("kotlin-dsl/generated-sources");
+ Files.createDirectories(generatedSourceDir);
+ final Path generatedSourceHomeDir = generatedSourceDir.resolve(PACKAGE_NAME.replace('.', File.separatorChar));
+ Files.createDirectories(generatedSourceHomeDir);
+ Map<String, Resource> nameToResource = new HashMap<>();
+ Set<File> filesToCompile = new HashSet<>();
+ CamelMainHelper.forEachMatchingResource(
+ resource -> {
+ if (!resource.getLocation().endsWith(".kts")) {
+ return;
+ }
+ String name = determineName(resource);
+ try (InputStream is = resource.getInputStream()) {
+ String content = toKotlinClass(name, IOHelper.loadText(is));
+ LOG.debug("Generated Kotlin source content:\n {}", content);
+ final Path sourceFile = generatedSourceHomeDir.resolve(String.format("%s.kt", name));
+ Files.write(sourceFile, content.getBytes(StandardCharsets.UTF_8));
+ filesToCompile.add(sourceFile.toFile());
+ nameToResource.put(String.format("%s.%s", PACKAGE_NAME, name), resource);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ });
+
+ if (filesToCompile.isEmpty()) {
+ return;
+ }
+ final Path classesDir = outputDirectory.resolve("kotlin-dsl/generated-classes");
+ Files.createDirectories(classesDir);
+ CompilationProvider.Context context = new CompilationProvider.Context(
+ FEATURE,
+ curateOutcomeBuildItem.getApplicationModel().getDependencies().stream()
+ .map(ResolvedDependency::getResolvedPaths)
+ .flatMap(PathCollection::stream)
+ .map(Path::toFile)
+ .filter(f -> f.getName().endsWith(".jar"))
+ .collect(Collectors.toSet()),
+ Set.of(),
+ projectDir.toFile(),
+ generatedSourceDir.toFile(),
+ classesDir.toFile(),
+ StandardCharsets.UTF_8.name(),
+ Map.of(),
+ KotlinConstantsKt.JVM_TARGET,
+ KotlinConstantsKt.JVM_TARGET,
+ KotlinConstantsKt.JVM_TARGET,
+ List.of(),
+ List.of());
+ try (KotlinCompilationProvider compiler = new KotlinCompilationProvider()) {
+ compiler.compile(filesToCompile, context);
+ }
+
+ try (Stream<Path> classFiles = Files.walk(classesDir)) {
+ classFiles
+ .filter(Files::isRegularFile)
+ .forEach(p -> {
+ String fileName = p.getFileName().toString();
+ String relativePath = classesDir.relativize(p).toString();
+ try {
+ if (fileName.endsWith(CLASS_EXT)) {
+ String className = relativePath.replace(File.separatorChar, '.').substring(0,
+ relativePath.length() - CLASS_EXT.length());
+ generatedClass.produce(new GeneratedClassBuildItem(true, className, Files.readAllBytes(p)));
+ if (nameToResource.containsKey(className)) {
+ reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, className));
+ generatedKotlinClass
+ .produce(new KotlinGeneratedClassBuildItem(className,
+ nameToResource.get(className).getLocation()));
+ }
+ } else {
+ generatedResource.produce(new GeneratedResourceBuildItem(
+ relativePath.replace(File.separatorChar, '/'),
+ Files.readAllBytes(p)));
+ }
+ } catch (IOException e) {
+ throw new RuntimeException("Could not read " + p);
+ }
+ });
+ }
+ }
+
+ @BuildStep(onlyIf = NativeBuild.class)
+ @Record(value = ExecutionTime.STATIC_INIT)
+ void registerRoutesBuilder(List<KotlinGeneratedClassBuildItem> classes,
+ CamelContextBuildItem context,
+ KotlinDslRecorder recorder) throws Exception {
+ RuntimeValue<CamelContext> camelContext = context.getCamelContext();
+ for (KotlinGeneratedClassBuildItem clazz : classes) {
+ recorder.registerRoutesBuilder(camelContext, clazz.getName(), clazz.getLocation());
+ }
+ }
+
+ private static String determineName(Resource resource) {
+ String str = FileUtil.onlyName(resource.getLocation(), true);
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0, length = str.length(); i < length; i++) {
+ char c = str.charAt(i);
+ if ((i == 0 && Character.isJavaIdentifierStart(c)) || (i > 0 && Character.isJavaIdentifierPart(c))) {
+ sb.append(c);
+ } else {
+ sb.append((int) c);
+ }
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Convert a Kotlin script into a Kotlin class to be able to compile it.
+ *
+ * @param name the name of the Kotlin class
+ * @param contentResource the content of the Kotlin script
+ * @return the content of the corresponding Kotlin class.
+ */
+ private static String toKotlinClass(String name, String contentResource) {
+ List<String> imports = new ArrayList<>();
+ imports.add("import org.apache.camel.*");
+ imports.add("import org.apache.camel.spi.*");
+ Matcher m = IMPORT_PATTERN.matcher(contentResource);
+ int beginIndex = 0;
+ while (m.find()) {
+ imports.add(m.group());
+ beginIndex = m.end();
+ }
+ if (beginIndex > 0) {
+ contentResource = contentResource.substring(beginIndex);
+ }
+ return String.format(
+ FILE_FORMAT, PACKAGE_NAME, String.join("\n", imports), name,
+ Configurer.class.getName(), contentResource);
+ }
+}
diff --git a/extensions-jvm/kotlin-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/kotlin/deployment/KotlinDslProcessor.java b/extensions/kotlin-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/kotlin/deployment/KotlinGeneratedClassBuildItem.java
similarity index 59%
copy from extensions-jvm/kotlin-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/kotlin/deployment/KotlinDslProcessor.java
copy to extensions/kotlin-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/kotlin/deployment/KotlinGeneratedClassBuildItem.java
index 767e2645e1..a9240ba6ef 100644
--- a/extensions-jvm/kotlin-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/kotlin/deployment/KotlinDslProcessor.java
+++ b/extensions/kotlin-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/kotlin/deployment/KotlinGeneratedClassBuildItem.java
@@ -14,24 +14,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.camel.quarkus.dsl.kotlin.deployment;
-import io.quarkus.deployment.annotations.BuildStep;
-import io.quarkus.deployment.builditem.FeatureBuildItem;
-import io.quarkus.deployment.pkg.steps.NativeBuild;
+import io.quarkus.builder.item.MultiBuildItem;
+
+public final class KotlinGeneratedClassBuildItem extends MultiBuildItem {
-public class KotlinDslProcessor {
- private static final String FEATURE = "camel-kotlin-dsl";
+ final String name;
+ final String location;
+
+ public KotlinGeneratedClassBuildItem(String name, String location) {
+ this.name = name;
+ this.location = location;
+ }
- @BuildStep
- FeatureBuildItem feature() {
- return new FeatureBuildItem(FEATURE);
+ public String getName() {
+ return this.name;
}
- @BuildStep(onlyIf = NativeBuild.class)
- void nativeUnsupported() {
- throw new RuntimeException("The " + FEATURE + " extension is not supported in native mode "
- + "as loading Kotlin code at runtime is not supported on GraalVM");
+ public String getLocation() {
+ return location;
}
}
diff --git a/extensions-jvm/kotlin-dsl/pom.xml b/extensions/kotlin-dsl/pom.xml
similarity index 96%
rename from extensions-jvm/kotlin-dsl/pom.xml
rename to extensions/kotlin-dsl/pom.xml
index 6c82278189..a2cf2d4eba 100644
--- a/extensions-jvm/kotlin-dsl/pom.xml
+++ b/extensions/kotlin-dsl/pom.xml
@@ -21,7 +21,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
- <artifactId>camel-quarkus-extensions-jvm</artifactId>
+ <artifactId>camel-quarkus-extensions</artifactId>
<version>2.16.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
diff --git a/extensions-jvm/kotlin-dsl/runtime/pom.xml b/extensions/kotlin-dsl/runtime/pom.xml
similarity index 89%
rename from extensions-jvm/kotlin-dsl/runtime/pom.xml
rename to extensions/kotlin-dsl/runtime/pom.xml
index ce43424feb..fa381be603 100644
--- a/extensions-jvm/kotlin-dsl/runtime/pom.xml
+++ b/extensions/kotlin-dsl/runtime/pom.xml
@@ -32,6 +32,7 @@
<properties>
<camel.quarkus.jvmSince>1.8.0</camel.quarkus.jvmSince>
+ <camel.quarkus.nativeSince>2.16.0</camel.quarkus.nativeSince>
</properties>
<dependencies>
@@ -47,18 +48,6 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-kotlin-dsl</artifactId>
</dependency>
- <dependency>
- <groupId>org.jetbrains.kotlin</groupId>
- <artifactId>kotlin-script-util</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jetbrains.kotlin</groupId>
- <artifactId>kotlin-scripting-jvm</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jetbrains.kotlin</groupId>
- <artifactId>kotlin-scripting-jvm-host</artifactId>
- </dependency>
</dependencies>
<build>
diff --git a/integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts b/extensions/kotlin-dsl/runtime/src/main/java/org/apache/camel/quarkus/dsl/kotlin/runtime/Configurer.java
similarity index 66%
copy from integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts
copy to extensions/kotlin-dsl/runtime/src/main/java/org/apache/camel/quarkus/dsl/kotlin/runtime/Configurer.java
index 1175ccbd11..3e69e9f086 100644
--- a/integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts
+++ b/extensions/kotlin-dsl/runtime/src/main/java/org/apache/camel/quarkus/dsl/kotlin/runtime/Configurer.java
@@ -14,6 +14,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-from("direct:start")
- .id("my-kotlin-route")
- .log("Hello Kotlin !!!")
\ No newline at end of file
+package org.apache.camel.quarkus.dsl.kotlin.runtime;
+
+import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
+import org.apache.camel.dsl.kotlin.KotlinDSL;
+import org.jetbrains.annotations.NotNull;
+
+public abstract class Configurer extends KotlinDSL {
+
+ protected Configurer(@NotNull EndpointRouteBuilder builder) {
+ super(builder);
+ }
+
+ public abstract void configure();
+}
diff --git a/extensions/kotlin-dsl/runtime/src/main/java/org/apache/camel/quarkus/dsl/kotlin/runtime/KotlinDslRecorder.java b/extensions/kotlin-dsl/runtime/src/main/java/org/apache/camel/quarkus/dsl/kotlin/runtime/KotlinDslRecorder.java
new file mode 100644
index 0000000000..7a1f3068ff
--- /dev/null
+++ b/extensions/kotlin-dsl/runtime/src/main/java/org/apache/camel/quarkus/dsl/kotlin/runtime/KotlinDslRecorder.java
@@ -0,0 +1,50 @@
+/*
+ * 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.dsl.kotlin.runtime;
+
+import java.lang.reflect.Constructor;
+
+import io.quarkus.runtime.RuntimeValue;
+import io.quarkus.runtime.annotations.Recorder;
+import org.apache.camel.CamelContext;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
+import org.apache.camel.support.ResourceHelper;
+
+@Recorder
+public class KotlinDslRecorder {
+
+ public void registerRoutesBuilder(RuntimeValue<CamelContext> camelContext, String className, String location)
+ throws Exception {
+ Constructor<? extends Configurer> constructor = (Constructor<? extends Configurer>) Class.forName(className)
+ .getDeclaredConstructor(EndpointRouteBuilder.class);
+ camelContext.getValue().addRoutes(
+ new EndpointRouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ setCamelContext(camelContext.getValue());
+ setResource(ResourceHelper.fromString(location, ""));
+ try {
+ constructor.newInstance(this).configure();
+ } catch (Exception e) {
+ throw new RuntimeCamelException("Cannot create instance of class: " + className, e);
+ }
+ }
+ });
+ }
+}
diff --git a/integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts b/extensions/kotlin-dsl/runtime/src/main/java/org/apache/camel/quarkus/dsl/kotlin/runtime/graal/SubstituteKotlinRoutesBuilderLoader.java
similarity index 59%
copy from integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts
copy to extensions/kotlin-dsl/runtime/src/main/java/org/apache/camel/quarkus/dsl/kotlin/runtime/graal/SubstituteKotlinRoutesBuilderLoader.java
index 1175ccbd11..9b23e996a4 100644
--- a/integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts
+++ b/extensions/kotlin-dsl/runtime/src/main/java/org/apache/camel/quarkus/dsl/kotlin/runtime/graal/SubstituteKotlinRoutesBuilderLoader.java
@@ -14,6 +14,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-from("direct:start")
- .id("my-kotlin-route")
- .log("Hello Kotlin !!!")
\ No newline at end of file
+package org.apache.camel.quarkus.dsl.kotlin.runtime.graal;
+
+import java.io.Reader;
+
+import com.oracle.svm.core.annotate.Substitute;
+import com.oracle.svm.core.annotate.TargetClass;
+import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
+import org.apache.camel.dsl.kotlin.KotlinRoutesBuilderLoader;
+
+@TargetClass(KotlinRoutesBuilderLoader.class)
+final class SubstituteKotlinRoutesBuilderLoader {
+
+ @Substitute
+ protected void doLoadEndpointRouteBuilder(Reader reader, EndpointRouteBuilder builder) {
+ // Do nothing
+ }
+}
diff --git a/extensions-jvm/kotlin-dsl/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/kotlin-dsl/runtime/src/main/resources/META-INF/quarkus-extension.yaml
similarity index 97%
rename from extensions-jvm/kotlin-dsl/runtime/src/main/resources/META-INF/quarkus-extension.yaml
rename to extensions/kotlin-dsl/runtime/src/main/resources/META-INF/quarkus-extension.yaml
index a9096e4cfd..e5820e7313 100644
--- a/extensions-jvm/kotlin-dsl/runtime/src/main/resources/META-INF/quarkus-extension.yaml
+++ b/extensions/kotlin-dsl/runtime/src/main/resources/META-INF/quarkus-extension.yaml
@@ -24,9 +24,8 @@
name: "Camel Kotlin DSL"
description: "Support for parsing Kotlin route definitions at runtime"
metadata:
- unlisted: true
guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/kotlin-dsl.html"
categories:
- "integration"
status:
- - "preview"
+ - "stable"
diff --git a/extensions/pom.xml b/extensions/pom.xml
index f548467277..bf56945982 100644
--- a/extensions/pom.xml
+++ b/extensions/pom.xml
@@ -156,6 +156,7 @@
<module>knative-consumer</module>
<module>knative-producer</module>
<module>kotlin</module>
+ <module>kotlin-dsl</module>
<module>kubernetes</module>
<module>kudu</module>
<module>language</module>
diff --git a/integration-tests-jvm/kotlin-dsl/src/main/java/org/apache/camel/quarkus/dsl/kotlin/KotlinDslResource.java b/integration-tests-jvm/kotlin-dsl/src/main/java/org/apache/camel/quarkus/dsl/kotlin/KotlinDslResource.java
deleted file mode 100644
index 7170ca12ee..0000000000
--- a/integration-tests-jvm/kotlin-dsl/src/main/java/org/apache/camel/quarkus/dsl/kotlin/KotlinDslResource.java
+++ /dev/null
@@ -1,60 +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.dsl.kotlin;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-import javax.json.Json;
-import javax.json.JsonArrayBuilder;
-import javax.json.JsonObject;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-
-import org.apache.camel.ExtendedCamelContext;
-import org.apache.camel.dsl.kotlin.KotlinConstantsKt;
-import org.apache.camel.quarkus.main.CamelMain;
-import org.apache.camel.spi.RoutesBuilderLoader;
-
-@Path("/test")
-@ApplicationScoped
-public class KotlinDslResource {
- @Inject
- CamelMain main;
-
- @Path("/main/describe")
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- public JsonObject describeMain() {
- final ExtendedCamelContext camelContext = main.getCamelContext().adapt(ExtendedCamelContext.class);
-
- JsonArrayBuilder routeBuilders = Json.createArrayBuilder();
- main.configure().getRoutesBuilders().forEach(builder -> routeBuilders.add(builder.getClass().getName()));
-
- JsonArrayBuilder routes = Json.createArrayBuilder();
- main.getCamelContext().getRoutes().forEach(route -> routes.add(route.getId()));
-
- return Json.createObjectBuilder()
- .add("routes-builder-loader",
- camelContext.getBootstrapFactoryFinder(RoutesBuilderLoader.FACTORY_PATH)
- .findClass(KotlinConstantsKt.EXTENSION).get().getName())
- .add("routeBuilders", routeBuilders)
- .add("routes", routes)
- .build();
- }
-}
diff --git a/integration-tests-jvm/kotlin-dsl/src/test/java/org/apache/camel/quarkus/dsl/kotlin/KotlinDslTest.java b/integration-tests-jvm/kotlin-dsl/src/test/java/org/apache/camel/quarkus/dsl/kotlin/KotlinDslTest.java
deleted file mode 100644
index cd0ee54595..0000000000
--- a/integration-tests-jvm/kotlin-dsl/src/test/java/org/apache/camel/quarkus/dsl/kotlin/KotlinDslTest.java
+++ /dev/null
@@ -1,49 +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.dsl.kotlin;
-
-import javax.ws.rs.core.MediaType;
-
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
-import io.restassured.path.json.JsonPath;
-import org.apache.camel.dsl.kotlin.KotlinRoutesBuilderLoader;
-import org.junit.jupiter.api.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-@QuarkusTest
-public class KotlinDslTest {
- @Test
- public void testMainInstanceWithJavaRoutes() {
- JsonPath p = RestAssured.given()
- .accept(MediaType.APPLICATION_JSON)
- .get("/test/main/describe")
- .then()
- .statusCode(200)
- .extract()
- .body()
- .jsonPath();
-
- assertThat(p.getString("routes-builder-loader"))
- .isEqualTo(KotlinRoutesBuilderLoader.class.getName());
- assertThat(p.getList("routeBuilders", String.class))
- .isEmpty();
- assertThat(p.getList("routes", String.class))
- .contains("my-kotlin-route");
- }
-}
diff --git a/integration-tests-jvm/pom.xml b/integration-tests-jvm/pom.xml
index b6fdee38d3..dd3059be92 100644
--- a/integration-tests-jvm/pom.xml
+++ b/integration-tests-jvm/pom.xml
@@ -86,7 +86,6 @@
<module>json-patch</module>
<module>jsonapi</module>
<module>jt400</module>
- <module>kotlin-dsl</module>
<module>ldap</module>
<module>ldif</module>
<module>lucene</module>
diff --git a/integration-tests-jvm/kotlin-dsl/pom.xml b/integration-tests/kotlin-dsl/pom.xml
similarity index 52%
rename from integration-tests-jvm/kotlin-dsl/pom.xml
rename to integration-tests/kotlin-dsl/pom.xml
index 6b7aade39f..17096e5044 100644
--- a/integration-tests-jvm/kotlin-dsl/pom.xml
+++ b/integration-tests/kotlin-dsl/pom.xml
@@ -39,6 +39,22 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-direct</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-jackson</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-bean</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-log</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-rest</artifactId>
+ </dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb</artifactId>
@@ -72,6 +88,19 @@
</activation>
<dependencies>
<!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory -->
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-bean-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-direct-deployment</artifactId>
@@ -85,6 +114,19 @@
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-jackson-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-kotlin-dsl-deployment</artifactId>
@@ -98,8 +140,61 @@
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-log-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-rest-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
</dependencies>
</profile>
+ <profile>
+ <id>native</id>
+ <activation>
+ <property>
+ <name>native</name>
+ </property>
+ </activation>
+ <properties>
+ <quarkus.package.type>native</quarkus.package.type>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
</profiles>
</project>
diff --git a/integration-tests/kotlin-dsl/src/main/java/org/apache/camel/quarkus/dsl/kotlin/KotlinDslResource.java b/integration-tests/kotlin-dsl/src/main/java/org/apache/camel/quarkus/dsl/kotlin/KotlinDslResource.java
new file mode 100644
index 0000000000..c1c7e55399
--- /dev/null
+++ b/integration-tests/kotlin-dsl/src/main/java/org/apache/camel/quarkus/dsl/kotlin/KotlinDslResource.java
@@ -0,0 +1,101 @@
+/*
+ * 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.dsl.kotlin;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.Route;
+import org.apache.camel.component.direct.DirectEndpoint;
+import org.apache.camel.dsl.kotlin.KotlinConstantsKt;
+import org.apache.camel.quarkus.main.CamelMain;
+import org.apache.camel.spi.RoutesBuilderLoader;
+
+@Path("/kotlin-dsl")
+@ApplicationScoped
+public class KotlinDslResource {
+ @Inject
+ CamelMain main;
+
+ @Inject
+ ProducerTemplate producerTemplate;
+
+ @Path("/main/kotlinRoutesBuilderLoader")
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String kotlinRoutesBuilder() {
+ final ExtendedCamelContext camelContext = main.getCamelContext().adapt(ExtendedCamelContext.class);
+ return camelContext.getBootstrapFactoryFinder(RoutesBuilderLoader.FACTORY_PATH)
+ .findClass(KotlinConstantsKt.EXTENSION).get().getName();
+ }
+
+ @Path("/main/routeBuilders")
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String routeBuilders() {
+ return main.configure().getRoutesBuilders().stream()
+ .map(rb -> rb.getClass().getSimpleName())
+ .sorted()
+ .collect(Collectors.joining(","));
+ }
+
+ @Path("/main/routes")
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String routes() {
+ return main.getCamelContext().getRoutes().stream()
+ .map(Route::getId)
+ .sorted()
+ .collect(Collectors.joining(","));
+ }
+
+ @GET
+ @Path("/main/successful/routes")
+ @Consumes(MediaType.TEXT_PLAIN)
+ @Produces(MediaType.TEXT_PLAIN)
+ public int successfulRoutes() {
+ int successful = 0;
+ Set<String> excluded = Set.of("my-kotlin-route", "routes-with-rest-dsl-get", "routes-with-rest-dsl-post");
+ for (Route route : main.getCamelContext().getRoutes()) {
+ String name = route.getRouteId();
+ if (route.getEndpoint() instanceof DirectEndpoint && !excluded.contains(name)
+ && producerTemplate.requestBody(route.getEndpoint(), "", Boolean.class) == Boolean.TRUE) {
+ successful++;
+ }
+ }
+ return successful;
+ }
+
+ @POST
+ @Path("/hello")
+ @Consumes(MediaType.TEXT_PLAIN)
+ @Produces(MediaType.TEXT_PLAIN)
+ public String hello(String message) {
+ return producerTemplate.requestBody("direct:kotlinHello", message, String.class);
+ }
+}
diff --git a/integration-tests-jvm/kotlin-dsl/src/main/resources/application.properties b/integration-tests/kotlin-dsl/src/main/resources/application.properties
similarity index 93%
rename from integration-tests-jvm/kotlin-dsl/src/main/resources/application.properties
rename to integration-tests/kotlin-dsl/src/main/resources/application.properties
index 3107c5ab50..3f43a52589 100644
--- a/integration-tests-jvm/kotlin-dsl/src/main/resources/application.properties
+++ b/integration-tests/kotlin-dsl/src/main/resources/application.properties
@@ -18,4 +18,5 @@
#
# Main
#
-camel.main.routes-include-pattern = classpath:routes/my-routes.kts
+camel.main.routes-include-pattern = classpath:routes/*.kts
+
diff --git a/integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts b/integration-tests/kotlin-dsl/src/main/resources/routes/my-routes.kts
similarity index 91%
copy from integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts
copy to integration-tests/kotlin-dsl/src/main/resources/routes/my-routes.kts
index 1175ccbd11..4387318c49 100644
--- a/integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts
+++ b/integration-tests/kotlin-dsl/src/main/resources/routes/my-routes.kts
@@ -14,6 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-from("direct:start")
+from("direct:kotlinHello")
.id("my-kotlin-route")
- .log("Hello Kotlin !!!")
\ No newline at end of file
+ .setBody().simple("Hello \${body} from Kotlin!")
diff --git a/extensions-jvm/kotlin-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/kotlin/deployment/KotlinDslProcessor.java b/integration-tests/kotlin-dsl/src/main/resources/routes/routes-with-components-configuration.kts
similarity index 54%
rename from extensions-jvm/kotlin-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/kotlin/deployment/KotlinDslProcessor.java
rename to integration-tests/kotlin-dsl/src/main/resources/routes/routes-with-components-configuration.kts
index 767e2645e1..45c1ac825f 100644
--- a/extensions-jvm/kotlin-dsl/deployment/src/main/java/org/apache/camel/quarkus/dsl/kotlin/deployment/KotlinDslProcessor.java
+++ b/integration-tests/kotlin-dsl/src/main/resources/routes/routes-with-components-configuration.kts
@@ -14,24 +14,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+import org.apache.camel.Exchange
+import org.apache.camel.component.direct.DirectComponent
+import org.apache.camel.component.log.LogComponent
-package org.apache.camel.quarkus.dsl.kotlin.deployment;
+camel {
+ components {
+ component<LogComponent>("log") {
+ setExchangeFormatter {
+ e: Exchange -> "" + e.getIn().body
+ }
+ }
-import io.quarkus.deployment.annotations.BuildStep;
-import io.quarkus.deployment.builditem.FeatureBuildItem;
-import io.quarkus.deployment.pkg.steps.NativeBuild;
+ component<DirectComponent>("direct") {
+ timeout = 1234
+ }
-public class KotlinDslProcessor {
- private static final String FEATURE = "camel-kotlin-dsl";
-
- @BuildStep
- FeatureBuildItem feature() {
- return new FeatureBuildItem(FEATURE);
+ component<DirectComponent>("myDirect") {
+ timeout = 4321
+ }
}
+}
- @BuildStep(onlyIf = NativeBuild.class)
- void nativeUnsupported() {
- throw new RuntimeException("The " + FEATURE + " extension is not supported in native mode "
- + "as loading Kotlin code at runtime is not supported on GraalVM");
+from("direct:routes-with-components-configuration")
+ .id("routes-with-components-configuration")
+ .process().message {
+ m -> m.body = m.exchange.context.getComponent("myDirect") != null
}
-}
diff --git a/integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts b/integration-tests/kotlin-dsl/src/main/resources/routes/routes-with-dataformats-configuration.kts
similarity index 57%
copy from integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts
copy to integration-tests/kotlin-dsl/src/main/resources/routes/routes-with-dataformats-configuration.kts
index 1175ccbd11..055e6e20b1 100644
--- a/integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts
+++ b/integration-tests/kotlin-dsl/src/main/resources/routes/routes-with-dataformats-configuration.kts
@@ -14,6 +14,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-from("direct:start")
- .id("my-kotlin-route")
- .log("Hello Kotlin !!!")
\ No newline at end of file
+import org.apache.camel.component.jackson.JacksonDataFormat
+
+camel {
+ dataFormats {
+ dataFormat<JacksonDataFormat>("jackson") {
+ unmarshalType = Map::class.java
+ isPrettyPrint = true
+ }
+
+ dataFormat<JacksonDataFormat>("my-jackson") {
+ unmarshalType = String::class.java
+ isPrettyPrint = false
+ }
+ }
+}
+
+from("direct:routes-with-dataformats-configuration")
+ .id("routes-with-dataformats-configuration")
+ .process().message {
+ m -> m.body = m.exchange.context.getRegistry().lookupByName("my-jackson") != null
+ }
diff --git a/integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts b/integration-tests/kotlin-dsl/src/main/resources/routes/routes-with-endpoint-dsl.kts
similarity index 81%
copy from integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts
copy to integration-tests/kotlin-dsl/src/main/resources/routes/routes-with-endpoint-dsl.kts
index 1175ccbd11..d9466cc7b6 100644
--- a/integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts
+++ b/integration-tests/kotlin-dsl/src/main/resources/routes/routes-with-endpoint-dsl.kts
@@ -14,6 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-from("direct:start")
- .id("my-kotlin-route")
- .log("Hello Kotlin !!!")
\ No newline at end of file
+var d = direct("routes-with-endpoint-dsl").advanced().synchronous(true)
+var t = log("info")
+
+from(d)
+ .id("routes-with-endpoint-dsl")
+ .setBody().constant("true")
+ .to(t)
diff --git a/integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts b/integration-tests/kotlin-dsl/src/main/resources/routes/routes-with-error-handler.kts
similarity index 68%
copy from integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts
copy to integration-tests/kotlin-dsl/src/main/resources/routes/routes-with-error-handler.kts
index 1175ccbd11..2f0f327a86 100644
--- a/integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts
+++ b/integration-tests/kotlin-dsl/src/main/resources/routes/routes-with-error-handler.kts
@@ -14,6 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-from("direct:start")
- .id("my-kotlin-route")
- .log("Hello Kotlin !!!")
\ No newline at end of file
+onException(IllegalArgumentException::class.java)
+ .id("my-on-exception")
+ .to("log:exception")
+
+from("direct:routes-with-error-handler")
+ .id("routes-with-error-handler")
+ .process().message {
+ m -> m.headers["SomeHeader"] = "SomeHeaderValue"
+ }
+ .filter().simple("\${header.SomeHeader} == 'SomeHeaderValue'")
+ .setBody().constant("true")
diff --git a/integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts b/integration-tests/kotlin-dsl/src/main/resources/routes/routes-with-languages-configuration.kts
similarity index 58%
copy from integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts
copy to integration-tests/kotlin-dsl/src/main/resources/routes/routes-with-languages-configuration.kts
index 1175ccbd11..6988090338 100644
--- a/integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts
+++ b/integration-tests/kotlin-dsl/src/main/resources/routes/routes-with-languages-configuration.kts
@@ -14,6 +14,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-from("direct:start")
- .id("my-kotlin-route")
- .log("Hello Kotlin !!!")
\ No newline at end of file
+import org.apache.camel.language.bean.BeanLanguage
+
+camel {
+ languages {
+ language<BeanLanguage>("bean") {
+ beanType = String::class.java
+ method = "toUpperCase"
+ }
+ language<BeanLanguage>("my-bean") {
+ beanType = String::class.java
+ method = "toLowerCase"
+ }
+ }
+}
+from("direct:routes-with-languages-configuration")
+ .id("routes-with-languages-configuration")
+ .process().message {
+ m -> m.body = m.exchange.context.getRegistry().lookupByName("my-bean") != null
+ }
diff --git a/integration-tests/kotlin-dsl/src/main/resources/routes/routes-with-rest.kts b/integration-tests/kotlin-dsl/src/main/resources/routes/routes-with-rest.kts
new file mode 100644
index 0000000000..8862655a56
--- /dev/null
+++ b/integration-tests/kotlin-dsl/src/main/resources/routes/routes-with-rest.kts
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+rest {
+ configuration {
+ contextPath = "/root"
+ }
+
+ path("/my/path") {
+ get("/get") {
+ id("routes-with-rest-get")
+ produces("text/plain")
+ to("direct:get")
+ }
+ }
+
+ post {
+ id("routes-with-rest-post")
+ path("/post")
+ consumes("text/plain")
+ produces("text/plain")
+ to("direct:post")
+ }
+}
+
+from("direct:get")
+ .id("routes-with-rest-dsl-get")
+ .transform().constant("Hello World")
+from("direct:post")
+ .id("routes-with-rest-dsl-post")
+ .setBody().simple("Hello \${body}")
+
+from("direct:routes-with-rest")
+ .id("routes-with-rest")
+ .process().message {
+ m -> m.headers["AnotherHeader"] = "AnotherHeaderValue"
+ }
+ .filter().simple("\${header.AnotherHeader} == 'AnotherHeaderValue'")
+ .setBody().constant("true")
diff --git a/integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts b/integration-tests/kotlin-dsl/src/main/resources/routes/routes.kts
similarity index 78%
copy from integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts
copy to integration-tests/kotlin-dsl/src/main/resources/routes/routes.kts
index 1175ccbd11..1bf9bcd8be 100644
--- a/integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts
+++ b/integration-tests/kotlin-dsl/src/main/resources/routes/routes.kts
@@ -14,6 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-from("direct:start")
- .id("my-kotlin-route")
- .log("Hello Kotlin !!!")
\ No newline at end of file
+from("direct:routes")
+ .id("routes")
+ .process().message {
+ m -> m.headers["MyHeader"] = "MyHeaderValue"
+ }
+ .filter().simple("\${header.MyHeader} == 'MyHeaderValue'")
+ .setBody().constant("true")
diff --git a/integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts b/integration-tests/kotlin-dsl/src/test/java/org/apache/camel/quarkus/dsl/kotlin/KotlinDslIT.java
similarity index 82%
rename from integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts
rename to integration-tests/kotlin-dsl/src/test/java/org/apache/camel/quarkus/dsl/kotlin/KotlinDslIT.java
index 1175ccbd11..7d41693a7c 100644
--- a/integration-tests-jvm/kotlin-dsl/src/main/resources/routes/my-routes.kts
+++ b/integration-tests/kotlin-dsl/src/test/java/org/apache/camel/quarkus/dsl/kotlin/KotlinDslIT.java
@@ -14,6 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-from("direct:start")
- .id("my-kotlin-route")
- .log("Hello Kotlin !!!")
\ No newline at end of file
+package org.apache.camel.quarkus.dsl.kotlin;
+
+import io.quarkus.test.junit.QuarkusIntegrationTest;
+
+@QuarkusIntegrationTest
+class KotlinDslIT extends KotlinDslTest {
+
+}
diff --git a/integration-tests/kotlin-dsl/src/test/java/org/apache/camel/quarkus/dsl/kotlin/KotlinDslTest.java b/integration-tests/kotlin-dsl/src/test/java/org/apache/camel/quarkus/dsl/kotlin/KotlinDslTest.java
new file mode 100644
index 0000000000..d9e85dd71b
--- /dev/null
+++ b/integration-tests/kotlin-dsl/src/test/java/org/apache/camel/quarkus/dsl/kotlin/KotlinDslTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.dsl.kotlin;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import org.apache.camel.dsl.kotlin.KotlinRoutesBuilderLoader;
+import org.hamcrest.CoreMatchers;
+import org.junit.jupiter.api.Test;
+
+@QuarkusTest
+class KotlinDslTest {
+
+ @Test
+ void kotlinHello() {
+ RestAssured.given()
+ .body("Will Smith")
+ .post("/kotlin-dsl/hello")
+ .then()
+ .statusCode(200)
+ .body(CoreMatchers.is("Hello Will Smith from Kotlin!"));
+ }
+
+ @Test
+ void testMainInstanceWithJavaRoutes() {
+ RestAssured.given()
+ .get("/kotlin-dsl/main/kotlinRoutesBuilderLoader")
+ .then()
+ .statusCode(200)
+ .body(CoreMatchers.is(KotlinRoutesBuilderLoader.class.getName()));
+
+ RestAssured.given()
+ .get("/kotlin-dsl/main/routeBuilders")
+ .then()
+ .statusCode(200)
+ .body(CoreMatchers.is(""));
+
+ RestAssured.given()
+ .get("/kotlin-dsl/main/routes")
+ .then()
+ .statusCode(200)
+ .body(CoreMatchers.is(
+ "my-kotlin-route,routes,routes-with-components-configuration,routes-with-dataformats-configuration,routes-with-endpoint-dsl,routes-with-error-handler,routes-with-languages-configuration,routes-with-rest,routes-with-rest-dsl-get,routes-with-rest-dsl-post,routes-with-rest-get,routes-with-rest-post"));
+
+ RestAssured.given()
+ .get("/kotlin-dsl/main/successful/routes")
+ .then()
+ .statusCode(200)
+ .body(CoreMatchers.is("7"));
+ }
+
+ @Test
+ void testRestEndpoints() {
+ RestAssured.given()
+ .get("/root/my/path/get")
+ .then()
+ .statusCode(200)
+ .body(CoreMatchers.is("Hello World"));
+ RestAssured.given()
+ .body("Will")
+ .post("/root/post")
+ .then()
+ .statusCode(200)
+ .body(CoreMatchers.is("Hello Will"));
+ }
+}
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index 061f0adea1..043063a5b4 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -144,6 +144,7 @@
<module>knative-event-consumer</module>
<module>knative-producer</module>
<module>kotlin</module>
+ <module>kotlin-dsl</module>
<module>kubernetes</module>
<module>kudu</module>
<module>leveldb</module>
diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml
index c0c776976d..023abb356b 100644
--- a/tooling/scripts/test-categories.yaml
+++ b/tooling/scripts/test-categories.yaml
@@ -208,6 +208,7 @@ group-13:
- jira
- java-joor-dsl
- js-dsl
+ - kotlin-dsl
- kubernetes
- salesforce
- sap-netweaver