Search code examples
soapxpathwso2orchestrationwso2-esb

SOAP mediation Wso2 ESB


Hello I have the following message:

 <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
      <soapenv:Header>
         <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="true">
            <wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-11">
               <wsu:Created>2012-09-06T09:59:04.031Z</wsu:Created>
               <wsu:Expires>2012-09-06T10:04:04.031Z</wsu:Expires>
            </wsu:Timestamp>
            <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-12">
               <wsse:Username>admin</wsse:Username>
               <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">admin</wsse:Password>
            </wsse:UsernameToken>
         </wsse:Security>
      </soapenv:Header>
      <soapenv:Body />
   </soapenv:Envelope>

I wanted to use an XPath to get the username <wsse:Username>admin</wsse:Username> from the incoming message

any suggestion?

EDIT:

I tried this:

<inSequence xmlns="http://ws.apache.org/ns/synapse">
   <property xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" name="p1" expression="$header/wsse:Username" scope="default" />
   <log>
      <property name="output*********" expression="get-property('p1')" />
   </log>
</inSequence>

but it does not output the username:

MessageID: urn:uuid:68f95493-7dfd-416a-b
455-f77f4fd5c9c5, Direction: request, output********* =

Solution

  • Nuvio,

    You can use the expression "$header/wsse:Security" where "wsse" prefixes the namespace carried by the Security header element. Shown below is how you can get it saved to a Synapse message context property.

    <property xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" name="Security" expression="$header/wsse:Security" />
    

    FYI, you can use the syntax "$header/header_name" to extract any SOAP header element that exists in your SOAP message.

    Hope this helps!

    Cheers, Prabath