如何在Apigee服务调用中使用动态URL

如何在Apigee服务调用中使用动态URL,apigee,callout,dynamic-url,Apigee,Callout,Dynamic Url,这很简单。我需要Apigee服务调用(SC)中的元素作为动态元素 例如:http://{dynamiccurl} 其中dynamiccurl将在运行时确定,并且每个请求的该值都不同。它将具有完整的目标URL,如(ip:port/abc/orderid/1234) http://{dynamiccurl} 我试过这些: 在JS策略中,尝试在上下文中设置servicecallout.{scpolicyname}.target.url。在这种情况下,只发送动态ip:port。URI缺少/abc/

这很简单。我需要Apigee服务调用(SC)中的
元素作为动态元素

例如:
http://{dynamiccurl}

其中
dynamiccurl
将在运行时确定,并且每个请求的该值都不同。它将具有完整的目标URL,如(ip:port/abc/orderid/1234)


http://{dynamiccurl}
我试过这些:

  • 在JS策略中,尝试在上下文中设置
    servicecallout.{scpolicyname}.target.url
    。在这种情况下,只发送动态
    ip:port
    。URI缺少
    /abc/orderid/1234

  • AssignMessage
    策略中,创建了一个标头,并尝试在SC URL元素中使用它,如request.header.name、{request.header.name},前面有$

  • AssignMessage
    策略中,创建了一个变量并尝试在SC中使用它,如前面有
    {dynamiccurl}

这是一个常见的用例,我相信一定有一个简单的方法。我需要你的帮助

谢谢


Somu

考虑使用目标服务器。它更干净,而且它们是专为您刚才描述的目的而设计的。更多详情请参阅

您可以结合使用ServiceCallout和AssignMessage策略

您可以在ServiceCallout策略本身中设置
ip:port
。正如您所指出的,在
http://{dynamiccurl}
元素中设置它

至于URI的其余部分,您可以使用assignmessagepolicy
元素。以下是一个例子:

<AssignMessage enabled="true" continueOnError="false" async="false" name="GenerateAuthorizationPayload">
    <FaultRules/>
    <Properties/>
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    <AssignTo createNew="true" type="request"/>
    <Set>
    <Payload contentType="text/xml">
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="urn:sample">
           <soapenv:Header/>
           <soapenv:Body>
              <v1:Login/>
           </soapenv:Body>
        </soapenv:Envelope>
    </Payload>
    <Path>/abc/orderid/1234</Path>
    <Verb>POST</Verb>
    </Set>
</AssignMessage>

假的
/abc/orderid/1234
邮递
如果需要灵活性,您还应该能够将
{variable}
放在
标记中


正是这两个策略的组合,使您获得了一个动态的
ip:port/path

谢谢您的输入,这是一个好主意。在我的例子中,IP:端口将为每个请求更改。给定一个请求,将映射ip和URI内容。因此,如果路由被LB中的其他服务器而不是特定的服务器选择,那么路由到LB将不起作用。但是我喜欢这个实现,因为它很干净&刚刚发现我们已经将它用于不同的用例:)我应该补充一点,在最新发布的OPDK中,您可以添加实际的callout本身。之前不需要单独的AssignMessage步骤。此外,详图索引中的允许变量。in AssignMessage不转换变量。例如:
callout BaasConfig BAAScalloutResponse http://{u BAAS_IP}/1234/{dealerId}
<AssignMessage enabled="true" continueOnError="false" async="false" name="GenerateAuthorizationPayload">
    <FaultRules/>
    <Properties/>
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    <AssignTo createNew="true" type="request"/>
    <Set>
    <Payload contentType="text/xml">
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="urn:sample">
           <soapenv:Header/>
           <soapenv:Body>
              <v1:Login/>
           </soapenv:Body>
        </soapenv:Envelope>
    </Payload>
    <Path>/abc/orderid/1234</Path>
    <Verb>POST</Verb>
    </Set>
</AssignMessage>