I have a proxy in Apigee that uses a service callout to another proxy in the same environment. I would like to set the URL host for the callout to match the host of the initial request.
For example, if a request is made in the dev environment to:
https://example-dev.apigee.com/awesome-proxy
I need to make a call to:
https://example-dev.apigee.com/support-proxy
In a test environment the first call is to:
https://example-test.apigee.com/awesome-proxy
The support call needs to go to:
https://example-test.apigee.com/support-proxy
Here is how I would like to define the service callout policy:
<?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>
This will not save and complains about no protocol. The help indicates that this must be hard coded:
<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.
I found a variable to define the URL of a service callout:
servicecallout.{policy-name}.target.url
I attempted to use an assign message policy to dynamically set the variable, as follows:
<?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>
This sets the URL to the literal text {client.host}
I have used the assign message policy in a similar fashion for other purposes and it actually resolves the variable listed. I'm not sure what's happening here.