Mule使用XPath从有效载荷中返回值 [英] Mule Using XPath to return a value out of an Payload
问题描述
好的,我被要求创建一个新问题,所以去吧.
OK I was asked to create a new question so here goes.
我想提取SOAP请求中的变量值
I want to extract the values of variables in a SOAP request
我通过SoapUI将SOAP请求发送到m子流
I send a SOAP request via SoapUI to a mule flow
<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>
这里是the子流,效果很好.
Here is the mule flow that works fine.
<?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>
我将记录器更改为此内容以查找值
As soon as I change the logger to this to find the value
<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
推荐答案
由于XPath表达式使用自定义名称空间(soapenv
和ws
),因此需要在添加到配置中的表达式管理器元素中声明它们.请参阅: http://www.mulesoft.org/documentation/display/current/XML +命名空间
Since your XPath expression uses custom namespaces (soapenv
and ws
) you need to declare them in an expression manager element added to your config. See: 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>
这篇关于Mule使用XPath从有效载荷中返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!