This documentation is for WSO2 API Manager 2.1.0 View documentation for the latest release.
Page Comparison - Writing Custom Handlers (v.20 vs v.21) - API Manager 2.1.0 - WSO2 Documentation

All docs This doc

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Reviewed changes

...

Code Block
<handler class="org.wso2.carbon.apimgt.custom.authentication.handler.CustomAPIAuthenticationHandler" />
       #foreach($handler in $handlers)
          #if(!($handler.className == "org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler"))
           <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>
         #end
        #end
</handlers>


You can conditionally select can select to which API(s) you need to engage the handler. Given below is an example of adding only the CustomAPIAuthenticationHandler only to  to the sample PizzaShackAPI.

Code Block
languagexml
<handlers xmlns="http://ws.apache.org/ns/synapse">
#if($apiName == 'admin--PizzaShackAPI')
    <handler class="org.wso2.carbon.sample.auth.CustomAPIAuthenticationHandler"/>
#end
#foreach($handler in $handlers)
    #if($apiName != 'admin--PizzaShackAPI' || !($handler.className == "org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler"))
        <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>
    #end
#end
</handlers>

...