Reputation: 24442
I have a custom handler that should only be applied to a set of APIs. I have seen that editing <APIM_HOME>/repository/resources/api_templates/velocity_template.xml
would apply the change to all APIs. Is there an automatic way to assign it but only to a subset of the APIs?
UPDATE: My wso2 api management version is 2.6.0. I am checking an application_type property but it doesn't work:
<handlers>
#if($apiObj.additionalProperties.get('application_type') == "whatener")
<handler class="com.codependent.MyCustomHandler"/>
#end
</handlers>
Removing the if block the handler is correctly printed.
So how can I access the API properties to check the condition?
Upvotes: 2
Views: 325
Reputation: 12502
You can apply handers selectively based on API properties. Look at my answer in Adding custom handler to specific API wso2 API-Manager
eg.
<Handlers>
#foreach($handler in $handlers)
#if(($handler.className ==
"org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler") &&
($apiObj.additionalProperties.get('auth_mode') == "Inhouse"))
<handler xmlns="http://ws.apache.org/ns/synapse" class="$handler.className">
#if($handler.hasProperties())
#set ($map = $handler.getProperties())
#foreach($property in $map.entrySet())
<property name="$!property.key" value="$!property.value"/>
#end
#end
</handler>
<handler class="org.wso2.apim.custom.extensions.CustomAuthHandler"/>
<Handlers>
Upvotes: 1