Web Services API
The operations of the WSO2 Governance Registry can now be accessed through Web Service calls using the Web Service API (WS-API).
The WS-API supports almost all operations exposed through the main Registry API. A WS client is provided for the WS-API which allows you to access the Registry just as you would through the main Registry API.
For more information about the Web Services API, see Web Services API - WSO2 Governance Registry, and WS-API Sample.
Setting up the WS API Registry Client and WS-Security
The following code shows how to set up the WS Client and authenticate it against an instance of the Governance Registry.
Note
It is assumed that default configurations of the Registry have not been changed.
1. Set the system properties to enable the HTTPS connection.
String GREG_HOME = /path/to/Governance_Registry System.setProperty("javax.net.ssl.trustStore", "GREG_HOME/repository/resources/security/client-truststore.jks"); System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon"); System.setProperty("javax.net.ssl.trustStoreType","JKS");
2. A number of parameters are required to initialize the client. These are initialized in the following code:
System.setProperty("carbon.repo.write.mode", "true"); String axis2Repo = GREG_HOME + "/repository/deployment/client"; String axis2Conf = GREG_HOME + "/repository/repository/conf/axis2_client.xml"; ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(axis2Repo, axis2Conf);
3. The final steps of the initialization is done in the following code segment:
String username = "admin"; String password = "admin"; String serverURL = "https://localhost:9443/services/"; WSRegistryServiceClient registry = new WSRegistryServiceClient(serverURL, username, password, configContext);
4. Run an ant
command at GREG_HOME/bin
and add all the JARs created in GREG_HOME/repository/lib
to the class path prior to running the examples.
5. If you run this example, an output similar to the following output will be generated at the server side console.
6. This client instance can now be used just as using the Registry API.
7. Set up WS-Security for the WS-API. To add WS-Security for the WS-API, just name the relevant policy file as ws-api-sec-policy.xml
and place it into GREG_HOME/repository/conf
. WS-Security will now be engaged.
Here are some of the possible operations as examples.
Adding a Resource to the Registry
Resource r1 = registry.newResource(); String path = "/dev_guide/r1"; String r1content = "R1 content"; r1.setContent(r1content); registry.put(path, r1);
Commenting, Tagging and Rating a Resource
registry.addComment(path, new Comment("This is a WS-API comment")); registry.rateResource(path, 5); registry.applyTag(path, "WS tag");
Moving and Renaming a Resource
String newPath = "/dev_guide_new/r1_move"; registry.move(path, newPath); registry.rename(newPath, "r2_renamed");
Retrieving the Resource's Content
Resource resource = registry.get("/dev_guide_new/r2_renamed"); System.out.println(new String((byte[])resource.getContent()));
This will output the original content to the console, for example, "R1 content."
See more operation in Registry API.