Search code examples
httpmulecustom-headers

Adding custom HTTP header in Mule HTTP endpoint


I am trying to add a custom header in Mule's HTTP endpoint:

<flow name="flow">
    <poll frequency="60000">
        <http:outbound-endpoint
            address="http://user:[email protected]"
            followRedirects="true" method="GET" exchange-pattern="request-response">
            <properties>
                <spring:entry key="CUSTOM-HEADER-NAME" value="custom-header-value" />
            </properties>
        </http:outbound-endpoint>
    </poll>
    <echo-component />
</flow>

But this way of using <spring:entry> element for adding custom header does not seem to work.

I tried replacing

<properties>
    <spring:entry key="CUSTOM-HEADER-NAME" value="custom-header-value" />
</properties>

with

<property key="CUSTOM-HEADER-NAME" value="custom-header-value"/>

But that does not work either. I am not seeing any error, but the response I am getting is the one which I would get without the custom header.

Am I following the right way to add custom headers? I am using Mule 3.2.0.


Solution

  • Got it working using <message-properties-transformer>:

    <http:outbound-endpoint
        address="http://user:[email protected]"
        followRedirects="true" method="GET" exchange-pattern="request-response">
        <message-properties-transformer
            scope="outbound">
            <add-message-property key="CUSTOM-HEADER-NAME"
                value="custom-header-value" />
            </message-properties-transformer>
    </http:outbound-endpoint>