This documentation is for WSO2 Governance Registry 5.3.0. View documentation for the latest release.
Skip to end of metadata
Go to start of metadata

This sample explains how to restrict the addition of files having a particular media type. We will be reusing the code of the Handler Sample in this example. This sample requires Apache Maven. See System Requirements for links on how to install it.


1. Navigate to GREG_HOME/samples/handler/src to find the source code of the Handler Sample.

2. Add a new Java Class named RestrictionHandler at 

GREG_HOME/samples/handler/src/src/main/java/org/wso2/carbon/registry/samples/handler/ with the following source:

package org.wso2.carbon.registry.samples.handler;
import org.wso2.carbon.registry.core.Collection;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.registry.core.jdbc.handlers.Handler;
import org.wso2.carbon.registry.core.jdbc.handlers.RequestContext;
import org.wso2.carbon.registry.core.utils.RegistryUtils;
public class RestrictionHandler extends Handler{
    public void put(RequestContext requestContext) throws RegistryException {
        String path = requestContext.getResourcePath().getPath();
        throw new RegistryException("You are not allowed to add the " +
                (requestContext.getResource() instanceof Collection ? "collection" : "resource") + " named '" +
                RegistryUtils.getResourceName(path) + "' to the location '" + path + "'. Please contact the " +
                "administrator for more information.");

3. Compile the source code by running the following command inside GREG_HOME/ samples/handler/src:

mvn clean install

The command mvn clean install will trigger an Apache Maven Build in your command line. This requires you having installed Apache Maven. See System Requirements for links on how to install it.

A successful run of Apache Maven will generate a report similar to the following:

3. Copy the <G-REG_HOME>/ samples/handler/src/target/ org.wso2.carbon.registry.samples.handler-5.3.0.jar into GREG_HOME/repository/components/dropins/ directory.

4. Edit the registry.xml file which is in GREG_HOME/repository/conf folder and add an XML snippet similar to the following. In this example, add this handler as the very first handler in the registry.xml file.

<handler class="org.wso2.carbon.registry.samples.handler.RestrictionHandler" methods="PUT">
    <filter class="org.wso2.carbon.registry.core.jdbc.handlers.filters.MediaTypeMatcher">
        <property name="mediaType">application/x-msdos-program</property>

The configuration above is used to restrict the addition of executable files into the WSO2 Governance Registry. There is no point to go ahead with any other processing for these types of media, which is why we added this handler as the very first handler in the registry.xml file.

See also Handler Sample.

5. Start the WSO2 Governance Registry. See Running the Product for more information.

  • No labels