2

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?

codependent
  • 23,193
  • 31
  • 166
  • 308

1 Answers1

1

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>
Bee
  • 12,251
  • 11
  • 46
  • 73
  • Hi Bee, could you check the updated question? For some reason the if block isn't working: `#if(($apiObj.additionalProperties.get('application_type') == "whatever"))` – codependent Dec 10 '18 at 09:26