[英]how to read variable in assign message policy in APIGee
In Apigee在 Apigee
given a variable in javascript policy, example: var value = 123;给定 javascript 策略中的一个变量,例如:var value = 123;
how to get this variable in the assign message policy?如何在分配消息策略中获取此变量?
by using {a} in the payload message is not reachable通过在负载消息中使用 {a} 无法访问
You have to set the variable in the context object using context.setVariable("variable-name", value);您必须使用context.setVariable("variable-name", value) 在上下文 object 中设置变量;
Refer to this variable in the assign_message policy using {variable-name}.使用 {variable-name} 在 assign_message 策略中引用此变量。
You can just set the context variable in jsPolicy like this:您可以像这样在 jsPolicy 中设置上下文变量:
context.setVariable("a","123");
You can use it after in any of the policies.您可以在任何政策之后使用它。
Ex:-前任:-
<QueryParams>
<QueryParam name="a">{a}</QueryParam>
</QueryParams>
For the variable to be available for use in any Apigee policy, you first have to make it a flow variable.要使变量可用于任何 Apigee 政策,您首先必须将其设为流变量。 You can use Apigee's JavaScript Object Model method called context
to to this (see ref here ).您可以使用 Apigee 的 JavaScript Object Model 方法调用context
对此(参见此处参考)。 In your JS policy, you have var {some-value} = 123;
在你的 JS 政策中,你有var {some-value} = 123;
. . To make this available as a flow variable,introduce this line in your JS policy after the variable assignment: context.setVariable("preferred-variable-name", some-value);
要使其可用作流变量,请在变量分配后在 JS 策略中引入此行: context.setVariable("preferred-variable-name", some-value);
You can now access this preferred-variable-name
in your AM policy as show below:您现在可以在 AM 策略中访问此preferred-variable-name
,如下所示:
<AssignVariable>
<Name>preferred-variable-name</Name>
<Ref>preferred-variable-name</Ref>
</AssignVariable>
Just to mention it is possible to pass the value directly in the policy as well as shown below只是提一下,可以直接在策略中传递值,如下所示
<AssignVariable>
<Name>variable_name</Name>
<Value>123</Value>
</AssignVariable>
The <Name>
tag can be set to any name. <Name>
标签可以设置为任何名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.