Search code examples
javaxmlsoapapache-camelblueprint-osgi

Remove <soapenv:Header> from payload in XML route


I am looking for solution how to remove <soapenv:Header> part from SOAP request using XML-based routing (Apache Camel Blueprint XML).

So this:

<soapenv:Envelope xmlns:net="..." xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header>
      ...
   </soapenv:Header>
   <soapenv:Body>
      ...
   </soapenv:Body>
</soapenv:Envelope>

shall become just this:

<soapenv:Envelope xmlns:net="..." xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      ...
   </soapenv:Body>
</soapenv:Envelope>

I think I found java-based solution, also xslt-based solution, but I dont find them quite suitable for my project, and I still hope there is some simple way how to do it directly in XML route without creating java processing class or adding XSLT template.

I was trying <removeHeaders pattern="_something_"/> but either I cant figure out the correct "something", or this command only applies to headers above payload section...


Solution

  • In Blueprint you can get the body of the XML by using XPATH. Something like this:

    <setProperty propertyName="MessageBody">
        <xpath>//*[local-name()='Body']</xpath>
    </setProperty>
    

    Then you could reconstruct your message with the envelop tag.

    <setBody>           
        <simple><![CDATA[<Envelope>${property.MessageBody}</Envelope>]]></simple>
    </setBody>
    

    This will only work if your Envelope tag is a constant.