0

I have a flow in MULE which receives SOAP messages. I am trying to extract the name of a node in this soap message.

My soap message looks like this:

<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>

I want to be able to retrieve the name of the node RetrieveOrgNumber in an operation. I want to set it as a variable.

I have tried #[xpath(fn:local-name('soapenv:Envelope/soapenv:Body/*[1]'))] but i get this error:

Execution of the expression xpath(fn:local-name('soapenv:Envelope/soapenv:Body/*[1]')) failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String

I forgot to add that I did add the namespaces in the message flow 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>

Thank you for the reply Mark.

I tried editing but it is not working. I cannot post a picture of my flow diagram here. I need a reputation of at least 10.

However considering your suggestion I tried Object to XML (StringTobyteArray did not work) Now for my xpath expression I have:

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

The error I get is:

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)

When I tried fn:local-name I had a namespace error with fn.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222

1 Answers1

0

You have 2 options, or you need to declare the namespaces in Mule in order to use these namespaces in your XPath queries. See http://www.mulesoft.org/documentation/display/current/XML+Namespaces

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

The other option is you use local-name() instead, as you tried, but than also match the local names and not with there namespace prefixes:

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

EDIT

The error message Message payload is of type: String mostly in the error file also follows a text saying something like Byte[] expected. So you should add a transformer in front of the XPath expression. For example: http://www.mulesoft.org/documentation/display/current/Using+Transformers

Maybe one of the following can help:

  1. StringToObject
  2. StringToObjectArray
Mark Veenstra
  • 4,691
  • 6
  • 35
  • 66