1

i have a response from a WS in WSO2 ESB and i write this xml file on a directory on my local machine. I'd like to change the name of the .xml file according to the content. Here is the code of the sequence used for writing file:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="WriteFile">
<property name="transport.vfs.ReplyFileName" value="MyFile.xml" scope="transport"></property>
<property name="OUT_ONLY" value="true"></property>
<send>
  <endpoint>
     <address uri="vfs:file:///C:\MyFolder"></address>
  </endpoint>
</send>
</sequence>

Now i'd like to have MyFile_2.xml if I find "MyFile_2" in a particular tag of the WS response, or MyFile_3.xml if i find "MyFile_3" and so on. I think i must parameterfy my sequence, and particularly value="MyFile.xml" but i don't understand how to do.

EDIT: And what about a SOAP response? I have a SOAP answer like this:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap..............>
<soap:Body>
  <QueryStructureResponse xmlns="..........>
     <QueryStructureResult>
        <RegistryInterface xmlns="ht............>
           <Header>
              <ID>IT1001</ID>
              <Test>true</Test>
              <Name xml:lang="en">MY_FILENAME</Name>
               ............

I tried in a similar way, but something goes wrong when i want to call my file with MY_FILENAME inside. Previous REST response manipulation is ok, great answer Jean-Michel .

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

1 Answers1

3
<property name="transport.vfs.ReplyFileName"
expression="concat('MyFile_',$body/root/child/text(),'.xml')" scope="transport"/>

where $body/root/child/text() is the XPath used to find your particular tag

Jean-Michel
  • 5,926
  • 1
  • 13
  • 19
  • What about a JSON response? It works fine with an XML response, but i can't extract my text from a JSON... i've tried with http://goessner.net/articles/JsonPath/ but nothing – FDC Jan 12 '17 at 15:01
  • use json-eval() in your expression, something like concat('MyFile_',json-eval($.elmt1.child1), '.xml'). See https://docs.wso2.com/display/ESB481/JSON+Support – Jean-Michel Jan 12 '17 at 15:12
  • i'm trying to use json-eval in this way: concat('Meteo_',json-eval($.city.name),'.xml') but wso2 esb doesn't save this configuration, I can't insert this in the "expression" field. If it's useful i could ask a new question for more detail – FDC Jan 13 '17 at 08:44
  • I posted this question: http://stackoverflow.com/questions/41631258/cant-apply-concat-function-in-wso2-esb-configuration-with-json-eval – FDC Jan 13 '17 at 09:27