FreeMarker inline template (load from database) in Smooks not interpreted - inline

All,
I try to load the FreeMarker template from database in the Smooks configuration file and use the build-ins INTERPRET to parse the string as template. However, the output is exactly the template I stored in the database.
The following is part of the Smooks configuration file:
....
<resource-config selector="hs:TravelerProfile">
<resource>org.milyn.delivery.DomModelCreator</resource>
</resource-config>
<db:executor executeOnElement="hs:TravelerProfile" datasource="StagingDS">
<db:statement>select freeMarker_template from template_lookup where agencyid='111';
</db:statement>
<db:resultSet name="mytemplate" />
</db:executor>
<ftl:freemarker applyOnElementNS="www.travel.com" applyOnElement="TravelerProfile">
<ftl:template>
< !--
<#assign templateSource = r"${mytemplate[0].freeMarker_template}">
<#assign inlineTemplate = [templateSource, "myInlineTemplate"]?interpret>
<#inlineTemplate/>
-- >
</ftl:template>
</ftl:freemarker>
.....
The template I stored in the database is like following:
<#ftl ns_prefixes={"D":"www.hhs.gov/travel"}>
<?xml version="1.0" encoding="UTF-8"?>
<po:PoHeadersInterfaceCollection xmlns:po="https://www.travel.com/xmlns/financial/po112007.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.travel.com/xmlns/financial/po112007.xsd">
<po:PoHeadersInterface>
<po:interfaceSourceCode>VendorName</po:interfaceSourceCode>
<po:poLinesInterfaceCollection>
<po:PoLinesInterface>
<po:PoDistributionsInterfaceCollection>
<po:PoDistributionsInterface>
<po:destinationOrganizationId>${TravelerProfile.TravelerOfficeCode}
</po:destinationOrganizationId>
</po:PoDistributionsInterface>
</po:PoDistributionsInterfaceCollection>
</po:PoLinesInterface>
</po:poLinesInterfaceCollection>
</po:PoHeadersInterface>
</po:PoHeadersInterfaceCollection>
====================================
For some reason, the output is exactly the above template itself. "${TravelerProfile.TravelerOfficeCode}" has not been evaluated! Please help!!!
Thank you!!!
Agnes

Sine mytemplate[0].freeMarker_template returns the template source code itself (or at least I assume that), and since you are using a raw string literal (r"..."), the source code of your template will be literally ${mytemplate[0].freeMarker_template}, which is then evaluated by ?interpret to the template source code. The corrected template would be:
<#assign inlineTemplate = [mytemplate[0].freeMarker_template, "myInlineTemplate"]?interpret>
<#inlineTemplate/>
which can be also written as:
<#([mytemplate[0].freeMarker_template, "myInlineTemplate"]?interpret) />
or if you don't need the "myInlineTemplate" template name:
<#mytemplate[0].freeMarker_template?interpret />

Related

Azure Logic App outputs XML all in single line

I'm trying to convert a CSV to XML, which works perfectly fine when I test the map file in Visual Studio as I made sure the XSLT1.0 contains indent="yes". But for some reason when I repeat the steps in my Azure Logic App everything gets exported to one line:
<?xml version="1.0" encoding="utf-8"?><enfinity xsi:schemaLocation="http://www.fakewebsite.com/xml/ns/enfinity/7.1/bc_pricing/impex bc_pricing.xsd" major="6" minor="1" family="enfinity" branch="enterprise" build="build" xmlns="http://www.fakewebsite.com/xml/ns/enfinity/7.1/bc_pricing/impex" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dt="http://www.fakewebsite.com/xml/ns/enfinity/6.5/core/impex-dt"><product-price-list id="DEMarkdown" priceType="ES_SalePrice" import-mode="UPDATE"><display-name>DE Markdown</display-name><description /><enabled>true</enabled><priority>1</priority><target-groups><customer-segments><customer-segment id="Everyone" repository-id="WhiteStuff-DE-Anonymous" /><customer-segment id="IG_RegisteredUsers" repository-id="WhiteStuff-DE-Anonymous" /></customer-segments></target-groups><product-price-list-entry sku="433493126" import-mode="REPLACE"><price-scale-table type-code="1" currency="EUR"><valid-from>2021-07-06T00:00:00+00:00</valid-from><valid-to>2099-07-13T00:00:00+00:00</valid-to><price-scale-entries><fixed-price-entry quantity="1" unit=""><value>44.95</value></fixed-price-entry></price-scale-entries></price-scale-table><price-scale-table type-code="1" currency="GBP"><valid-from>2021-07-06T00:00:00+00:00</valid-from><valid-to>2099-07-13T00:00:00+00:00</valid-to><price-scale-entries><fixed-price-entry quantity="1" unit=""><value>39.50</value></fixed-price-entry></price-scale-entries></price-scale-table></product-price-list-entry></product-price-list></enfinity>
I have 2 ways for this
WAY-1
You can use the XML Validation connector before the process which parses the content into the right format.
WAY-2
Just for viewing purposes, you can do a request-response method using Postman then use XML format in order to achieve your requirement.
For those interested, I've found a setting within the Logic App, simply select Apply XSLT output attributes and that's it, no validation needed either!

gatling checking if soap response contains node

I use Gatling to test against an API responding with this:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<sam:HentAktiveSamtykkerMedPartrefResponse xmlns:sam="urn:gjensidige:forsikring:samtykke">
<sam:samtykke>
<sam:idNr>01018448285</sam:idNr>
<sam:partref>0005009147</sam:partref>
<sam:utfortAv></sam:utfortAv>
<sam:navn></sam:navn>
<sam:navnUtvidet></sam:navnUtvidet>
<sam:svar>J</sam:svar>
How can I script that the response must contain the element:
<sam:svar>
?
I guess something in the lines of:
.check(xpath("whathere").exists)
But what should be stated as "whathere"?
The xpath would look something like : /*/SOAP-ENV:Body/descendant::*[name()='sam:navn']/text() this should extract the value from <sam:navn></sam:navn>.

Salesforce Bulk API - "missing a mapping for the external id field" error

I'm starting a bulk API job and passing a spec file. Here is the job.txt file I'm using to create the job:
<?xml version="1.0" encoding="UTF-8"?>
<jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload">
<operation>upsert</operation>
<object>Contact</object>
<externalIdFieldName>Unique_Email__c</externalIdFieldName>
<contentType>CSV</contentType>
</jobInfo>
Then, I'm posting a spec file as follows:
Salesforce Field,Csv Header,Value,Hint
Unique_Email__c,email1,,
Name,Full Name,,
And I get the error "Transformation specification is missing a mapping for the external id field" but that's very strange because the Unique_Email__c is actually there. What's going on?

How to get right attribute which contain "&" through libxml2

When I try to get the attribute of URL in a test XML:
<Test> <Item URL="http://127.0.0.1?a=1&b=2"/>
</Test>
After I call: attr=xmlGetProp(cur, BAD_CAST "URL");
The libxml2 give a message: Entity: line 1: parser error : EntityRef: expecting ';'
and return value of attr is "http://127.0.0.1?a=1=2"
How can I get the completion attribution of URL? Thanks
You cannot get the “correct” URL here because the XML file is not well-formed. the & should have been written as &. You have to ask the creator of the XML file to create a syntactically valid, well-formed XML file.
XML is not created by just putting strings together, they also have to be encoded properly.

ibatis - where to place the <cacheModel> tag?

I have the map config file like this
<sqlMap ..............>
<alias>
<typeAlias ......../>
</alias>
<statements>
....
<sql>....</sql>
<select cacheModel="cache-select-all">....</select>
<update>...</update>
<procedure>...</procedure>
.....
</statements>
<parameterMaps>
<parameterMap>....</parameterMap>
</parameterMaps>
<cacheModel id="cache-select-all" type="LRU" readOnly="true" serialize="false">
<flushInterval hours="24"/>
<flushOnExecute statement="InsertIOs"/>
<!--<property name="CacheSize" value="1000"/>-->
</cacheModel>
</sqlMap>
I am using ibatis (.net, if that matters) and i have one question: where to place the tags? is There a or because placing it like i did, in the statements seems not to work. What am i doing wrong?
You must reference the cacheModel you defined inside a statement tag as shown in the following link:
http://ibatis.apache.org/docs/dotnet/datamapper/ch03s08.html
Before you use it in the select statement. Order does matter here. Otherwise sql map parser wouldn't be able to validate your sql map.

Resources