Adding custom HTTP header in Mule HTTP endpoint

Pranav Pal picture Pranav Pal · Mar 24, 2014 · Viewed 8.1k times · Source

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.

Answer

Anirban Sen Chowdhary picture Anirban Sen Chowdhary · Mar 24, 2014

If you want to add custom header name from Mule .. there are 2 ways :-

1) Use Set property in your flow like :-

< set-property propertyName="Custom Header"  doc:name="Set Custom Header" value="Here Set your Message"/ >

2) Use SOAP intercepter where you have to create a java class HttpHeaderInterceptor.java and then refer in the intercepter using Spring bean.. Please refer this :- http://java.dzone.com/articles/adding-http-headers-soap

Either way you can follow ... easy way is using set Property in mule flow Just before CXF SOAP component .... The result you can see in SOAP UI in header section in response... Hope this help