Social Icons

twitterfacebookgoogle pluslinkedinrss feed Online Resume

Friday, February 14, 2014

WSO2 Governance Registry - Apply Tags using Handler

There can be scenarios, where users want to apply tags into their resources, while resource is inserted. I am writing this post based on my answer provided to this Stack Overflow question.

Question was on how to apply a tag into a service in WSO2 Governance Registry at the time of the service creation. We can use Registry Handler for achieving this requirement. Handlers are the well-known extension points in WSO2 Governance Registry.

"Handlers are pluggable components, that contain custom processing logic for handling resources. All handlers extend an abstract class named Handler, which provides default implementations for resource handling methods as well as a few utilities useful for concrete handler implementations."[WSO2 Governance Registry Docs]

I have modified handler sample, which is shipped with Governance Registry pack. Using above link please download the G-Reg pack and handler sample is located at GREG_HOME/samples/handler.

public void put(RequestContext requestContext) throws RegistryException {

 if (!CommonUtil.isUpdateLockAvailable()) {
        try {
   String resourcePath = requestContext.getResourcePath().getPath();
   Registry registry = requestContext.getRegistry();
   registry.applyTag(resourcePath, "CustomTag");

  } finally {

Compiled jar file need to be added into GREG_HOME/repository/components/dropins folder and register handler using either management console or registry.xml file.

<handler class="org.wso2.carbon.registry.samples.handler.CustomServiceHandler">
    <filter class="org.wso2.carbon.registry.core.jdbc.handlers.filters.MediaTypeMatcher">
        <property name="mediaType">application/vnd.wso2-service+xml</property>

When you are inserting a new service, this handler will get hit and it will add the given tag into the Service.