2014-03-12 33 views
2

好的,我被要求創建一個新問題。Mule使用XPath從有效載荷中返回一個值

我想提取SOAP請求

變量的值通過我發送了SoapUI一個SOAP請求騾子流

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://sms.csir.co.za/"> 
<soapenv:Header/> 
<soapenv:Body> 
    <ws:sendTextMessage> 
    <sender>Jaco</sender> 
    <to>08277899863</to> 
    <text>Hallo Jaco how are you</text> 
    </ws:sendTextMessage> 
</soapenv:Body> 
</soapenv:Envelope> 

這裏是騾子流工作正常。

<?xml version="1.0" encoding="UTF-8"?> 

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" 
    xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.2" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd 
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd"> 
    <flow name="jacoFlow1" doc:name="jacoFlow1"> 
     <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8090" doc:name="HTTP"/> 
     <object-to-string-transformer doc:name="Object to String"/> 
     <logger message="#[payload]" level="INFO" doc:name="Logger"/> 
    </flow> 
</mule> 

只要我改變記錄到這個發現的價值

<logger message="#[xpath('//soapenv:Envelope/soapenv:Body/ws:sendTextMessage/text/text()').text]" level="INFO" doc:name="Logger"/> 

我得到這個錯誤

Execution of the expression "xpath('//soapenv:Envelope/soapenv:Body/ws:sendTextMessage/text/text()').text" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String 
+0

這本書。 Mule in Action聲明瞭這個「xpath(xPathExpression)」 - 將XPath表達式應用於正在傳輸的消息 有效負載(必須是XML文檔或DOM實例)。「我試圖將有效負載轉換爲XML和DOM,但得到相同的錯誤。 –

+0

嘗試[this](https://github.com/skjolber/mule-module-dxpath)獲取更高級的XPath表達式 – ThomasRS

回答

4

由於您的XPath表達式使用自定義命名空間(soapenvws)您需要在添加到配置中的表達式管理器元素中聲明它們。參見:http://www.mulesoft.org/documentation/display/current/XML+Namespaces

<mulexml:namespace-manager> 
    <mulexml:namespace prefix="soapenv" 
         uri="http://schemas.xmlsoap.org/soap/envelope/"/> 
    ... 
</mulexml:namespace-manager> 
+0

感謝您回到我身邊David。我是騾新手。我是否一個接一個地聲明兩個名稱空間? –

+0

謝謝,我得到它的工作。如果你知道如何,很容易。親切的問候。 –

相關問題