Sunday, August 23, 2015

How to Write custom Handler to use Access Token as the query parameter in WSO2 API Manager !

Introduction
In this tutorial I'll show how to use Custom handler to use Access token as query Parameter. I'll use WSO2 API Manager 1.9.0 that is the latest release available.

Use Case

API publishing company need to expose their API validation token as a query parameter in url. In order to achieve this task from WSO2 API Manager , they have to do as following way.


Request Path of Handler


Prerequisite

[1] WSO2 API Manager (you can Download from here) .

[2] Java IDE you prefered.

[3] code base in here.


First get the code from  [3] and open in a ide you prefered .

build the code using mvn clean install command.

copy the jar in target directory into the repository/components/dropins and start the server.

If you already create the API you can see synapse API configuration on the deployment/server/synapse-configs/default/api folder in file system.

If you see an  API configuration, You can find [5] in that file.



[5]- handlers configurations
 this custom handler need to place before the APIAuthenticationHandler after place this handler you can see following handler configuration.
[6] - Modified handlers configuration


From this steps you can successfully engage the custom handler into the API. 
If you need to add these configuration into the every api you can edit the velocity template in the <Server-home>/repository/resources/api_templates.

If you see this file you can see handlers part in this file as [7] .

[7] - handlers configuration in velocity template
after the done the configuration as [8] , you can engage the custom handler into the every API you create.
 
[8] - modified handlers configuration with custom handler in velocity template

You can find custom Handler project from here