Skip to content

Commit

Permalink
Add header details and examples to Qute documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnetherton committed Oct 17, 2024
1 parent ff07ba2 commit e272077
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 1 deletion.
105 changes: 105 additions & 0 deletions docs/modules/ROOT/pages/reference/extensions/qute.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,111 @@ endif::[]
== Usage
include::partial$component-configure-options.adoc[]
include::partial$component-endpoint-options.adoc[]
include::partial$component-endpoint-headers.adoc[]

[id="extensions-qute-usage-qute-template-data"]
=== Qute template data

Camel will populate the Qute `TemplateInstance` data model with exchange information. The following options are available within Qute templates as variables:

[width="100%",cols="50%,50%",options="header",]
|=======================================================================
|key |value

|`exchange` |The `Exchange` itself.

|`exchange.properties` |The `Exchange` properties.

|`variables` |The exchange variables

|`headers` |The headers of the In message.

|`camelContext` |The Camel Context.

|`request` |The In message.

|`body` |The In message body.

|`response` |The Out message (only for InOut message exchange pattern).
|=======================================================================

You can configure your own template data with the message header `CamelQuteTemplateData` like this.

[source,java]
--------------------------------------------------------------------
Map<String, Object> variableMap = new HashMap<String, Object>();
variableMap.put("headers", headersMap);
variableMap.put("body", "Monday");
variableMap.put("exchange", exchange);
exchange.getMessage().setHeader("CamelQuteTemplateData", variableMap);
--------------------------------------------------------------------

[id="extensions-qute-usage-dynamic-templates"]
=== Dynamic templates

Camel provides headers `CamelQuteResourceUri`, `CamelQuteTemplate` and `CamelQuteTemplateInstance` which can be used to define a different resource
location for a template, or provide the template instance itself. If any of these headers is set, then Camel uses this over
the endpoint configured resource. This allows you to provide a dynamic template at runtime.

[id="extensions-qute-usage-examples"]
=== Examples

Processing an exchange with a Qute template read from the classpath.

[source,java]
-------------------------------------------
from("direct:start")
.to("qute:org/acme/myTemplate.txt");
-------------------------------------------

Processing an exchange with a Qute template read from a file-based resource.

[source,java]
-------------------------------------------
from("direct:start")
.to("qute:file://path/to/myTemplate.txt");
-------------------------------------------

Dynamic template path URI.

[source,java]
---------------------------------------------------------------------------------------------
from("direct:start")
.setHeader(QuteConstants.QUTE_RESOURCE_URI).constant("org/acme/template.txt")
.to("qute:dynamic?allowTemplateFromHeader=true");
---------------------------------------------------------------------------------------------

Dynamic template content.

[source,java]
---------------------------------------------------------------------------------------------
from("direct:start")
.setHeader(QuteConstants.QUTE_TEMPLATE).constant("<hello>{headers.greeting}</hello>")
.to("qute:dynamic?allowTemplateFromHeader=true");
---------------------------------------------------------------------------------------------

Dynamic template instance.

[source,java]
---------------------------------------------------------------------------------------------
from("direct:start")
.setHeader(QuteConstants.QUTE_TEMPLATE_INSTANCE).constant(myTemplateInstance)
.to("qute:dynamic?allowTemplateFromHeader=true");
---------------------------------------------------------------------------------------------

Qute template example.

----------------------------------------------
Dear {headers.lastName}, {headers.firstName}
Thanks for the order of {headers.item}.
Regards Camel Riders Bookstore
{body}
----------------------------------------------

[id="extensions-qute-usage-quarkus-qute-documentation"]
=== Quarkus Qute documentation

For more information about Qute, please refer to the https://quarkus.io/guides/qute[Quarkus Qute] documentation.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
"autowiredEnabled": { "index": 2, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc." },
"quteEngine": { "index": 3, "kind": "property", "displayName": "Qute Engine", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "io.quarkus.qute.Engine", "deprecated": false, "autowired": false, "secret": false, "description": "To use the Engine otherwise a new engine is created" }
},
"headers": {
"CamelQuteResourceUri": { "index": 0, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "A URI for the template resource to use instead of the endpoint configured one.", "constantName": "org.apache.camel.component.qute.QuteConstants#QUTE_RESOURCE_URI" },
"CamelQuteTemplate": { "index": 1, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The template to use instead of the endpoint configured one.", "constantName": "org.apache.camel.component.qute.QuteConstants#QUTE_TEMPLATE" },
"CamelQuteTemplateInstance": { "index": 2, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "TemplateInstance", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The template instance to use instead of the endpoint configured one.", "constantName": "org.apache.camel.component.qute.QuteConstants#QUTE_TEMPLATE_INSTANCE" },
"CamelQuteTemplateData": { "index": 3, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "Map", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The template model data.", "constantName": "org.apache.camel.component.qute.QuteConstants#QUTE_TEMPLATE_DATA" }
},
"properties": {
"resourceUri": { "index": 0, "kind": "path", "displayName": "Resource Uri", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "supportFileReference": true, "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." },
"allowContextMapAll": { "index": 1, "kind": "parameter", "displayName": "Allow Context Map All", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Sets whether the context map should allow access to all details. By default only the message body and headers can be accessed. This option can be enabled for full access to the current Exchange and CamelContext. Doing so impose a potential security risk as this opens access to the full power of CamelContext API." },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@
*/
package org.apache.camel.component.qute;

import org.apache.camel.spi.Metadata;

public final class QuteConstants {
@Metadata(description = "A URI for the template resource to use instead of the endpoint configured one.", javaType = "String")
public static final String QUTE_RESOURCE_URI = "CamelQuteResourceUri";
@Metadata(description = "The template to use instead of the endpoint configured one.", javaType = "String")
public static final String QUTE_TEMPLATE = "CamelQuteTemplate";
@Metadata(description = "The template instance to use instead of the endpoint configured one.", javaType = "TemplateInstance")
public static final String QUTE_TEMPLATE_INSTANCE = "CamelQuteTemplateInstance";
@Metadata(description = "The template model data.", javaType = "Map")
public static final String QUTE_TEMPLATE_DATA = "CamelQuteTemplateData";

private QuteConstants() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
/**
* Transforms the message using a Quarkus Qute template.
*/
@UriEndpoint(firstVersion = "3.2.0", scheme = "qute", title = "Qute", syntax = "qute:resourceUri", producerOnly = true, category = Category.TRANSFORMATION)
@UriEndpoint(firstVersion = "3.2.0", scheme = "qute", title = "Qute", syntax = "qute:resourceUri", producerOnly = true, category = Category.TRANSFORMATION, headersClass = QuteConstants.class)
public class QuteEndpoint extends ResourceEndpoint {
private Engine quteEngine;

Expand Down
101 changes: 101 additions & 0 deletions extensions/qute/runtime/src/main/doc/usage.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,105 @@
include::partial$component-configure-options.adoc[]
include::partial$component-endpoint-options.adoc[]
include::partial$component-endpoint-headers.adoc[]

=== Qute template data

Camel will populate the Qute `TemplateInstance` data model with exchange information. The following options are available within Qute templates as variables:

[width="100%",cols="50%,50%",options="header",]
|=======================================================================
|key |value

|`exchange` |The `Exchange` itself.

|`exchange.properties` |The `Exchange` properties.

|`variables` |The exchange variables

|`headers` |The headers of the In message.

|`camelContext` |The Camel Context.

|`request` |The In message.

|`body` |The In message body.

|`response` |The Out message (only for InOut message exchange pattern).
|=======================================================================

You can configure your own template data with the message header `CamelQuteTemplateData` like this.

[source,java]
--------------------------------------------------------------------
Map<String, Object> variableMap = new HashMap<String, Object>();
variableMap.put("headers", headersMap);
variableMap.put("body", "Monday");
variableMap.put("exchange", exchange);
exchange.getMessage().setHeader("CamelQuteTemplateData", variableMap);
--------------------------------------------------------------------

=== Dynamic templates

Camel provides headers `CamelQuteResourceUri`, `CamelQuteTemplate` and `CamelQuteTemplateInstance` which can be used to define a different resource
location for a template, or provide the template instance itself. If any of these headers is set, then Camel uses this over
the endpoint configured resource. This allows you to provide a dynamic template at runtime.

=== Examples

Processing an exchange with a Qute template read from the classpath.

[source,java]
-------------------------------------------
from("direct:start")
.to("qute:org/acme/myTemplate.txt");
-------------------------------------------

Processing an exchange with a Qute template read from a file-based resource.

[source,java]
-------------------------------------------
from("direct:start")
.to("qute:file://path/to/myTemplate.txt");
-------------------------------------------

Dynamic template path URI.

[source,java]
---------------------------------------------------------------------------------------------
from("direct:start")
.setHeader(QuteConstants.QUTE_RESOURCE_URI).constant("org/acme/template.txt")
.to("qute:dynamic?allowTemplateFromHeader=true");
---------------------------------------------------------------------------------------------

Dynamic template content.

[source,java]
---------------------------------------------------------------------------------------------
from("direct:start")
.setHeader(QuteConstants.QUTE_TEMPLATE).constant("<hello>{headers.greeting}</hello>")
.to("qute:dynamic?allowTemplateFromHeader=true");
---------------------------------------------------------------------------------------------

Dynamic template instance.

[source,java]
---------------------------------------------------------------------------------------------
from("direct:start")
.setHeader(QuteConstants.QUTE_TEMPLATE_INSTANCE).constant(myTemplateInstance)
.to("qute:dynamic?allowTemplateFromHeader=true");
---------------------------------------------------------------------------------------------

Qute template example.

----------------------------------------------
Dear {headers.lastName}, {headers.firstName}
Thanks for the order of {headers.item}.
Regards Camel Riders Bookstore
{body}
----------------------------------------------

=== Quarkus Qute documentation

For more information about Qute, please refer to the https://quarkus.io/guides/qute[Quarkus Qute] documentation.

0 comments on commit e272077

Please sign in to comment.