Monday, January 11, 2010

Access WSO2 Governance as a Service From Remote Registry

WSO2 Governance as a Service is a hosted instance of WSO2 Governance Registry with multi-tenant support. WSO2 Governance as a Service provide you almost all the functionalities provided with the Governance Registry targeting the enterprise SOA governance, same time it provides all the advantages  inherent with the Software as a Service model.

Here I'm talking about how to use a popular feature available in Governance Registry, inside WSO2 Governance as a Service. i.e. Remote Registry Client. With Remote Registry Client, you can access the resources in registry programatically. It uses atom/pub protocol to communicate with the registry server.

Here is an example of using Remote Registry Client. I assumed I have an account with domain name 'example.com' with a user name 'example_user' ('example_password'). You have to change this to valid values before running this code, You can create an account in Governance as a Service freely for a limited use.
import java.net.URL;
import org.wso2.carbon.registry.core.Registry;
import org.wso2.carbon.registry.core.Resource;
import org.wso2.carbon.registry.app.RemoteRegistry;

class RegistryDemo {
public static void main(String[] args) throws Exception {

// calls the registry with the authentication information
callRemoteRegistry("http://governance.cloud.wso2.com/registry",
 "example_username@example.com", "example_password");
}

public static void callRemoteRegistry(String url, String username,
 String password) throws Exception {

Registry myRegistry = new RemoteRegistry(new URL(url), username, password);
if (!myRegistry.resourceExists("/demoResource")) {

Resource r = myRegistry.newResource();
r.setContent("demo content");
myRegistry.put("/demoResource", r);
}

Resource r = myRegistry.get("/demoResource");
byte[] contentBytes = (byte[])r.getContent();
String content = new String(contentBytes);
System.out.println("Content: " + content);
}
}

1 comment:

Koos said...

I found some errors with this code. As it currently is it complains about uncaught exceptions, which is no big deal as you can just surround the block with try-catch. However, as soon as I do that it gives me an error saying RegistryException is an incompatible type and requires java.lang.throwable. I dont know if I'm just making a stupid mistake somewhere but thats what I get from this code.