Hello,

I found the solution for this.
>From Camel 2.25.2/3.4.0 onward you need to add this property to the
freemarker producer: allowContextMapAll=true. Otherwise you'll only have
access to body/headers in a template engine like Freemarker.
This is based on https://issues.apache.org/jira/browse/CAMEL-15050

Thanks for helping on the chat!

Regards,
Laurentiu

On Thu, Nov 18, 2021 at 3:45 PM Laurentiu Trica <[email protected]>
wrote:

> Hello,
>
> I've been using Camel 2.16 with Freemarker 2.3.23.stable on Karaf 4.0.4
> for a long time now.
> I'm switching to Camel 2.25.4 with Freemarker 2.3.31.stable on Karaf 4.3.3
> now.
>
> The problem is that something that worked without problems with the old
> setup is now not working. When I have something like this in a freemarker
> template:
> ${request.setHeader('someHeader', 'some value')}
>
> I get this error: *The following has evaluated to null or missing:*
> *==> request  [in template "xml.ftl" at line 434, column 3]*
>
> Using ${body} is working, using ${headers} is also working, so I don't
> know why ${request} wouldn't work...
>
> Can you please help me solve this?
>
> Many thanks!
> Laurentiu
>
> Full stack trace below:
> 2021-11-18T13:28:29,457 | ERROR | Camel (camelContext) thread #99 -
> file://data/endpoints/IN | DefaultErrorHandler              | 56 -
> org.apache.camel.camel-core - 2.25.4 | Failed delivery for (MessageId:
> ID-4205717fa667-1637237151718-6-9 on ExchangeId:
> ID-4205717fa667-1637237151718-6-1). Exhausted after delivery attempt: 1
> caught: freemarker.core.InvalidReferenceException: *The following has
> evaluated to null or missing:\n==> request*  [in template "xml.ftl" at
> line 434, column 3]\n\n----\nTip: If the failing expression is known to
> legally refer to something that's sometimes null or missing, either specify
> a default value like myOptionalV
> java.lang.IllegalArgumentException: Transaction stopped on error
> at
> jdk.internal.reflect.GeneratedConstructorAccessor103.newInstance(Unknown
> Source) ~[?:?]
> at
> jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
> ~[?:?]
> at
> java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
> ~[?:?]
> at java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[?:?]
> at
> org.apache.aries.blueprint.utils.ReflectionUtils.newInstance(ReflectionUtils.java:369)
> ~[!/:1.10.3]
> at
> org.apache.aries.blueprint.container.BeanRecipe.newInstance(BeanRecipe.java:839)
> ~[!/:1.10.3]
> at
> org.apache.aries.blueprint.container.BeanRecipe.getInstanceFromType(BeanRecipe.java:350)
> ~[!/:1.10.3]
> at
> org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:283)
> ~[!/:1.10.3]
> at
> org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:685)
> ~[!/:1.10.3]
> at
> org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:666)
> ~[!/:1.10.3]
> at
> org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:81)
> ~[!/:1.10.3]
> at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
> at
> org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:90)
> ~[!/:1.10.3]
> at
> org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:360)
> ~[!/:1.10.3]
> at
> org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:190)
> ~[!/:1.10.3]
> at
> org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:737)
> ~[!/:1.10.3]
> at
> org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:433)
> ~[!/:1.10.3]
> at
> org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:298)
> ~[!/:1.10.3]
> at
> org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:335)
> ~[!/:1.10.3]
> at
> org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:288)
> ~[!/:1.10.3]
> at
> org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:284)
> ~[!/:1.10.3]
> at
> org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:274)
> ~[!/:1.10.3]
> at
> org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500)
> ~[!/:1.1.3]
> at
> org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433)
> ~[!/:1.1.3]
> at
> org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725)
> ~[!/:1.1.3]
> at
> org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463)
> ~[!/:1.1.3]
> at
> org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422)
> ~[!/:1.1.3]
> at
> org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1180)
> ~[?:?]
> at
> org.apache.felix.framework.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:730)
> ~[?:?]
> at
> org.apache.felix.framework.EventDispatcher.fireBundleEvent(EventDispatcher.java:485)
> ~[?:?]
> at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4817) ~[?:?]
> at org.apache.felix.framework.Felix.startBundle(Felix.java:2336) ~[?:?]
> at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998) ~[?:?]
> at
> org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260)
> ~[?:?]
> at
> org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233)
> ~[?:?]
> at
> org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1221)
> ~[?:?]
> at
> org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:515)
> ~[?:?]
> at
> org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365)
> ~[?:?]
> at
> org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316)
> ~[?:?]
> Suppressed: freemarker.core.InvalidReferenceException:
> *The following has evaluated to null or missing:==> request  [in template
> "xml.ftl" at line 434, column 3]*
>
> ----
> Tip: If the failing expression is known to legally refer to something
> that's sometimes null or missing, either specify a default value like
> myOptionalVar!myDefault, or use <#if
> myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover
> the last step of the expression; to cover the whole expression, use
> parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
> ----
>
> ----
> FTL stack trace ("~" means nesting-related):
> - Failed at: ${request.setHeader("error_on_parcel_...  [in template
> "xml.ftl" at line 434, column 1]
> ----
> at
> freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:134)
> ~[!/:2.3.31]
> at
> freemarker.core.UnexpectedTypeException.newDescriptionBuilder(UnexpectedTypeException.java:85)
> ~[!/:2.3.31]
> at
> freemarker.core.UnexpectedTypeException.<init>(UnexpectedTypeException.java:48)
> ~[!/:2.3.31]
> at freemarker.core.NonHashException.<init>(NonHashException.java:49)
> ~[!/:2.3.31]
> at freemarker.core.Dot._eval(Dot.java:48) ~[!/:2.3.31]
> at freemarker.core.Expression.eval(Expression.java:101) ~[!/:2.3.31]
> at freemarker.core.MethodCall._eval(MethodCall.java:55) ~[!/:2.3.31]
> at freemarker.core.Expression.eval(Expression.java:101) ~[!/:2.3.31]
> at
> freemarker.core.DollarVariable.calculateInterpolatedStringOrMarkup(DollarVariable.java:100)
> ~[!/:2.3.31]
> at freemarker.core.DollarVariable.accept(DollarVariable.java:63)
> ~[!/:2.3.31]
> at freemarker.core.Environment.visit(Environment.java:347) ~[!/:2.3.31]
> at freemarker.core.Environment.visit(Environment.java:353) ~[!/:2.3.31]
> at freemarker.core.Environment.process(Environment.java:326) ~[!/:2.3.31]
> at freemarker.template.Template.process(Template.java:383) ~[!/:2.3.31]
> at
> org.apache.camel.component.freemarker.FreemarkerEndpoint.onExchange(FreemarkerEndpoint.java:182)
> ~[!/:2.25.4]
> at
> org.apache.camel.impl.ProcessorEndpoint$1.process(ProcessorEndpoint.java:71)
> ~[!/:2.25.4]
> at
> org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
> ~[!/:2.25.4]
> at
> org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148)
> ~[!/:2.25.4]
> at
> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548)
> [!/:2.25.4]
> at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
> [!/:2.25.4]
> at org.apache.camel.processor.Pipeline.process(Pipeline.java:138)
> [!/:2.25.4]
> at org.apache.camel.processor.Pipeline.process(Pipeline.java:101)
> [!/:2.25.4]
> at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
> [!/:2.25.4]
> at
> org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:452)
> [!/:2.25.4]
> at
> org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:221)
> [!/:2.25.4]
> at
> org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:185)
> [!/:2.25.4]
> at
> org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174)
> [!/:2.25.4]
> at
> org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101)
> [!/:2.25.4]
> at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
> [?:?]
> at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) [?:?]
> at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
> [?:?]
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
> [?:?]
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
> [?:?]
> at java.lang.Thread.run(Thread.java:831) [?:?]
>


-- 
Laurentiu Trica
Software Developer             Mobile: (+40) 722 329318
S.C MoreDevs S.R.L.          Email: [email protected]

This message can contain privileged or confidential information and it is
intended only for addressee. Any unauthorized disclosure is strictly
prohibited.

Reply via email to