1
votes

I'm trying to figure out how to customize the default set of API Handlers that is deployed into the Synapse engine for an API's implementation.

The 'API Handlers' section of the architecture overview () shows how deployment of an API results in a Synapse configuration consisting of a standard set of handlers.  The customization instructions indicate that to change this you go to the source view in the management console and alter the xml content. 

That works, but it would mean that to customize the standard set of handlers (for example, to include an additional/custom policy enforcement step), I would need to alter each deployed API by hand in that config.

Is there a place where I can configure API Manager to add additional custom handlers automatically to any API deployed through it, just as it automatically adds handlers like the Authentication Policy, the Throttling Policy, and so on. This way, I can enforce conformance to corporate standards and not require that each API is individually edited, nor force API publishers to use a sequence to add the additional behavior.

From checking the code, it appears that this module may be the one building the synapse config for an API:

.//components/apimgt/org.wso2.carbon.apimgt.impl/1.2.3/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java

If I wanted to add the additional logic - is that the appropriate module to override in order to add that behavior, or is there an easier, less intrusive way to do this?

1

1 Answers

0
votes
  1. add your handler to dropins
  2. AM_HOME/repository/resources/api_templates/velocity_template.xml and change the following

#if($handlers.size() > 0)
        <handlers xmlns="http://ws.apache.org/ns/synapse">
            #foreach($handler in $handlers)
            <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
        </handlers>
        #end

to


<handlers>
      **<handler class="com.custom.api.CustomHandler"/>**
      <handler class="org.wso2.carbon.apimgt.gateway.handlers.throttling.APIThrottleHandler">
         <property name="id" value="A"/>
         <property name="policyKey" value="gov:/apimgt/applicationdata/tiers.xml"/>
      </handler>
      <handler class="org.wso2.carbon.apimgt.usage.publisher.APIMgtUsageHandler"/>
      <handler class="org.wso2.carbon.apimgt.usage.publisher.APIMgtGoogleAnalyticsTrackingHandler">
         <property name="configKey" value="gov:/apimgt/statistics/ga-config.xml"/>
      </handler>
      <handler class="org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler"/>
   </handlers>

this will add your custom handler (<handler class="com.custom.api.CustomHandler"/>)to all the api automatically and other default handlers mentioned above.