Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions components/camel-qute/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.camel</groupId>
<artifactId>components</artifactId>
<version>3.2.0-SNAPSHOT</version>
</parent>

<artifactId>camel-qute</artifactId>
<packaging>jar</packaging>
<name>Camel :: Qute</name>
<description>Camel Qute support</description>

<dependencies>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-support</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-qute</artifactId>
<version>${qute-version}</version>
<exclusions>
<exclusion>
<groupId>org.jboss.slf4j</groupId>
<artifactId>slf4j-jboss-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* Generated by camel build tools - do NOT edit this file! */
package org.apache.camel.component.qute;

import org.apache.camel.CamelContext;
import org.apache.camel.spi.GeneratedPropertyConfigurer;
import org.apache.camel.support.component.PropertyConfigurerSupport;

/**
* Generated by camel build tools - do NOT edit this file!
*/
@SuppressWarnings("unchecked")
public class QuteComponentConfigurer extends PropertyConfigurerSupport implements GeneratedPropertyConfigurer {

@Override
public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) {
QuteComponent target = (QuteComponent) obj;
switch (ignoreCase ? name.toLowerCase() : name) {
case "basicpropertybinding":
case "basicPropertyBinding": target.setBasicPropertyBinding(property(camelContext, boolean.class, value)); return true;
case "lazystartproducer":
case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
case "quteengine":
case "quteEngine": target.setQuteEngine(property(camelContext, io.quarkus.qute.Engine.class, value)); return true;
default: return false;
}
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* Generated by camel build tools - do NOT edit this file! */
package org.apache.camel.component.qute;

import org.apache.camel.CamelContext;
import org.apache.camel.spi.GeneratedPropertyConfigurer;
import org.apache.camel.support.component.PropertyConfigurerSupport;

/**
* Generated by camel build tools - do NOT edit this file!
*/
@SuppressWarnings("unchecked")
public class QuteEndpointConfigurer extends PropertyConfigurerSupport implements GeneratedPropertyConfigurer {

@Override
public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) {
QuteEndpoint target = (QuteEndpoint) obj;
switch (ignoreCase ? name.toLowerCase() : name) {
case "basicpropertybinding":
case "basicPropertyBinding": target.setBasicPropertyBinding(property(camelContext, boolean.class, value)); return true;
case "contentcache":
case "contentCache": target.setContentCache(property(camelContext, boolean.class, value)); return true;
case "encoding": target.setEncoding(property(camelContext, java.lang.String.class, value)); return true;
case "lazystartproducer":
case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
case "synchronous": target.setSynchronous(property(camelContext, boolean.class, value)); return true;
default: return false;
}
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Generated by camel build tools - do NOT edit this file!
components=qute
groupId=org.apache.camel
artifactId=camel-qute
version=3.2.0-SNAPSHOT
projectName=Camel :: Qute
projectDescription=Camel Qute support
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated by camel build tools - do NOT edit this file!
class=org.apache.camel.component.qute.QuteComponent
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated by camel build tools - do NOT edit this file!
class=org.apache.camel.component.qute.QuteComponentConfigurer
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated by camel build tools - do NOT edit this file!
class=org.apache.camel.component.qute.QuteEndpointConfigurer
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"component": {
"kind": "component",
"scheme": "qute",
"extendsScheme": "",
"syntax": "qute:resourceUri",
"title": "Qute",
"description": "Transforms the message using a Quarkus Qute template.",
"label": "transformation",
"deprecated": false,
"async": false,
"consumerOnly": false,
"producerOnly": true,
"lenientProperties": false,
"javaType": "org.apache.camel.component.qute.QuteComponent",
"firstVersion": "3.2.0",
"groupId": "org.apache.camel",
"artifactId": "camel-qute",
"version": "3.2.0-SNAPSHOT"
},
"componentProperties": {
"lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing." },
"basicPropertyBinding": { "kind": "property", "displayName": "Basic Property Binding", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities" },
"quteEngine": { "kind": "property", "displayName": "Qute Engine", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "io.quarkus.qute.Engine", "deprecated": false, "secret": false, "description": "To use the Engine otherwise a new engine is created" }
},
"properties": {
"resourceUri": { "kind": "path", "displayName": "Resource Uri", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "secret": false, "description": "Path to the resource. You can prefix with: classpath, file, http, ref, or bean. classpath, file and http loads the resource using these protocols (classpath is default). ref will lookup the resource in the registry. bean will call a method on a bean to be used as the resource. For bean you can specify the method name after dot, eg bean:myBean.myMethod." },
"contentCache": { "kind": "parameter", "displayName": "Content Cache", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": "false", "description": "Sets whether to use resource content cache or not" },
"encoding": { "kind": "parameter", "displayName": "Encoding", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "description": "Character encoding of the resource content." },
"lazyStartProducer": { "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing." },
"basicPropertyBinding": { "kind": "parameter", "displayName": "Basic Property Binding", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the endpoint should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities" },
"synchronous": { "kind": "parameter", "displayName": "Synchronous", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": "false", "description": "Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported)." }
}
}
136 changes: 136 additions & 0 deletions components/camel-qute/src/main/docs/qute-component.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
[[qute-component]]
= Qute Component

*Since Camel 3.2*

// HEADER START
*Only producer is supported*
// HEADER END

The Qute component allows you to process a message using an
https://quarkus.io/guides/qute[Quarkus Qute] template. This can be ideal
when using Templating to generate responses for
requests.

Maven users will need to add the following dependency to their `pom.xml`
for this component:

[source,xml]
------------------------------------------------------------
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-qute</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
------------------------------------------------------------

== URI format

[source,java]
-------------------------------
qute:templateName[?options]
-------------------------------

Where *templateName* is the classpath-local URI of the template to
invoke; or the complete URL of the remote template (eg:
\file://folder/myfile.txt).

You can append query options to the URI in the following format,
`?option=value&option=value&...`

== Options
// component options: START
The Qute component supports 3 options, which are listed below.



[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean
| *basicPropertyBinding* (advanced) | Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
| *quteEngine* (advanced) | To use the Engine otherwise a new engine is created | | Engine
|===
// component options: END

// endpoint options: START
The Qute endpoint is configured using URI syntax:

----
qute:resourceUri
----

with the following path and query parameters:

=== Path Parameters (1 parameters):


[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *resourceUri* | *Required* Path to the resource. You can prefix with: classpath, file, http, ref, or bean. classpath, file and http loads the resource using these protocols (classpath is default). ref will lookup the resource in the registry. bean will call a method on a bean to be used as the resource. For bean you can specify the method name after dot, eg bean:myBean.myMethod. | | String
|===


=== Query Parameters (5 parameters):


[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *contentCache* (producer) | Sets whether to use resource content cache or not | false | boolean
| *encoding* (producer) | Character encoding of the resource content. | | String
| *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean
| *basicPropertyBinding* (advanced) | Whether the endpoint should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
| *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean
|===
// endpoint options: END
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add a new section with one or two examples to the docs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I will add the examples.


== Message Headers

You can use the following headers on the message:

[width="100%",cols="10%,90%",options="header",]
|=======================================================================
|Header |Description

|`CamelQuteResourceUri` |The *templateName* as a `String` object.

|`CamelQuteTemplate` | The *content* of template as a `String` object.

|`CamelQuteTemplateData` |To add additional information used in the template.
The value of this data should be a `Map` with key/values that will
added (override any existing key with the same name).
|=======================================================================


== Samples

For example you could use this component to render the data just like

[source,java]
----------------------------------------
from("activemq:My.Queue").
to("qute:org/example/hello.txt");
----------------------------------------

It's possible to specify what template the component
should use dynamically via a header, so for example:

[source,java]
---------------------------------------------------------------------------
from("direct:in").
setHeader("CamelQuteResourceUri").constant("path/to/my/template.txt").
to("qute:dummy");
---------------------------------------------------------------------------

It's possible to specify a template directly as a header
the component should use dynamically via a header, so for example:

[source,java]
---------------------------------------------------------------------------------------------------------------
from("direct:in").
setHeader("CamelQuteTemplate").constant("Hi this is a qute template that can do templating {body}").
to("qute:dummy");
---------------------------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.component.qute;

import java.util.Map;

import io.quarkus.qute.Engine;
import org.apache.camel.Endpoint;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.annotations.Component;
import org.apache.camel.support.DefaultComponent;
import org.apache.camel.support.ResourceHelper;

@Component("qute")
public class QuteComponent extends DefaultComponent {

@Metadata(label = "advanced")
private Engine quteEngine;

public QuteComponent() {
}

public Engine getQuteEngine() {
return quteEngine;
}
/**
* To use the {@link Engine} otherwise a new engine is created
*/
public void setQuteEngine(Engine quteEngine) {
this.quteEngine = quteEngine;
}

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
boolean cache = getAndRemoveParameter(parameters, "contentCache", Boolean.class, Boolean.TRUE);

QuteEndpoint answer = new QuteEndpoint(uri, this, remaining);
setProperties(answer, parameters);
answer.setContentCache(cache);
answer.setQuteEngine(quteEngine);

// if its a http resource then append any remaining parameters and update the resource uri
if (ResourceHelper.isHttpUri(remaining)) {
remaining = ResourceHelper.appendParameters(remaining, parameters);
answer.setResourceUri(remaining);
}

return answer;
}
}
Loading