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

The Java Governance API is one of many APIs supported by the WSO2 Governance Registry. Read more on Supported APIs and Standards for a complete list of APIs supported by WSO2 Governance Registry.

In the Governance Registry, you can store and govern the behaviors of SOA artifacts like services, WSDLs, schemas, policies and Endpoints. Governance API provides a way to do it programatically.

The relationship of the classes used in the Governance API is shown in the following class diagram.

The Governance API needs to be accessed through a Governance Registry (as opposed to a root registry) instance.

Inside an admin service, a Governance Registry instance can be obtained by inheriting from the org.wso2.carbon.core.AbstractAdmin class and calling its getGovernanceRegistry() method.

When Remote Registry or WS-Registry is used, this instance can be created as shown below.

import org.wso2.carbon.governance.api.util.GovernanceUtils;

public static void main(String[] args) {
    Registry governanceRegistry = GovernanceUtils.getGovernanceUserRegistry(rootRegistry, username); //rootRegistry refers to an instance of RemoteRegistry or WSRegistryServiceClient

}

For optimum performance at the client-side, it is also useful to enable client-side caching.

import org.wso2.carbon.governance.api.cache.ArtifactCacheManager;

public static void main(String[] args) {
    ArtifactCacheManager.enableClientCache();
}

As a specific example, Governance Registry can be obtained via Remote Registry as shown below. See also Accessing Registry Remotely through API.

import org.wso2.carbon.registry.app.RemoteRegistry;
import org.wso2.carbon.governance.api.util.GovernanceUtils;

public static void main(String[] args) {
    String url = "https://localhost:9443/registry";
    String username = "admin";
    String password = "admin";
    System.setProperty("carbon.repo.write.mode", "true");
    Registry rootRegistry = new RemoteRegistry(new URL(url), username, password);
    Registry governanceRegistry = GovernanceUtils.getGovernanceUserRegistry(rootRegistry, username);
	GovernanceUtils.loadGovernanceArtifacts((UserRegistry) govReg);
	return govReg;
}

As another specific example, Governance Registry can be obtained via WS-Registry as shown below. See also Setting up the WS API Registry Client and WS-Security.

import org.wso2.carbon.registry.ws.client.registry.WSRegistryServiceClient;
import org.wso2.carbon.governance.api.util.GovernanceUtils;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.wso2.carbon.base.ServerConfiguration;
 
private static final String GREG_HOME = "/home/test/wso2greg-4.5.0";

public static void main(String[] args) {
    String url = "https://localhost:9443/services/";
    String username = "admin";
    String password = "admin";
    System.setProperty("carbon.repo.write.mode", "true");
    ConfigurationContext configurationContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(
                           GREG_HOME + File.separator + "repository" + File.separator + "deployment" + File.separator + "client",
                               ServerConfiguration.getInstance().getFirstProperty("Axis2Config.clientAxis2XmlLocation")));
    WSRegistryServiceClient rootRegistry = new WSRegistryServiceClient(url, username, password, configurationContext);
    Registry governanceRegistry = GovernanceUtils.getGovernanceUserRegistry(rootRegistry, username);
	GovernanceUtils.loadGovernanceArtifacts((UserRegistry) govReg);
	return govReg;
}

See more information about the Governance API on the following pages:

See also Governance API for WSO2 Governance Registry.

  • No labels