Skip to content

Header Mediator incorrect behaviour – escapes XML when setting complex headers using an expression #4535

@Samitha-001

Description

@Samitha-001

Description

When the Header Mediator is used with the expression attribute to dynamically construct and set a SOAP header containing XML, the Micro Integrator escapes the XML instead of inserting it as an XML node since the evaluating header expression as text in the SOAP header, which causes the XML to be escaped. The escaping happens only when setting SOAP headers using the Header Mediator.

Example:

Expected Behaviour

Setting the following WS-Addressing header:

<wsa:From>
    <wsa:Address>http://localhost:3000/</wsa:Address>
</wsa:From>

The Header Mediator should insert the XML fragment as a proper OMElement.

Actual Behaviour

MI inserts the value as text, escaping XML:

<wsa:From>
    &lt;wsa:Address>http://localhost:3000/&lt;/wsa:Address>
</wsa:From>

This results in an invalid WS-A header.

Steps to Reproduce

This can be reproduced by adding the below artifacts into any API in-sequence and observing the outgoing message.

When invoking the API, you will clearly see that the WS-A header is escaped in the outgoing SOAP envelope, confirming the incorrect behavior of the Header Mediator.

<property name="TMP_HEADER"
          expression="concat('&lt;', 'wsa:Address', '&gt;', 'http://localhost:3000/', '&lt;/wsa:Address&gt;')"/>

<!-- Set header -->
<header name="wsa:From"
        xmlns:wsa="http://www.w3.org/2005/08/addressing"
        action="set"
        expression="$ctx:TMP_HEADER"/>

This will result the below format when checking through a log full.

<wsa:From>
    &lt;wsa:Address>http://localhost:3000/&lt;/wsa:Address>
</wsa:From>

Version

4.3.0

Environment Details (with versions)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions