【问题标题】:extracting node-name from soap message in MULE从MULE中的soap消息中提取节点名
【发布时间】:2014-07-22 10:25:15
【问题描述】:

我在 MULE 中有一个接收 SOAP 消息的流。我正在尝试在此肥皂消息中提取节点的名称。

我的肥皂信息如下所示:

<soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:ns="http://abc/dto/2013/08" 
    xmlns:ns1="http://abc/message/dto/2013/08"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:RetrieveOrgNumber>
         <ns:request>
            <ns1:sessionId>SessionId</ns1:sessionId>
            <ns1:timeStamp>2001-12-31T12:00:00</ns1:timeStamp>
            <ns1:userIdentifier>UserIdentifier</ns1:userIdentifier>
            <ns1:language>EN</ns1:language>
            <ns1:source>SoapUI</ns1:source>
            <!-- 1 or more repetitions: -->
           <ns:orgNumber>AE7WJ046</ns:orgNumber>
         </ns:request>
      </ns:RetrieveOrgNumber>
   </soapenv:Body>
</soapenv:Envelope>

我希望能够在操作中检索节点 RetrieveOrgNumber 的名称。我想将其设置为变量。

我已经尝试过#[xpath(fn:local-name('soapenv:Envelope/soapenv:Body/*[1]'))],但我得到了这个错误:

执行表达式 xpath(fn:local-name('soapenv:Envelope/soapenv:Body/*[1]')) 失败。 (org.mule.api.expression.ExpressionRuntimeException)。消息负载的类型:字符串

我忘了补充,我确实在消息流 xml 中添加了命名空间:

<mulexml:namespace-manager>
    <mulexml:namespace prefix="soapenv" uri="http://schemas.xmlsoap.org/soap/envelope/" />
    <mulexml:namespace prefix="ns" uri="http://sanlam.co.za/group/party/service/clientmanagement/dto/2013/08" />
    <mulexml:namespace prefix="ns1" uri="http://sanlam.co.za/group/common/message/dto/2013/08" />
    <mulexml:namespace prefix="xsi" uri="http://www.w3.org/2001/XMLSchema-instance" />
    </mulexml:namespace-manager>

感谢马克的回复。

我尝试过编辑,但它不起作用。我不能在这里张贴我的流程图的图片。我需要至少 10 的声望。

但是考虑到您的建议,我尝试了 Object to XML(StringTobyteArray 不起作用)现在对于我的 xpath 表达式,我有:

#[xpath(local-name('soapenv:Envelope/soapenv:Body/*[1]'))]

我得到的错误是:

Caused by: [Error: unresolvable property or identifier: local]
[Near : {... xpath(local-name('soapenv:Envelope/s ....}]
                   ^
[Line: 1, Column: 7]
    at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getBeanProperty(ReflectiveAccessorOptimizer.java:687)
    at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getBeanPropertyAO(ReflectiveAccessorOptimizer.java:472)
    at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:374)

当我尝试fn:local-name 时,fn 出现命名空间错误。

【问题讨论】:

    标签: web-services soap xpath mule-studio


    【解决方案1】:

    您有 2 个选项,或者您需要在 Mule 中声明命名空间才能在 XPath 查询中使用这些命名空间。见http://www.mulesoft.org/documentation/display/current/XML+Namespaces

    #[xpath(/soapenv:Envelope/soapenv:Body/*[1]/local-name())]
    

    另一个选项是您尝试使用 local-name() 代替,但也匹配本地名称而不是那里的命名空间前缀:

    #[xpath(/*[local-name()='Envelope']/*[local-name()='Body']/*[1]/local-name())]
    

    编辑

    错误消息Message payload is of type: String 主要在错误文件中,后面还有类似Byte[] expected 的文字。因此,您应该在 XPath 表达式前面添加一个转换器。例如:http://www.mulesoft.org/documentation/display/current/Using+Transformers

    也许以下其中一项可以提供帮助:

    1. StringToObject
    2. StringToObjectArray

    【讨论】:

    • 感谢 Mark 的回复,我确实声明了命名空间。我忘了提。我在流程图中声明它们如下: schemas.xmlsoap.org/soap/envelope" /> sanlam.co.za/group/party/service/clientmanagement/dto/2013/08 " /> sanlam.co.za/group/common/message/dto/2013/08" /> w3.org........
    • 因此 aamespace 不是问题。
    • 希望编辑有所帮助,如果没有分享必要的流程配置
    • 您好,我尝试了您的建议。我收到一个新错误。请在我的问题中查看上述内容。
    • 将您的 xpath 更改为:#[xpath(/soapenv:Envelope/soapenv:Body/*[1]/local-name())]
    猜你喜欢
    • 2012-05-04
    • 2015-03-19
    • 1970-01-01
    • 1970-01-01
    • 2011-04-10
    • 1970-01-01
    • 2018-05-30
    • 2021-10-28
    • 1970-01-01
    相关资源
    最近更新 更多