[ 
https://issues.apache.org/jira/browse/CAMEL-22772?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen resolved CAMEL-22772.
---------------------------------
    Resolution: Fixed

> Freemarker shared variables not respected when using dynamic templates
> ----------------------------------------------------------------------
>
>                 Key: CAMEL-22772
>                 URL: https://issues.apache.org/jira/browse/CAMEL-22772
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-freemarker
>    Affects Versions: 4.16.0
>            Reporter: Bartosz Popiela
>            Priority: Minor
>             Fix For: 4.14.3, 4.17.0
>
>
> I have a ComponentCustomizer which provides a custom Freemarker method:
> {code:java}
> @BindToRegistry(lazy=true)
> public ComponentCustomizer freemarkerCustomizer(@BeanInject CacheService 
> cacheService) {
>     return new ComponentCustomizer() {
>         private final BeansWrapper beansWrapper =
>                 new 
> BeansWrapperBuilder(freemarker.template.Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS).build();
>         @Override
>         public void configure(String name, Component component) {
>             try {
>                 configure((FreemarkerComponent) component);
>             } catch (TemplateModelException e) {
>                 throw new RuntimeException(e);
>             }
>         }
>         private void configure(FreemarkerComponent component) throws 
> TemplateModelException {
>             var configuration = component.getConfiguration();
>             configuration.setRecognizeStandardFileExtensions(true);
>             
> configuration.setRegisteredCustomOutputFormats(List.of(SafeJsonOutputFormat.INSTANCE));
>             configuration.setSharedVariable("customMethod", new 
> MyCustomMethod());
>             component.setConfiguration(configuration); // This is necessary 
> because FreemarkerComponent#getConfiguration returns a cloned object
>         }
>         @Override
>         public boolean isEnabled(String name, Component target) {
>             return target instanceof FreemarkerComponent;
>         }
>     };
> } {code}
> When passing a template with the CamelFreemarkerTemplate header, 
> FreemarkerEndpoint creates a new freemarker.template.Configuration which 
> doesn't provide my customMethod.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to