【发布时间】:2014-11-18 19:21:40
【问题描述】:
我在 Apigee 中有一个代理,它使用服务调出到同一环境中的另一个代理。我想为标注设置 URL 主机以匹配初始请求的主机。
例如,如果在开发环境中发出请求:
https://example-dev.apigee.com/awesome-proxy
我需要打电话给:
https://example-dev.apigee.com/support-proxy
在测试环境中,第一个调用是:
https://example-test.apigee.com/awesome-proxy
支持电话需要转到:
https://example-test.apigee.com/support-proxy
这是我想定义服务调用策略的方式:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="serviceCallout">
<DisplayName>serviceCallout</DisplayName>
<FaultRules/>
<Properties/>
<Request clearPayload="true" variable="example.request">
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
</Request>
<Response>example.response</Response>
<HTTPTargetConnection>
<Properties/>
<URL>{client.host}/support-proxy</URL>
</HTTPTargetConnection>
</ServiceCallout>
这不会保存并抱怨没有协议。帮助表明这必须是硬编码的:
<HTTPTargetConnection>/<URL> element
The URL to the service being called. While the hostname portion of URL must be hard-coded, you can supply the remainder of the URL dynamically with a variable.
我找到了一个变量来定义服务调用的 URL:
servicecallout.{policy-name}.target.url
我尝试使用分配消息策略来动态设置变量,如下:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="assignCalloutURL">
<DisplayName>assignCalloutURL</DisplayName>
<FaultRules/>
<Properties/>
<AssignVariable>
<Name>servicecallout.serviceCallout.target.url</Name>
<Value>{client.host}</Value>
<Ref/>
</AssignVariable>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>
这会将 URL 设置为文字文本 {client.host}
我以类似的方式将分配消息策略用于其他目的,它实际上解决了列出的变量。我不确定这里发生了什么。
【问题讨论】:
标签: apigee