Freemarker

JVM since1.1.0 Native since1.8.0

Transform messages using FreeMarker templates.

What’s inside

Please refer to the above link for usage and configuration details.

Maven coordinates

Or add the coordinates to your existing project:

<dependency>
    <groupId>org.apache.camel.quarkus</groupId>
    <artifactId>camel-quarkus-freemarker</artifactId>
</dependency>

Check the User guide for more information about writing Camel Quarkus applications.

allowContextMapAll option in native mode

The allowContextMapAll option is not supported in native mode as it requires reflective access to security sensitive camel core classes such as CamelContext & Exchange. This is considered a security risk and thus access to the feature is not provided by default.

Additional Camel Quarkus configuration

Class path resources

For the FreeMarker templates loaded from class path to work flawlessly in native mode, you need to list all your template files using quarkus.native.resources.includes and quarkus.native.resources.excludes options in application.properties.

Here is an example: If your application’s resources look like this

$ tree src/main/resources
src/main/resources
└── templates
    ├── email.ftl
    ├── page.html
    └── unwanted-file.txt

and if your configuration is like this

quarkus.native.resources.includes = templates/*.ftl,templates/*.html
quarkus.native.resources.excludes = templates/unwanted*

then, resources templates/email.ftl and templates/page.ftl will be available in the native image, while file unwanted-file.txt will not be available.

You can thus use the available templates in a Camel route, e.g.:

public class MyRoutes extends RouteBuilder {
    @Override
    public void configure() {
        from("direct:example")
            .to("freemarker:templates/email.ftl")
    }
}

Quarkiverse Freemarker and its configuration

Camel Quarkus Freemarker uses dev/index.html[Quarkiverse Freemarker] under the hood. This means in particular, that the freemarker.template.Configuration bean produced by Quarkiverse Freemarker is used by Camel Quarkus. The bean can be configured via quarkus.freemarker.* properties - check Freemarker Configuration Reference for more details.

If you wish to use your custom Configuration bean instead of the default provided by Quarkiverse Freemarker, you can let CDI to do the required wiring:

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Named;
import freemarker.template.Configuration;
import io.quarkus.arc.Unremovable;
import org.apache.camel.builder.RouteBuilder;

@ApplicationScoped
public class MyRoutes extends RouteBuilder {

    @Produces
    @ApplicationScoped
    @Unremovable
    @Named("myFreemarkerConfig")
    Configuration produceFreemarkerConfig() {
        Configuration result = new Configuration();
        ...
        return result;
    }

    @Override
    public void configure() {
        from("direct:example")
            .to("freemarker:templates/email.ftl?configuration=myFreemarkerConfig")

    }
}