reading soap header element in payload

2019-09-06 13:27发布

问题:

I need to read contents of wsse:Username(which is part of soap header) from following soap payload in mule using message-properties-transformer. I would like to use this variable somewhere else.

Soap Webservice request:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:spel="http://mobistar.be/spellchecker/">
   <soapenv:Header> 
      <wsse:Security soapenv:mustUnderstand="1" >
         <wsse:UsernameToken wsu:Id="UsernameToken-1">
           <wsse:Username>Tester01</wsse:Username>
         </wsse:UsernameToken>
       </wsse:Security>
   </soapenv:Header> 
   <soapenv:Body>
     <spel:CheckSpellingRequest>
        <spel:Text>Please test this blabla</spel:Text>
      </spel:CheckSpellingRequest>
   </soapenv:Body>
</soapenv:Envelope>

Please let me know if we can achieve this in mule?

回答1:

  • Declare the "soapenv" and "wsse" namespaces in Mule's namespace manager: http://www.mulesoft.org/documentation/display/current/XML+Namespaces
  • Use XPath in a MEL expression to extract the value(s) you need: http://www.mulesoft.org/documentation/display/current/MEL+Cheat+Sheet#MELCheatSheet-XPathSupport

Also use set-variable, set-session-variable or set-property instead of the old message-properties-transformer.