【发布时间】:2019-02-12 14:22:56
【问题描述】:
我是 Mulesoft 的新手,也是一名入门级程序员。我一直在试图弄清楚如何实施 Mule 4 自定义策略。这是在线文档:https://docs.mulesoft.com/api-manager/2.x/http-policy-transform#add-headers
按照示例,我成功地添加了请求和响应标头。我的主要目标是在使用变量时添加请求标头。我正在尝试 MEL (https://docs.mulesoft.com/mule-runtime/3.7/mule-expression-language-examples) 尝试调用变量名,但它不起作用。但是,每当我尝试记录变量时,它都会返回正确的值。
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:http-policy="http://www.mulesoft.org/schema/mule/http-policy"
xmlns:http-transform="http://www.mulesoft.org/schema/mule/http-policy-transform"
xmlns:secure-properties="http://www.mulesoft.org/schema/mule/secure-properties"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http-policy http://www.mulesoft.org/schema/mule/http-policy/current/mule-http-policy.xsd
http://www.mulesoft.org/schema/mule/http-policy-transform http://www.mulesoft.org/schema/mule/http-policy-transform/current/mule-http-policy-transform.xsd
http://www.mulesoft.org/schema/mule/secure-properties http://www.mulesoft.org/schema/mule/secure-properties/current/mule-secure-properties.xsd">
<http-policy:proxy name="{{{policyId}}}-custom-policy">
<http-policy:source propagateMessageTransformations="true">
<try>
<set-variable variableName="header" value="TEST_HEADER"/>
<logger level="INFO" message="#[vars.header]" />
<http-transform:add-headers outputType="request">
<http-transform:headers>#[{'TEST_HEADER': 'TEST'}]</http-transform:headers>
</http-transform:add-headers>
<http-policy:execute-next/>
<http-transform:add-headers outputType="response">
<http-transform:headers>#[{'Header_Added': '#[vars.header]'}]</http-transform:headers>
#this step doesn't work as I hoped it would
</http-transform:add-headers>
<logger level="INFO" message="#[vars.header]" />
#logging prints the value of header
</try>
</http-policy:source>
</http-policy:proxy>
</mule>
我正在尝试添加 #[vars.header] 作为请求标头名称,可能还有值?我需要创建另一个变量来获得标题值吗?有人可以指导我正确的方向吗?
谢谢
【问题讨论】: