【问题标题】:Adding custom HTTP header in Mule HTTP endpoint在 Mule HTTP 端点中添加自定义 HTTP 标头
【发布时间】:2014-03-24 07:26:36
【问题描述】:

我正在尝试在 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>

但是这种使用&lt;spring:entry&gt; 元素添加自定义标题的方式似乎不起作用。

我尝试替换

<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。

【问题讨论】:

    标签: http mule custom-headers


    【解决方案1】:

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

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

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

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

    无论哪种方式,您都可以遵循...简单的方法是在 mule 流中使用 set Property 就在 CXF SOAP 组件之前...。 您可以在 header 部分的 SOAP UI 中看到响应... 希望对您有所帮助

    【讨论】:

    • 我不认为 &lt;set-property&gt; 在 Mule 3.2 中是一个有效的元素。请参阅 3.2 here 和 3.3 here 的 HTTP 传输参考。
    • 然后尝试第二种方法...将链接中给出的示例中的java类添加为CXF拦截器
    【解决方案2】:

    使用&lt;message-properties-transformer&gt;:

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-15
      • 2015-06-01
      • 2010-10-09
      • 2012-04-23
      • 1970-01-01
      • 1970-01-01
      • 2017-11-11
      • 1970-01-01
      相关资源
      最近更新 更多