我们如何使用Xpath打破Wso2esb中的字符串

时间:2013-07-11 06:42:45

标签: xpath wso2 wso2esb wso2dss

我希望使用xpath在wso2esb中打破一个字符串 我这样的输入

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

我需要使用xpath在相同的属性中断 我需要这样的

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

为此我尝试使用tokenize函数,但wso2esb显示错误 我的配置文件

<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>

但是这样的抛出错误你对此有任何想法我需要将它存储在Db表中作为一个看起来像单独的行的字段 错误是

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

2 个答案:

答案 0 :(得分:4)

tokenize是XPath 2.0附带的一个函数。要启用XPath 2.0功能,请取消注释synapse.properties文件中的以下条目,该文件位于$ ESB_HOME / repository / conf目录

synapse.xpath.dom.failover.enabled=true

然后你必须指定中介,如下,

<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"/>

答案 1 :(得分:1)

我不认为这可以通过XPath来完成,XPath是在XML中导航元素。您可以使用脚本介体并编写JS来破坏属性值。 使用以下命令从脚本介体

访问ESB参数
<script language="js"> var test_param = mc.getProperty('Message')

使用以下命令将脚本介体中的参数检索回ESB

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

使用javascript执行所需的字符串操作