Smooks freemarker transformation fails in SOA-P 5 if input data contains namespaces
Issue
We want to use Smooks to transform an XML stream into a different one using the templating mechanism provided by Freemarker. The service is exposed as ESB webservice:
<actions inXsd="SmooksIssueWS.xsd" mep="RequestResponse">
<action name="print-input-soap-message" class="org.jboss.soa.esb.actions.SystemPrintln" />
<action name="transform" class="org.jboss.soa.esb.smooks.SmooksAction">
<property name="smooksConfig" value="/smooks-res.xml" />
<property name="resultType" value="STRING" />
</action>
<action name="print-xml-result" class="org.jboss.soa.esb.actions.SystemPrintln" />
</actions>
Smooks transformation file (smooks-res.xml):
<?xml version='1.0' encoding='UTF-8'?>
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd"
xmlns:esbr="http://www.jboss.org/xsd/jbossesb/smooks/routing-1.0.xsd">
<!-- Capture data from the incoming message into DOM models. These are then avaiable to
templating etc... -->
<resource-config selector="sayHi">
<resource>org.milyn.delivery.DomModelCreator</resource>
</resource-config>
<ftl:freemarker applyOnElement="sayHi">
<ftl:template>/templates/soap-to-plain-xml.ftl</ftl:template>
</ftl:freemarker>
</smooks-resource-list>
Freemarker template file (soap-to-plain-xml.ftl):
<root>
<args>
<arg>${sayHi.arg}</arg>
</args>
</root>
When running this sample and providing input data using SoapUI, the transformation fails with the following ERROR:
ERROR [runtime]
Error on line 3, column 11 in templates/soap-to-plain-xml.ftl
Expecting a string, date or number here, Expression sayHi.arg is instead a freemarker.ext.dom.NodeListModel
The problematic instruction:
----------
==> ${sayHi.arg} [on line 3, column 9 in templates/soap-to-plain-xml.ftl]
----------
Java backtrace for programmers:
----------
freemarker.core.NonStringException: Error on line 3, column 11 in templates/soap-to-plain-xml.ftl
Expecting a string, date or number here, Expression sayHi.arg is instead a freemarker.ext.dom.NodeListModel
at freemarker.core.Expression.getStringValue(Expression.java:126)
at freemarker.core.Expression.getStringValue(Expression.java:93)
at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
at freemarker.core.Environment.visit(Environment.java:209)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:209)
at freemarker.core.Environment.process(Environment.java:189)
at freemarker.template.Template.process(Template.java:237)
at org.milyn.templating.freemarker.FreeMarkerTemplateProcessor.applyTemplate(FreeMarkerTemplateProcessor.java:207)
at org.milyn.templating.freemarker.FreeMarkerTemplateProcessor.visitAfter(FreeMarkerTemplateProcessor.java:179)
Environment
- JBoss Enterprise SOA Platform (SOA-P)
- 4.3
- 5.x
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.