Skip to content

Commit

Permalink
String template native support #1694
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriOndrusek authored and jamesnetherton committed Sep 29, 2020
1 parent f81b12e commit a29ad99
Show file tree
Hide file tree
Showing 24 changed files with 378 additions and 58 deletions.
15 changes: 15 additions & 0 deletions docs/modules/ROOT/pages/reference/components/stringtemplate.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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: true
:cq-status: Stable
:cq-deprecated: false
:cq-jvm-since: 1.1.0
: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.
:cq-extension-page-title: String Template
18 changes: 14 additions & 4 deletions docs/modules/ROOT/pages/reference/extensions/stringtemplate.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.

Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion extensions-jvm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@
<modules>
<module>deployment</module>
<module>runtime</module>
<module>integration-test</module>
</modules>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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>.
Original file line number Diff line number Diff line change
@@ -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}
Original file line number Diff line number Diff line change
@@ -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$
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit a29ad99

Please sign in to comment.