How We Can Break a String in Wso2esb using Xpath

岁酱吖の 提交于 2019-12-02 16:36:51

问题


I wish to break a string in wso2esb using xpath my input like this

<property name="Message" value="assetname:ups,assetcode:452chi,assetid:548935,assetvalue:215" scope="default"/>

i need break in same property using xpath i need like this

assetname:ups
assetcode=452chi
assetid=54895
assetvalue=215

for this i tried with tokenize function but wso2esb showing errors my configure file

<proxy xmlns="http://ws.apache.org/ns/synapse" name="Xpathcheck" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <property name="max" value="1" scope="default" type="STRING"/>
         <property name="min" value="1" scope="default" type="STRING"/>
         <property name="MessageText" expression="fn:concat('Assetid:',get-property('min'),',','Assetname:',get-property('max'))" scope="default" type="STRING"/>
         <property name="Tokenize" expression="fn:tokenize(get-property('Messagetext'),',')" scope="default" type="STRING"/>
         <log>
            <property name="MessageText" expression="get-property('MessageText')"/>
            <property name="Tokenize" expression="get-property('Tokenize')"/>
         </log>
               </inSequence>
      <outSequence/>
   </target>
   <description></description>
</proxy>

But its throwing errors like this u have any idea for this i need store this in Db table as a one field which look like separate lines error is

ERROR - SynapseXPath Evaluation of the XPath expression fn:tokenize(get-property('Messagetext'),',') resulted in an error
org.jaxen.UnresolvableException: No Such Function tokenize

回答1:


tokenize is a function comes with XPath 2.0. To enable XPath 2.0 functions uncomment the following entry in the synapse.properties file which is located at $ESB_HOME/repository/conf directory

synapse.xpath.dom.failover.enabled=true

then you have to specify the mediator as follows,

<property name="Message" value="a,b,c,d,e" scope="default"/>
         <property xmlns:fn="http://www.w3.org/2005/xpath-functions" name="Tokenize" expression="fn:tokenize(syn:get-property('Message'),',')" scope="default" type="STRING"/>



回答2:


I dont think this can be done through XPath, XPath is to navigate elements in an XML. You can do this by using a script mediator and write a JS to break the property values. use the following to access the ESB params from the script mediator

<script language="js"> var test_param = mc.getProperty('Message')

Use the following to retrieve the params within the script mediator back to the ESB

mc.setProperty("param1",var1)
mc.setProperty("param2",var2)

Use the javascript to carry out the required string manupulations



来源:https://stackoverflow.com/questions/17586688/how-we-can-break-a-string-in-wso2esb-using-xpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!