Extending the WSO2 GovernanceRegistry with Handlers and Filters Isuru Wimalasundera Software Engineer WSO2
Objectives• An introduction to Handlers and Filters• A brief description over normal processing of resources in registry.• The extension of resource processing by Handlers.• The role of a filter• A simple demo on the use of handlers and filters• Other important aspects
Why need Handlers ?• Handlers is a Java archive file which is used in extending functionality of registry.• Registry is not only a resources store, it inherits additional capabilities and makes resources suitable for enterprise deployment.• But Organizations or a deployment can have the requirement of customizing the standard behavior of resources.
The normal resource processing (contd.)• Registry API provides all the resources related operations.• The Repository interacts with the data access layer and do low- level database operations.• Registry invokes the Version Repository if the resource requires versioning.• Registry directly interacts with data access layer to do non resource related operations. E.g. – tagging, commenting, etc.
Handlers in to action• Handler is a pluggable component.• Every handler is extended from an abstract class called Handler.• The Handler implementation allows to provide alternative behaviors for basic resource related operations.• The handler implements a corresponding operation for resource handling methods of the Registry API.
Handlers in to action (contd.)• As event invocations happens the corresponding handler methods will get triggered by registry. get – Retrieve a resource. put - Adding a new resource , updating an existing resource. importResource - Adding or updating a resource by importing its content from a URL. delete - Deleting a resource. putChild - Adding a child resource to a collection. importChild - Importing a child resource to a collection.
Handlers in to action (contd.)• All the handler methods contains a single parameter of type RequestContext.• An instance of RequestContext holds all details about current request. • resourcePath – a unique path referred to the resource • resource - holds the actual Resource instance • sourceURL - URL to import resource content (only for import operations) • parentPath – path to the parent resource • parentCollection - collection implementation of the parent resource • properties - to store handler specific information • processingComplete – must set to true to terminate the processing after the handler is invoked.
The role of a Filter• Every handler has an associated Filter.• Filters provide criteria for engaging handlers.• Registry always evaluates the associated filter before invoking a handler.• If the filter evaluates to true, it will invoke its associated handler.• A filter extends from the Abstract class Filter.
The role of a Filter (contd.)• The registry contains two built in filter implementations for common filtering scenarios• MediaTypeMatcher • Filter by the media type of resource.• URLMatcher • Filter by the URL criteria defined .• Customized filters can be implement according to the organization and deployment requirements.
Handler Manager Phases• At registration handlers get categorized in to phases as given below.• Pre-Commit Handlers: • System Phase (all built-in handlers and handlers defined on registry.xml) • Tenant System Phase (tenant-specific system handlers) • User Defined Handler Phase (handlers uploaded and configured through Management Console) • Reporting Phase (the eventing, statistics, and simulation handlers)• Post-Commit Handlers • Commit Phase (if the commit succeeded these are executed) • Rollback Phase (if the commit failed these are executed)
The demo• Implementation of a Handler• Implementation of a Filter• How to deploy a handler• Handler registration to the handler chain• Functionality of the Handler• Functionality of the Filter
WSO2• Founded in 2005 by acknowledged leaders in XML, Web Services Technologies & Standards and Open Source• Producing entire middleware platform 100% open source under Apache license• Business model is to sell comprehensive support & maintenance for our products• Venture funded by Intel Capital• Global corporation with offices in USA, UK & Sri Lanka• 100+ employees and growing