Mule Tip: Controlling Mule Soap Headers

motif

You might have noticed that under certain circumstances Mule will add its own Soap Headers to the calls. This can be a problem in some situations. For example, let’s say I’m communicating with a remote web service that is not expecting these extra headers. This will probably result in a validation failure and leave me unable to communicate with the web service. Fortunately there is a way to avoid the unwanted headers, which is what we’ll be discussing now.

First, it is important to understand what the Mule headers are for and when are they being added to a Soap message.

The Mule Soap Headers we’ve been talking about are the following:

  • MULE_CORRELATION_ID
  • MULE_CORRELATION_GROUP_SIZE
  • MULE_CORRELATION_SEQUENCE
  • MULE_REPLYTO

The first three, as their names suggest, are related to the correlation information a message might have. This information is useful when you want to break down a message into different parts and still be able to reassemble it afterwards. For instance, Mule sets these values during the splitting and aggregation process. You should be aware of these headers but you don’t need to think about them, Mule handles correlation for you. The replyTo on the other hand, defines where the message should be routed after the recipient of the message is done processing it. For more information about the replyTo, you can click here.

These headers are populated with the corresponding values present in the Mule message being processed. They are only added when the message has a correlation Id or the replyTo property is set in the outbound scope. In any other case, Mule won’t add a Soap Header to your message.

Now if you’ve gotten this far, it’s probably because you have the Mule headers and you want to know how to get rid of them. You can disable them through your Mule configuration. To that end you have the ‘enableMuleSoapHeaders’ attribute, which can be set either in the configuration element or in each service/client that you have configured. By default this attribute is set to ‘true’, so unless you specify that you don’t want them, they are going to be included (given the situation that we explained before of course).

To let Mule know that you don’t want it to add the headers, you need to set the ‘enableMuleSoapHeaders’ to ‘false’ in the configuration element as well as in any CXF processor elements. For instance, I would like to avoid the Mule headers in the following configuration:

Keep in mind that the goal of the Mule Soap Headers is to pass along the correlation and replyTo information present on the Mule Message, so once you disable the headers this information will be lost from the Soap Message.

I hope this blog helps to clarify Mule Soap Headers and explain why you will sometimes find them in your Soap Messages, but more importantly, I hope it demonstrates how you can tailor Mule to your needs.

For more information about how to configure CXF in Mule you can go to the CXF module configuration reference.


We'd love to hear your opinion on this post