在Mule HTTP端点中添加自定义HTTP标头

时间:2014-03-24 07:26:37

标签: http mule custom-headers

我正在尝试在Mule的HTTP端点中添加自定义标头:

<flow name="flow">
    <poll frequency="60000">
        <http:outbound-endpoint
            address="http://user:pass@example.com"
            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>

但是这种使用<spring:entry>元素添加自定义标头的方式似乎不起作用。

我试过替换

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

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

但这也不起作用。我没有看到任何错误,但我得到的反应是没有自定义标题的情况。

我是否按照正确的方式添加自定义标头?我使用的是Mule 3.2.0。

2 个答案:

答案 0 :(得分:1)

如果你想从Mule中添加自定义标题名称,有两种方法: -

1)在流程中使用Set属性,如: -

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

2)使用SOAP intercepter,你必须创建一个java类 HttpHeaderInterceptor.java ,然后使用Spring bean在intercepter中引用..请参考: - http://java.dzone.com/articles/adding-http-headers-soap

无论哪种方式,你都可以遵循...简单的方法是在mule流中使用set属性就在CXF SOAP组件之前.... 您可以在标头中的标头部分中看到的结果,以响应... 希望这个帮助

答案 1 :(得分:1)

使用<message-properties-transformer>

了解它
<http:outbound-endpoint
    address="http://user:pass@example.com"
    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>