Wednesday, February 12, 2014

The custom artifact drop down populator for WSO2 Governance Registry.

Configurable Governance Artifacts (RXT) is the another way to extend the functionality of  WSO2 Governance Registry. The RXT feature provides way to define your own data model very easily.

Please go through the official documentation to learn more about RXT [1].


Here I'm going to show you how to write a drop down populator to list the given type of artifacts.

Lets say we have already stored set of WSDL files in governance registry.
Now we want a drop down field in add service page to select the related WSDL file.

To achieve  this requirement you can write simple drop down populator implementing DropDownDataPopulator interface.

*  Copyright (c) 2005-2010, WSO2 Inc. ( All Rights Reserved.
*  WSO2 Inc. licenses this file to you under the Apache License,
*  Version 2.0 (the "License"); you may not use this file except
*  in compliance with the License.
*  You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.

package org.sampl.rxt.populator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.governance.generic.stub.beans.xsd.ContentArtifactsBean;
import org.wso2.carbon.governance.generic.ui.clients.ManageGenericArtifactServiceClient;
import org.wso2.carbon.governance.generic.ui.utils.DropDownDataPopulator;

import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;

public class WSDLPopulator implements DropDownDataPopulator {

    private static final Log log = LogFactory.getLog(WSDLPopulator.class);
    String[] out = new String[1];

    public String[] getList(HttpServletRequest httpServletRequest, ServletConfig servletConfig) {

        try {
            ManageGenericArtifactServiceClient client =
                    new ManageGenericArtifactServiceClient(servletConfig, httpServletRequest.getSession());

            ContentArtifactsBean artifactsBean = client.listContentArtifacts("application/wsdl+xml");
            if (artifactsBean.getName() != null && artifactsBean.getName().length > 0) {
                return artifactsBean.getName();
            } else {
                out[0] = "None";

        } catch (Exception e) {
            log.error("An error occurred while obtaining the WSDL list", e);
        return out;

Now when you go to add a service, you can pick the available WSDL name from the WSDL drop down list.