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/09/29 12:58:41 UTC

[camel-quarkus] branch master updated: String template native support #1694

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

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


The following commit(s) were added to refs/heads/master by this push:
     new a29ad99  String template native support #1694
a29ad99 is described below

commit a29ad9965d5a1360d3a0bb4bcc4a0932dc2a4d3a
Author: JiriOndrusek <on...@gmail.com>
AuthorDate: Wed Sep 23 14:01:33 2020 +0200

    String template native support #1694
---
 .../reference/components/stringtemplate.adoc}      |   8 +-
 .../pages/reference/extensions/stringtemplate.adoc |  18 ++-
 .../reference/components/string-template.adoc      |   6 +-
 extensions-jvm/pom.xml                             |   1 -
 extensions/pom.xml                                 |   1 +
 .../stringtemplate/deployment/pom.xml              |   0
 .../deployment/StringtemplateProcessor.java        |  16 --
 .../stringtemplate/pom.xml                         |   1 -
 .../stringtemplate/runtime/pom.xml                 |   1 +
 .../runtime/src/main/doc/limitations.adoc          |   6 +
 .../main/resources/META-INF/quarkus-extension.yaml |   3 +-
 integration-tests/pom.xml                          |   1 +
 .../stringtemplate}/pom.xml                        |  45 +++++-
 .../stringtemplate/it/StringtemplateResource.java  |  40 +++--
 .../src/main/resources/application.properties      |  17 +++
 .../main/resources/template/allowContextMapAll.tm  |  17 +++
 .../resources/template/custom-delimiter-brace.tm   |  17 +++
 .../resources/template/custom-delimiter-dollar.tm  |  17 +++
 .../src/main/resources/template/letter.tm          |  17 +++
 .../src/main/resources/template/template.tm        |  17 +++
 .../stringtemplate/it/StringtemplateIT.java        |  16 +-
 .../stringtemplate/it/StringtemplateTest.java      | 162 +++++++++++++++++++++
 pom.xml                                            |   1 +
 tooling/scripts/test-categories.yaml               |   1 +
 24 files changed, 368 insertions(+), 61 deletions(-)

diff --git a/docs/modules/ROOT/partials/reference/components/string-template.adoc b/docs/modules/ROOT/pages/reference/components/stringtemplate.adoc
similarity index 82%
copy from docs/modules/ROOT/partials/reference/components/string-template.adoc
copy to docs/modules/ROOT/pages/reference/components/stringtemplate.adoc
index 48adaa6..c2db535 100644
--- a/docs/modules/ROOT/partials/reference/components/string-template.adoc
+++ b/docs/modules/ROOT/pages/reference/components/stringtemplate.adoc
@@ -1,12 +1,14 @@
 // Do not edit directly!
 // This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
+
+= String Template
 :cq-artifact-id: camel-quarkus-stringtemplate
 :cq-artifact-id-base: stringtemplate
-:cq-native-supported: false
-:cq-status: Preview
+:cq-native-supported: true
+:cq-status: Stable
 :cq-deprecated: false
 :cq-jvm-since: 1.1.0
-:cq-native-since: n/a
+:cq-native-since: 1.2.0
 :cq-camel-part-name: string-template
 :cq-camel-part-title: String Template
 :cq-camel-part-description: Transform messages using StringTemplate engine.
diff --git a/docs/modules/ROOT/pages/reference/extensions/stringtemplate.adoc b/docs/modules/ROOT/pages/reference/extensions/stringtemplate.adoc
index be7f244..87c1b0e 100644
--- a/docs/modules/ROOT/pages/reference/extensions/stringtemplate.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/stringtemplate.adoc
@@ -2,15 +2,15 @@
 // This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
 = String Template
 :cq-artifact-id: camel-quarkus-stringtemplate
-:cq-native-supported: false
-:cq-status: Preview
+:cq-native-supported: true
+:cq-status: Stable
 :cq-description: Transform messages using StringTemplate engine.
 :cq-deprecated: false
 :cq-jvm-since: 1.1.0
-:cq-native-since: n/a
+:cq-native-since: 1.2.0
 
 [.badges]
-[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native##[.badge-unsupported]##unsupported##
+[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native since##[.badge-supported]##1.2.0##
 
 Transform messages using StringTemplate engine.
 
@@ -31,3 +31,13 @@ Please refer to the above link for usage and configuration details.
 ----
 
 Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.
+
+== Camel Quarkus limitations
+
+If property `allowContextMapAll` is set to `true` there is a limitation in native mode. Reflective calls to methods
+of several classes in camel are not allowed (for example `org.apache.camel.support.DefaultExchange`). Therefore
+some expressions won't work (for example `<exchange.properties.*>).
+
+You can allow reflective calls to such classes (for example by using application.properties), but keep in mind that it brings
+some security risks.
+
diff --git a/docs/modules/ROOT/partials/reference/components/string-template.adoc b/docs/modules/ROOT/partials/reference/components/string-template.adoc
index 48adaa6..87917cb 100644
--- a/docs/modules/ROOT/partials/reference/components/string-template.adoc
+++ b/docs/modules/ROOT/partials/reference/components/string-template.adoc
@@ -2,11 +2,11 @@
 // This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
 :cq-artifact-id: camel-quarkus-stringtemplate
 :cq-artifact-id-base: stringtemplate
-:cq-native-supported: false
-:cq-status: Preview
+:cq-native-supported: true
+:cq-status: Stable
 :cq-deprecated: false
 :cq-jvm-since: 1.1.0
-:cq-native-since: n/a
+:cq-native-since: 1.2.0
 :cq-camel-part-name: string-template
 :cq-camel-part-title: String Template
 :cq-camel-part-description: Transform messages using StringTemplate engine.
diff --git a/extensions-jvm/pom.xml b/extensions-jvm/pom.xml
index c7991d6..9cd0b87 100644
--- a/extensions-jvm/pom.xml
+++ b/extensions-jvm/pom.xml
@@ -140,7 +140,6 @@
         <module>splunk-hec</module>
         <module>stax</module>
         <module>stomp</module>
-        <module>stringtemplate</module>
         <module>stub</module>
         <module>syslog</module>
         <module>thrift</module>
diff --git a/extensions/pom.xml b/extensions/pom.xml
index 7501bdf..1f0b45e 100644
--- a/extensions/pom.xml
+++ b/extensions/pom.xml
@@ -179,6 +179,7 @@
         <module>sql</module>
         <module>ssh</module>
         <module>stream</module>
+        <module>stringtemplate</module>
         <module>tagsoup</module>
         <module>tarfile</module>
         <module>telegram</module>
diff --git a/extensions-jvm/stringtemplate/deployment/pom.xml b/extensions/stringtemplate/deployment/pom.xml
similarity index 100%
rename from extensions-jvm/stringtemplate/deployment/pom.xml
rename to extensions/stringtemplate/deployment/pom.xml
diff --git a/extensions-jvm/stringtemplate/deployment/src/main/java/org/apache/camel/quarkus/component/stringtemplate/deployment/StringtemplateProcessor.java b/extensions/stringtemplate/deployment/src/main/java/org/apache/camel/quarkus/component/stringtemplate/deployment/StringtemplateProcessor.java
similarity index 62%
rename from extensions-jvm/stringtemplate/deployment/src/main/java/org/apache/camel/quarkus/component/stringtemplate/deployment/StringtemplateProcessor.java
rename to extensions/stringtemplate/deployment/src/main/java/org/apache/camel/quarkus/component/stringtemplate/deployment/StringtemplateProcessor.java
index bd32a09..95e1b1b 100644
--- a/extensions-jvm/stringtemplate/deployment/src/main/java/org/apache/camel/quarkus/component/stringtemplate/deployment/StringtemplateProcessor.java
+++ b/extensions/stringtemplate/deployment/src/main/java/org/apache/camel/quarkus/component/stringtemplate/deployment/StringtemplateProcessor.java
@@ -17,30 +17,14 @@
 package org.apache.camel.quarkus.component.stringtemplate.deployment;
 
 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.pkg.steps.NativeBuild;
-import org.apache.camel.quarkus.core.JvmOnlyRecorder;
-import org.jboss.logging.Logger;
 
 class StringtemplateProcessor {
 
-    private static final Logger LOG = Logger.getLogger(StringtemplateProcessor.class);
     private static final String FEATURE = "camel-stringtemplate";
 
     @BuildStep
     FeatureBuildItem feature() {
         return new FeatureBuildItem(FEATURE);
     }
-
-    /**
-     * Remove this once this extension starts supporting the native mode.
-     */
-    @BuildStep(onlyIf = NativeBuild.class)
-    @Record(value = ExecutionTime.RUNTIME_INIT)
-    void warnJvmInNative(JvmOnlyRecorder recorder) {
-        JvmOnlyRecorder.warnJvmInNative(LOG, FEATURE); // warn at build time
-        recorder.warnJvmInNative(FEATURE); // warn at runtime
-    }
 }
diff --git a/extensions-jvm/stringtemplate/pom.xml b/extensions/stringtemplate/pom.xml
similarity index 97%
rename from extensions-jvm/stringtemplate/pom.xml
rename to extensions/stringtemplate/pom.xml
index 68b0308..105c7ac 100644
--- a/extensions-jvm/stringtemplate/pom.xml
+++ b/extensions/stringtemplate/pom.xml
@@ -35,6 +35,5 @@
     <modules>
         <module>deployment</module>
         <module>runtime</module>
-        <module>integration-test</module>
     </modules>
 </project>
diff --git a/extensions-jvm/stringtemplate/runtime/pom.xml b/extensions/stringtemplate/runtime/pom.xml
similarity index 98%
rename from extensions-jvm/stringtemplate/runtime/pom.xml
rename to extensions/stringtemplate/runtime/pom.xml
index a788696..47d6298 100644
--- a/extensions-jvm/stringtemplate/runtime/pom.xml
+++ b/extensions/stringtemplate/runtime/pom.xml
@@ -34,6 +34,7 @@
 
     <properties>
         <camel.quarkus.jvmSince>1.1.0</camel.quarkus.jvmSince>
+        <camel.quarkus.nativeSince>1.2.0</camel.quarkus.nativeSince>
     </properties>
 
     <dependencyManagement>
diff --git a/extensions/stringtemplate/runtime/src/main/doc/limitations.adoc b/extensions/stringtemplate/runtime/src/main/doc/limitations.adoc
new file mode 100644
index 0000000..af16d9e
--- /dev/null
+++ b/extensions/stringtemplate/runtime/src/main/doc/limitations.adoc
@@ -0,0 +1,6 @@
+If property `allowContextMapAll` is set to `true` there is a limitation in native mode. Reflective calls to methods
+of several classes in camel are not allowed (for example `org.apache.camel.support.DefaultExchange`). Therefore
+some expressions won't work (for example `<exchange.properties.*>).
+
+You can allow reflective calls to such classes (for example by using application.properties), but keep in mind that it brings
+some security risks.
\ No newline at end of file
diff --git a/extensions-jvm/stringtemplate/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/stringtemplate/runtime/src/main/resources/META-INF/quarkus-extension.yaml
similarity index 97%
rename from extensions-jvm/stringtemplate/runtime/src/main/resources/META-INF/quarkus-extension.yaml
rename to extensions/stringtemplate/runtime/src/main/resources/META-INF/quarkus-extension.yaml
index f11ea09..2bd8ea6 100644
--- a/extensions-jvm/stringtemplate/runtime/src/main/resources/META-INF/quarkus-extension.yaml
+++ b/extensions/stringtemplate/runtime/src/main/resources/META-INF/quarkus-extension.yaml
@@ -24,9 +24,8 @@
 name: "Camel String Template"
 description: "Transform messages using StringTemplate engine"
 metadata:
-  unlisted: true
   guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/stringtemplate.html"
   categories:
   - "integration"
   status:
-  - "preview"
+  - "stable"
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index ea9705e..18a9bc9 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -147,6 +147,7 @@
         <module>soap</module>
         <module>sql</module>
         <module>ssh</module>
+        <module>stringtemplate</module>
         <module>syndication</module>
         <module>tarfile</module>
         <module>telegram</module>
diff --git a/extensions-jvm/stringtemplate/integration-test/pom.xml b/integration-tests/stringtemplate/pom.xml
similarity index 69%
rename from extensions-jvm/stringtemplate/integration-test/pom.xml
rename to integration-tests/stringtemplate/pom.xml
index a624d02..544081e 100644
--- a/extensions-jvm/stringtemplate/integration-test/pom.xml
+++ b/integration-tests/stringtemplate/pom.xml
@@ -23,13 +23,13 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.camel.quarkus</groupId>
-        <artifactId>camel-quarkus-build-parent-it</artifactId>
+        <artifactId>camel-quarkus-integration-tests</artifactId>
         <version>1.2.0-SNAPSHOT</version>
-        <relativePath>../../../poms/build-parent-it/pom.xml</relativePath>
+        <relativePath>../pom.xml</relativePath>
     </parent>
 
-    <artifactId>camel-quarkus-stringtemplate-integration-test</artifactId>
-    <name>Camel Quarkus :: String Template :: Integration Test</name>
+    <artifactId>camel-quarkus-integration-test-stringtemplate</artifactId>
+    <name>Camel Quarkus :: Integration Tests :: String Template</name>
     <description>Integration tests for Camel Quarkus String Template extension</description>
 
     <dependencyManagement>
@@ -53,6 +53,10 @@
             <groupId>io.quarkus</groupId>
             <artifactId>quarkus-resteasy</artifactId>
         </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-resteasy-jackson</artifactId>
+        </dependency>
 
         <!-- test dependencies -->
         <dependency>
@@ -66,7 +70,7 @@
             <scope>test</scope>
         </dependency>
 
-        <!-- The following dependencies guarantee that this module is built after them. You can update them by runing `mvn process-resources -Pformat -N` from the source tree root directory -->
+        <!-- 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-stringtemplate-deployment</artifactId>
@@ -97,4 +101,35 @@
             </plugin>
         </plugins>
     </build>
+
+    <profiles>
+        <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/extensions-jvm/stringtemplate/integration-test/src/main/java/org/apache/camel/quarkus/component/stringtemplate/it/StringtemplateResource.java b/integration-tests/stringtemplate/src/main/java/org/apache/camel/quarkus/component/stringtemplate/it/StringtemplateResource.java
similarity index 53%
rename from extensions-jvm/stringtemplate/integration-test/src/main/java/org/apache/camel/quarkus/component/stringtemplate/it/StringtemplateResource.java
rename to integration-tests/stringtemplate/src/main/java/org/apache/camel/quarkus/component/stringtemplate/it/StringtemplateResource.java
index 1a4599c..e500213 100644
--- a/extensions-jvm/stringtemplate/integration-test/src/main/java/org/apache/camel/quarkus/component/stringtemplate/it/StringtemplateResource.java
+++ b/integration-tests/stringtemplate/src/main/java/org/apache/camel/quarkus/component/stringtemplate/it/StringtemplateResource.java
@@ -16,15 +16,21 @@
  */
 package org.apache.camel.quarkus.component.stringtemplate.it;
 
+import java.net.URI;
+import java.util.Map;
+
 import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
-import javax.ws.rs.GET;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
-import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
 import org.jboss.logging.Logger;
 
 @Path("/stringtemplate")
@@ -33,19 +39,27 @@ public class StringtemplateResource {
 
     private static final Logger LOG = Logger.getLogger(StringtemplateResource.class);
 
-    private static final String COMPONENT_STRING_TEMPLATE = "string-template";
     @Inject
-    CamelContext context;
+    ProducerTemplate producerTemplate;
 
-    @Path("/load/component/string-template")
-    @GET
+    @Path("/template")
+    @POST
+    @Consumes(MediaType.APPLICATION_JSON)
     @Produces(MediaType.TEXT_PLAIN)
-    public Response loadComponentStringTemplate() throws Exception {
-        /* This is an autogenerated test */
-        if (context.getComponent(COMPONENT_STRING_TEMPLATE) != null) {
-            return Response.ok().build();
-        }
-        LOG.warnf("Could not load [%s] from the Camel context", COMPONENT_STRING_TEMPLATE);
-        return Response.status(500, COMPONENT_STRING_TEMPLATE + " could not be loaded from the Camel context").build();
+    public Response post(Map<String, Object> headers,
+            @QueryParam("template") String template,
+            @QueryParam("body") String body,
+            @QueryParam("parameters") String parameters) throws Exception {
+        LOG.infof("Sending to stringtemplate: %s", headers);
+        String endpointUri = "string-template:" + template + (parameters != null ? "?" + parameters : "");
+        final Exchange response = producerTemplate.request(endpointUri, exchange -> {
+            exchange.getIn().setBody(body);
+            exchange.getIn().setHeaders(headers);
+        });
+        LOG.infof("Got response from stringtemplate: %s", response.getMessage().getBody());
+        return Response
+                .created(new URI("https://camel.apache.org/"))
+                .entity(response.getMessage().getBody())
+                .build();
     }
 }
diff --git a/integration-tests/stringtemplate/src/main/resources/application.properties b/integration-tests/stringtemplate/src/main/resources/application.properties
new file mode 100644
index 0000000..ce60864
--- /dev/null
+++ b/integration-tests/stringtemplate/src/main/resources/application.properties
@@ -0,0 +1,17 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+quarkus.camel.native.resources.include-patterns = template/*.tm 
\ No newline at end of file
diff --git a/integration-tests/stringtemplate/src/main/resources/template/allowContextMapAll.tm b/integration-tests/stringtemplate/src/main/resources/template/allowContextMapAll.tm
new file mode 100644
index 0000000..976c889
--- /dev/null
+++ b/integration-tests/stringtemplate/src/main/resources/template/allowContextMapAll.tm
@@ -0,0 +1,17 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+Exchange is <exchange>.
\ No newline at end of file
diff --git a/integration-tests/stringtemplate/src/main/resources/template/custom-delimiter-brace.tm b/integration-tests/stringtemplate/src/main/resources/template/custom-delimiter-brace.tm
new file mode 100644
index 0000000..391bb4b
--- /dev/null
+++ b/integration-tests/stringtemplate/src/main/resources/template/custom-delimiter-brace.tm
@@ -0,0 +1,17 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+With brace delimiter {body}
diff --git a/integration-tests/stringtemplate/src/main/resources/template/custom-delimiter-dollar.tm b/integration-tests/stringtemplate/src/main/resources/template/custom-delimiter-dollar.tm
new file mode 100644
index 0000000..b667b3e
--- /dev/null
+++ b/integration-tests/stringtemplate/src/main/resources/template/custom-delimiter-dollar.tm
@@ -0,0 +1,17 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+With identical dollar delimiter $body$
diff --git a/integration-tests/stringtemplate/src/main/resources/template/letter.tm b/integration-tests/stringtemplate/src/main/resources/template/letter.tm
new file mode 100644
index 0000000..c581691
--- /dev/null
+++ b/integration-tests/stringtemplate/src/main/resources/template/letter.tm
@@ -0,0 +1,17 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+Dear <headers.name>! Thanks for the order of <headers.item>. Regards Camel Riders Bookstore <body>
\ No newline at end of file
diff --git a/integration-tests/stringtemplate/src/main/resources/template/template.tm b/integration-tests/stringtemplate/src/main/resources/template/template.tm
new file mode 100644
index 0000000..61abe97
--- /dev/null
+++ b/integration-tests/stringtemplate/src/main/resources/template/template.tm
@@ -0,0 +1,17 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+Dear <headers.name>. You ordered item <item> on <body>.
\ No newline at end of file
diff --git a/extensions-jvm/stringtemplate/integration-test/src/test/java/org/apache/camel/quarkus/component/stringtemplate/it/StringtemplateTest.java b/integration-tests/stringtemplate/src/test/java/org/apache/camel/quarkus/component/stringtemplate/it/StringtemplateIT.java
similarity index 68%
rename from extensions-jvm/stringtemplate/integration-test/src/test/java/org/apache/camel/quarkus/component/stringtemplate/it/StringtemplateTest.java
rename to integration-tests/stringtemplate/src/test/java/org/apache/camel/quarkus/component/stringtemplate/it/StringtemplateIT.java
index 72b8a1a..485390b 100644
--- a/extensions-jvm/stringtemplate/integration-test/src/test/java/org/apache/camel/quarkus/component/stringtemplate/it/StringtemplateTest.java
+++ b/integration-tests/stringtemplate/src/test/java/org/apache/camel/quarkus/component/stringtemplate/it/StringtemplateIT.java
@@ -16,19 +16,9 @@
  */
 package org.apache.camel.quarkus.component.stringtemplate.it;
 
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
-import org.junit.jupiter.api.Test;
+import io.quarkus.test.junit.NativeImageTest;
 
-@QuarkusTest
-class StringtemplateTest {
-
-    @Test
-    public void loadComponentStringTemplate() {
-        /* A simple autogenerated test */
-        RestAssured.get("/stringtemplate/load/component/string-template")
-                .then()
-                .statusCode(200);
-    }
+@NativeImageTest
+class StringtemplateIT extends StringtemplateTest {
 
 }
diff --git a/integration-tests/stringtemplate/src/test/java/org/apache/camel/quarkus/component/stringtemplate/it/StringtemplateTest.java b/integration-tests/stringtemplate/src/test/java/org/apache/camel/quarkus/component/stringtemplate/it/StringtemplateTest.java
new file mode 100644
index 0000000..976b4b6
--- /dev/null
+++ b/integration-tests/stringtemplate/src/test/java/org/apache/camel/quarkus/component/stringtemplate/it/StringtemplateTest.java
@@ -0,0 +1,162 @@
+/*
+ * 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.stringtemplate.it;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.apache.camel.component.stringtemplate.StringTemplateConstants;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.equalTo;
+
+@QuarkusTest
+class StringtemplateTest {
+
+    @Test
+    public void testTemplateFromClasspath() {
+        Map<String, Object> headers = new HashMap() {
+            {
+                put("name", "Sheldon");
+                put("item", "Camel in Action");
+            }
+        };
+        RestAssured.given()
+                .queryParam("body", "PS: Next beer is on me!")
+                .queryParam("template", "//template/letter.tm")
+                .contentType(ContentType.JSON)
+                .body(headers)
+                .post("/stringtemplate/template")
+                .then()
+                .statusCode(201)
+                .body(containsString(
+                        "Dear Sheldon! Thanks for the order of Camel in Action. Regards Camel Riders Bookstore PS: Next beer is on me!"));
+    }
+
+    @Test
+    public void testVariableMap() {
+
+        Map<String, Object> variableMap = new HashMap<>();
+        Map<String, Object> headersMap = new HashMap<>();
+        headersMap.put("name", "Willem");
+        variableMap.put("headers", headersMap);
+        variableMap.put("body", "Monday");
+        variableMap.put("item", "1");
+        Map<String, Object> headers = new HashMap() {
+            {
+                put("name", "Sheldon");
+                put("item", "7");
+                put(StringTemplateConstants.STRINGTEMPLATE_VARIABLE_MAP, variableMap);
+                put(StringTemplateConstants.STRINGTEMPLATE_RESOURCE_URI, variableMap);
+            }
+        };
+        //`allowTemplateFromHeader` is need to be set to true because of https://issues.apache.org/jira/browse/CAMEL-15577
+        RestAssured.given()
+                .queryParam("body", "")
+                .queryParam("template", "//template/template.tm")
+                .queryParam("parameters", "allowTemplateFromHeader=true")
+                .contentType(ContentType.JSON)
+                .body(headers)
+                .post("/stringtemplate/template")
+                .then()
+                .statusCode(201)
+                .body(containsString(
+                        "Dear Willem. You ordered item 1 on Monday."));
+    }
+
+    @Test
+    public void testWithBraceDelimiter() {
+        testWithDelimiter("{", "}", "With brace delimiter ", "custom-delimiter-brace.tm");
+    }
+
+    @Test
+    public void testWithDollarDelimiter() {
+        testWithDelimiter("$", "$", "With identical dollar delimiter ", "custom-delimiter-dollar.tm");
+    }
+
+    private void testWithDelimiter(String start, String stop, String text, String template) {
+        RestAssured.given()
+                .queryParam("body", "WORKS!")
+                .queryParam("template", "//template/" + template)
+                .queryParam("parameters", "delimiterStart=" + start + "&delimiterStop=" + stop)
+                .contentType(ContentType.JSON)
+                .body(Collections.emptyMap())
+                .post("/stringtemplate/template")
+                .then()
+                .statusCode(201)
+                .body(containsString(
+                        text + "WORKS!\n"));
+    }
+
+    @Test
+    public void testContentCacheFalse() throws Exception {
+        testContentCache(false);
+    }
+
+    @Test
+    public void testContentCacheTrue() throws Exception {
+        testContentCache(true);
+    }
+
+    private void testContentCache(boolean useContentCache) throws Exception {
+        File template = createFile("stringtemplate", "Hi <headers.name>");
+
+        RestAssured.given()
+                .queryParam("template", "file:" + template.getPath())
+                .queryParam("parameters", "contentCache=" + useContentCache)
+                .contentType(ContentType.JSON)
+                .body(Collections.singletonMap("name", "Sheldon"))
+                .post("/stringtemplate/template")
+                .then()
+                .statusCode(201)
+                .body(equalTo("Hi Sheldon"));
+
+        //override file
+        Files.write(Paths.get(template.getPath()), "Bye <headers.name>".getBytes(StandardCharsets.UTF_8));
+
+        RestAssured.given()
+                .queryParam("template", "file:" + template.getPath())
+                .queryParam("parameters", "contentCache=" + useContentCache)
+                .contentType(ContentType.JSON)
+                .body(Collections.singletonMap("name", "Sheldon"))
+                .body(Collections.singletonMap("name", "Sheldon"))
+                .post("/stringtemplate/template")
+                .then()
+                .statusCode(201)
+                .body(equalTo(useContentCache ? "Hi Sheldon" : "Bye Sheldon"));
+    }
+
+    private File createFile(String fileName, String body) throws IOException {
+        File tmpFile = File.createTempFile(fileName, ".tm");
+
+        Files.write(tmpFile.toPath(), body.getBytes(StandardCharsets.UTF_8));
+
+        tmpFile.deleteOnExit();
+        return tmpFile;
+    }
+
+}
diff --git a/pom.xml b/pom.xml
index ffe22a9..3896eda 100644
--- a/pom.xml
+++ b/pom.xml
@@ -421,6 +421,7 @@
                             <rng>XML_STYLE</rng>
                             <spring.factories>CAMEL_PROPERTIES_STYLE</spring.factories>
                             <spring.provides>CAMEL_PROPERTIES_STYLE</spring.provides>
+                            <tm>CAMEL_PROPERTIES_STYLE</tm>
                             <kt>SLASHSTAR_STYLE</kt>
                         </mapping>
                         <headerDefinitions>
diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml
index 4317c69..e116f12 100644
--- a/tooling/scripts/test-categories.yaml
+++ b/tooling/scripts/test-categories.yaml
@@ -101,6 +101,7 @@ misc:
   - mustache
   - pdf
   - qute
+  - stringtemplate
   - tika
   - velocity
   - as2