4

I'm trying to set this expression in order to obtain the output file name as a concat between the name of the city and the extention of the file:

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="WriteFile_City" xmlns="http://ws.apache.org/ns/synapse">
<property expression="concat(json-eval($.city.name),'.xml')"
    name="transport.vfs.ReplyFileName" scope="transport"
    type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
<property name="OUT_ONLY" value="true"/>
<send>
    <endpoint>
        <address uri="vfs:file:///C:/myFolder"/>
    </endpoint>
</send>
</sequence>

If I only try to insert the name of the city, it works: the third line would be

<property expression="json-eval($.city.name)"

and in this way i save my output in a file named "London", for example. But i need to save output as "London.xml", but i can't understand where is the problem with this concat function.

Community
  • 1
  • 1
FDC
  • 317
  • 3
  • 16

3 Answers3

3

did you tried fn:concat(json-eval($.city.name),'.xml') instead of simply concat(....) ? I know that I already add issue when using functions with some expression. I generally also try to first declare a property and then use it like

<property expression="json-eval($.city.name)" name="city"/>
<property expression="concat(get-property('city'),'.xml')"
name="transport.vfs.ReplyFileName" scope="transport"
type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
Nicolas
  • 482
  • 4
  • 16
  • I already tried fn:concat(json-eval($.city.name),'.xml') but didn't work. Your solution with "city" property works fine, i can't understand why we are forced to use it but it's great... thanks a lot. – FDC Jan 13 '17 at 10:49
  • maybe a bug, you're right I don't know why it's not working. I don't know how to get an access to wso2 jira to submit a defect. I've also [another question that I would like to raise to them regarding dss](http://stackoverflow.com/questions/41588602/wso2-dss-issue-when-selecting-timestamps-from-database) – Nicolas Jan 17 '17 at 11:33
3

You can use as below,

<property expression="json-eval($.city.name)" name="city"/>
<property expression="fn:concat($ctx:city, '.xml')" name="name-of-attribute" type="STRING" scope="default"/>

If you want to concat many parameters use as below,

<property expression="fn:concat($ctx:city ,'.', 'xml')" name="name-of-attribute" type="STRING" scope="default"/>
Rajitha Bhanuka
  • 714
  • 10
  • 11
1

there, the right way is:

    <property expression="fn:concat(get-property('city'),'.xml')" name="transport.vfs.ReplyFileName" scope="transport" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
Alex Lu
  • 914
  • 7
  • 5