【问题标题】:Deleting headers from request-config instead of flow in MULE 4从请求配置中删除标头而不是 MULE 4 中的流
【发布时间】:2019-06-13 13:15:01
【问题描述】:

我正在尝试通过比实际更有效的方式找到在 MULE 4 中删除请求标头的解决方案。 在请求配置中可能有<http:default-headers />,但我找不到从这里删除标头的方法。所以我正在删除流中的标题-> 像这样:

    <http:headers>#[attributes.headers -- ["host", "http.headers"]]</http:headers>

完整版流程在这里:

<flow name="WS_name">
<http:listener path="someway/*" config-ref="External_Listener" doc:name="HTTP">
    <http:response statusCode="#[vars.httpStatus default 200]">
        <http:headers>#[vars.outboundHeaders default {}]</http:headers>
    </http:response>
    <http:error-response statusCode="#[vars.httpStatus default 500]">
        <http:body>#[payload]</http:body>
        <http:headers>#[vars.outboundHeaders default {}]</http:headers>
    </http:error-response>
</http:listener>
<http:request method="#[attributes.method]" sendBodyMode="AUTO" config-ref="HTTPS_Request_configuration_proxy" url="#['https://${endpoint.WS_name.host}:${endpoint.WS_name.port}' ++ '${endpoint.WS_name.path}/']">
    <http:headers>#[attributes.headers -- ["host", "http.headers"]]</http:headers>
</http:request>

如果有人有更好的解决方案,请分享。

【问题讨论】:

  • 是否要将监听器中收到的http属性转发给请求?只需删除主机等?
  • 是的,完全正确。我必须从属性中删除这两个标头,bcs 请求不要期望它们并且无法出错。

标签: mule mule-component mule-esb mule4


【解决方案1】:

你正在做的很好。如果您想在 http:request 之外的流程中执行此操作,那么您可以。所有 http:headers 期望的是一张地图。所以这里是一个使用 var 的例子:

<set-variable variableName="myAttributes" value="#[attributes.headers -- ['host', 'http.headers']]" />

<http:request method="#[attributes.method]" sendBodyMode="AUTO" config-ref="HTTPS_Request_configuration_proxy"
            url="#['https://${endpoint.WS_name.host}:${endpoint.WS_name.port}' +++ '${endpoint.WS_name.path}/']">
            <http:headers>#[vars.myAttributes]</http:headers>
</http:request>

【讨论】:

  • 谢谢,这个方法很简单。我的观点是主要使流程尽可能薄。在 Mule 3 中,我使用了这个:&lt;https:outbound-endpoint address="URL" transformer-refs="remove-http-headers"/&gt;,但在 Mule 4 中,唯一的方法是将 &lt;http:headers&gt; 放入 &lt;http:request&gt; 中,如您所述?它的 4+ 行而不是 1..(是的,加上 1+ 行设置变压器参考)
  • 是的,但是您可以将 var 封装在子流中并重复使用它
  • 正如我现在所看到的,我实际上使用了最佳选择。谢谢 - 解决了。
猜你喜欢
  • 2012-01-19
  • 1970-01-01
  • 2020-09-08
  • 1970-01-01
  • 2015-01-20
  • 1970-01-01
  • 2015-03-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多