0

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

Ellrohir
  • 1,017
  • 1
  • 14
  • 32

4 Answers4

1

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.

Ewout
  • 146
  • 6
  • seems like a plan, but I need to find, where to put it...because in the place in route, where I am editing, `body` is already set to `soapenv:Body` content - so this code just empties it...however `soapenv:Header` is somehow presented and it is re-integrated to response in the end...I guess I need more analysis of our code (sadly I am quite a newb to this :/) – Ellrohir Jun 23 '16 at 14:14
0

The easiest way I would thing is to parse the SOAP message and then remove the header. You can do that with SAAJ. How to remove empty header from SOAP message?

.removeHeaders() is for removing Camel exchange headers which is something completely different.

Community
  • 1
  • 1
Souciance Eqdam Rashti
  • 3,143
  • 3
  • 15
  • 31
0

It depends on what dataformat you are using for the CXF endpoint, Is this SOAP request coming from someother service ?

Why are you not happy with XSLT ?

Regardless, You can remove if you use payload DATAFORMAT.

gnanagurus
  • 883
  • 1
  • 12
  • 29
  • mainly because the sample XSLT code I am copy-pasting from tutorials is causing whole ESB to crash upon load, as it is not considered valid for some reason (can't figure out why so far) – Ellrohir Jun 23 '16 at 14:18
  • Wow, interesting comment. I have worked on so many projects, where we had dealt with millions of messages & large data sets predominantly using XSLT + Apache Camel. I won't advocate XSLT if you are dealing with JSON, but I don't want you to get a wrong idea that's it. Answer from @Ewout is also a good idea, but there will be lots of transformation requirements where XSLT would help. Good luck. – gnanagurus Jun 24 '16 at 00:32
  • Back to my issue after a while. Can you possibly provide me correct xsl code to perform what I want to do? I tried a few so far but it never done what I expected (to remove ONLY `` tag and its contents, nothing else). – Ellrohir Jul 20 '16 at 09:24
0

So I find perfect and very simple solution to my issue:

The contents of <soapenv:Header> (along with contents of <soapenv:Body>) were stored in CxfPayload object , which is part of org.apache.camel.Exchange

After I learned this, I was just one Groovy command, that can be easily included in routes.xml, away from solution:

<groovy>
    exchange.getIn().getBody(org.apache.camel.impl.DefaultMessage.class).getBody(org.apache.camel.component.cxf.CxfPayload.class).getHeaders().clear();
</groovy> 
Ellrohir
  • 1,017
  • 1
  • 14
  • 32