首页 文章

使用Apache Synapse时评估XPath的问题

提问于
浏览
1

我正在尝试在ubuntu 11.04 64位上运行Apache Synapse示例,我发现在样本nr 2中评估XPath表达式有问题 .

我的XPath表达式:

$ <definitions xmlns="http://ws.apache.org/ns/synapse"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://ws.apache.org/ns/synapse http://synapse.apache.org/ns/2010/04/configuration/synapse_config.xsd">

<sequence name="main">
    <switch source="//m0:getQuote/m0:request/m0:symbol" xmlns:m0="http://services.samples">
        <case regex="IBM">
            <!-- the property mediator sets a local property on the *current* message -->
            <property name="symbol" value="Great stock - IBM"/>
        </case>
        <case regex="MSFT">
            <property name="symbol" value="Are you sure? - MSFT"/>
        </case>
        <default>
            <!-- it is possible to assign the result of an XPath expression as well -->
            <property name="symbol" expression="fn:concat('Normal Stock - ', //m0:getQuote/m0:request/m0:symbol)"/>
        </default>
    </switch>
    <log level="custom">
        <!-- the get-property() XPath extension function allows the lookup of local message properties
                    as well as properties from the Axis2 or Transport contexts (i.e. transport headers) -->
        <property name="symbol" expression="get-property('symbol')"/>
        <!-- the get-property() function supports the implicit message headers To/From/Action/FaultTo/ReplyTo -->
        <property name="epr" expression="get-property('To')"/>
    </log>
    <!-- Send the messages where they are destined to (i.e. the 'To' EPR of the message) -->
    <send/>
</sequence>

它运行在以下数据上:

$ <soapenv:Body><m0:getQuote xmlns:m0="http://services.samples"><m0:request><m0:symbol>IBM</m0:symbol></m0:request></m0:getQuote></soapenv:Body></soapenv:Envelope>

结果是:

2011-08-08 15:37:04,227 [ - ] [HttpClientWorker-1] DEBUG SwitchMediator XPath:// m0:getQuote / m0:request / m0:symbol的计算结果为:

2011-08-08 15:37:04,227 [ - ] [HttpClientWorker-1] DEBUG SwitchMediator没有匹配的交换机案例 - 执行默认值

它应该去:

$<case regex="IBM">
        <!-- the property mediator sets a local property on the *current* message -->
        <property name="symbol" value="Great stock - IBM"/>
    </case>

有谁知道会出现什么问题?我几天前安装了ubuntu,因此有可能在该系统上缺少某些东西 .

1 回答

  • 0

    尝试使用完整的xpath ..

    <switch xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:m0="http://services.samples" source="//soapenv:Envelope/soapenv:Body/m0:getQuote/m0:request/m0:symbol">
    

相关问题