Can I use a KVM property to supply value of virtual host in HttpProxyConnection?

I have defined kvm property as below:

<Get assignTo="private.virtualhost">

<Key>

<Parameter>virtualhost</Parameter> <!-- virtualhost =~ secure -->

</Key>

</Get>

In the proxy policy, I am trying to refer this property under HttpProxyConnection.

<HTTPProxyConnection> <BasePath>/v1/mobile/internet</BasePath> <Properties/> <VirtualHost ref="private.virtualhost"/> </HTTPProxyConnection>

I am getting an error while deploying saying:

Invalid virtual host reference . Context Revision:15;APIProxy:<proxyName>;Organization:<<org>>;Environment:<env>.

The urge to externalize the virtual host is to avoid the need to update the policy while deploying between the environments (non prod to prod) where virtual host values differ.

0 2 136
2 REPLIES 2

Virtual hosts already have a unique configuration for each environment. So you should be able to leverage this.

Also note, that KVM policy is for use at runtime. eg the KVM is accessed while an API proxy request is being processed. Hence it's not possible to use a KVM for the configuration of a deployment of an API proxy. However again, you should be able to use virtual hosts to implement this.

Not applicable

you cannot use reference in virtual host tag.

I can give a workaround.

If you have multiple virtual hosts in a particular environment, then you can add all the virtual hosts in the proxy code and create a raise fault policy in the preflow request with the condition request.header.Host equal to your virtualhost urls, which you can configure in KVM.

As you have specified between different environments, its good to have the same virtual host names in nonprod and prod, which will help you avoid these scenarios. You can create virtualhost names same and urls different in different environments.