This is a easy one.I need the <URL>
element in the Apigee Service callout(SC) as dynamic one.
Eg: <URL>http://{dynamicURL}</URL>
Where dynamicURL
will be determined at runtime and this value will be different for every request. It will have the complete target URL such as (ip:port/abc/orderid/1234)
<HTTPTargetConnection>
<Properties />
<URL>http://{dynamicURL}</URL>
</HTTPTargetConnection>
Have tried these:
In a JS policy, tried setting servicecallout.{scpolicyname}.target.url
in the context. In this case only the dynamic ip:port
is getting sent. The URI is missing /abc/orderid/1234
.
In the AssignMessage
policy, created a header and tried using it in SC URL element like request.header.name, {request.header.name}, with $ at front.
In the AssignMessage
policy, created a variable & tried using it in SC like {dynamicURL}
with $
at front.
This is a common usecase and I'm sure there must be a easy way to do. Need your help with this.
Thanks,
Somu
You can use a combination of the ServiceCallout and AssignMessage policy.
You can set the ip:port
in the ServiceCallout policy itself. Set this in the element <URL>http://{dynamicURL}</URL>
of the <HTTPTargetConnection>
, just as you noted.
As for the rest of the URI, you can use the AssignMessage policy <Path>
element. Here is an example:
<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>
You should also be able to put a {variable}
inside of the <Path>
tags if you need flexibility there.
It is the combination of these 2 policies that you get a dynamic ip:port/path
.