forked from apache/camel-quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests and docs for the simple language apache#2533
- Loading branch information
1 parent
cc32c2f
commit 2c93ab6
Showing
11 changed files
with
468 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
extensions-core/core/runtime/src/main/doc/configuration.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
=== Simple language | ||
|
||
==== Using the OGNL notation | ||
When using the OGNL notation from the simple language, the `camel-quarkus-bean` extension should be used. | ||
|
||
For instance, the expression below is accessing the `getAddress()` method on the message body of type `Client`. | ||
[source,java] | ||
--- | ||
simple("${body.address}") | ||
--- | ||
|
||
In such a situation, one should take an additional dependency on the camel-quarkus-bean extension xref:{cq-camel-components}::bean-component.adoc[as described here]. | ||
Note that in native mode, some classes may need to be registered for reflection. In the example above, the `Client` class | ||
needs to be link:https://quarkus.io/guides/writing-native-applications-tips#registering-for-reflection[registered for reflection]. | ||
|
||
==== Using dynamic type resolution in native mode | ||
When dynamically resolving a type from simple expressions like `${mandatoryBodyAs(TYPE)}` or `${body} is TYPE`, it may be needed to register some classes for reflection manually. | ||
|
||
For instance, the simple expressions below is dynamically resolving the type `java.nio.ByteBuffer` at runtime: | ||
[source,java] | ||
--- | ||
simple("${body} is 'java.nio.ByteBuffer'") | ||
--- | ||
|
||
As such, the class `java.nio.ByteBuffer` needs to be link:https://quarkus.io/guides/writing-native-applications-tips#registering-for-reflection[registered for reflection]. | ||
|
||
==== Using the simple language with classpath resources in native mode | ||
Beyond standard usages, a trick is needed when using the simple language with classpath resources in native mode. In such a situation, one needs to explicitly embed the resources in the native executable by specifying the `include-patterns` option. | ||
|
||
For instance, the route below would load a simple script from a classpath resource named _mysimple.txt_: | ||
[source,java] | ||
---- | ||
from("direct:start").transform().simple("resource:classpath:mysimple.txt"); | ||
---- | ||
|
||
In order to work in native mode the `include-patterns` configuration should be set. For instance, in the `application.properties` file as below : | ||
[source,properties] | ||
---- | ||
quarkus.camel.native.resources.include-patterns = *.txt | ||
---- | ||
|
||
More information about selecting resources for inclusion in the native executable could be found at xref:user-guide/native-mode.adoc#embedding-resource-in-native-executable[Embedding resource in native executable]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-integration-tests</artifactId> | ||
<version>1.9.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>camel-quarkus-integration-test-simple</artifactId> | ||
<name>Camel Quarkus :: Integration Tests :: Simple :: Tests</name> | ||
<description>The camel quarkus integration tests for the simple language</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-direct</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-bean</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy</artifactId> | ||
</dependency> | ||
|
||
<!-- test dependencies --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- 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> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<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> |
39 changes: 39 additions & 0 deletions
39
...mple/src/main/java/org/apache/camel/quarkus/language/simple/ReflectionConfigurations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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.language.simple; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
import io.quarkus.runtime.annotations.RegisterForReflection; | ||
|
||
/** | ||
* Manually register some third party classes for reflection. | ||
*/ | ||
public class ReflectionConfigurations { | ||
|
||
// Needed as "${mandatoryBodyAs(String).OGNL}" reflectively invokes method 'String.toUpperCase()' | ||
@RegisterForReflection(targets = String.class, fields = false) | ||
public class StringReflectionConfiguration { | ||
} | ||
|
||
// Needed as "${body} is TYPE" reflectively resolves 'java.nio.ByteBuffer' | ||
// at runtime | ||
@RegisterForReflection(targets = ByteBuffer.class, fields = false, methods = false) | ||
public class ByteBufferReflectionConfiguration { | ||
} | ||
|
||
} |
83 changes: 83 additions & 0 deletions
83
...n-tests/simple/src/main/java/org/apache/camel/quarkus/language/simple/SimpleResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* 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.language.simple; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
import javax.ws.rs.Consumes; | ||
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.ProducerTemplate; | ||
|
||
@Path("/simple") | ||
@ApplicationScoped | ||
public class SimpleResource { | ||
|
||
@Inject | ||
ProducerTemplate template; | ||
|
||
@Path("/filter") | ||
@GET | ||
@Consumes(MediaType.TEXT_PLAIN) | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String filter(boolean premium) { | ||
return template.requestBodyAndHeader("direct:filter-simple", "NOT-PREMIUM", "premium", premium, String.class); | ||
} | ||
|
||
@Path("/transform") | ||
@GET | ||
@Consumes(MediaType.TEXT_PLAIN) | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String transform(String user) { | ||
return template.requestBodyAndHeader("direct:transform-simple", null, "user", user, String.class); | ||
} | ||
|
||
@Path("/resource") | ||
@GET | ||
@Consumes(MediaType.TEXT_PLAIN) | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String resource(String body) { | ||
return template.requestBody("direct:resource-simple", body, String.class); | ||
} | ||
|
||
@Path("/mandatoryBodyAs") | ||
@GET | ||
@Consumes(MediaType.TEXT_PLAIN) | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String mandatoryBodyAs(byte[] body) { | ||
return template.requestBody("direct:mandatoryBodyAs-simple", body, String.class); | ||
} | ||
|
||
@Path("/bodyIs") | ||
@GET | ||
@Consumes(MediaType.TEXT_PLAIN) | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String mandatoryBodyAs(String body) { | ||
if ("A body of type String".equals(body)) { | ||
return template.requestBody("direct:bodyIs-simple", "STRING", String.class); | ||
} else { | ||
return template.requestBody("direct:bodyIs-simple", ByteBuffer.wrap(body.getBytes(StandardCharsets.UTF_8)), | ||
String.class); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...ion-tests/simple/src/main/java/org/apache/camel/quarkus/language/simple/SimpleRoutes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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.language.simple; | ||
|
||
import org.apache.camel.builder.RouteBuilder; | ||
|
||
public class SimpleRoutes extends RouteBuilder { | ||
|
||
@Override | ||
public void configure() { | ||
from("direct:filter-simple").filter().simple("${in.header.premium} == true").setBody(constant("PREMIUM")); | ||
|
||
from("direct:transform-simple").transform().simple("Hello ${in.header.user} !"); | ||
|
||
from("direct:resource-simple").transform().simple("resource:classpath:mysimple.txt"); | ||
|
||
from("direct:mandatoryBodyAs-simple").filter().simple("${mandatoryBodyAs(String).toUpperCase()} == 'GOLD'") | ||
.setBody(constant("PREMIUM")); | ||
|
||
from("direct:bodyIs-simple").filter().simple("${body} is 'java.nio.ByteBuffer'").setBody(constant("BYTE_BUFFER")); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
integration-tests/simple/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = *.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The name is ${body} |
Oops, something went wrong.