WSO2 Governance Registry - WS API [ Documentation Index ]

WS API of the Registry

Registry can be accessed through Web services since the registry API methods are exposed as Web services. Though these methods are not exactly same as the Registry API methods, we can use them to deal with the basic registry operations.

Writing a Simple WS Client

Following code shows how to write a WS client to put a collection and a text resource and to read the resource.



First, we have to set the system properties to enable the https connection.



System.setProperty("javax.net.ssl.trustStore", "CARBON_HOME/resources/security/client-truststore.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
System.setProperty("javax.net.ssl.trustStoreType","JKS");
RemoteRegistry remote_registry = new RemoteRegistry(new URL("https://localhost:9443/registry"));



To authenticate the client, we have to generate the stubs from AuthenticationAdminService.wsdl which can be accessed via https://localhost:9443/services/AuthenticationAdminService?wsdl



AuthenticationAdminServiceStub authenticationStub =
                    new AuthenticationAdminServiceStub("https://localhost:9443/services/AuthenticationAdminService");
authenticationStub._getServiceClient().getOptions().setManageSession(true);
boolean resp = authenticationStub.login("admin","admin",NetworkUtils.getLocalHostname());




Then get the cookie to be used in the next service invocations. This lets registry service to authenticate the second request



ServiceContext serviceContext = authenticationStub._getServiceClient().getLastOperationContext().getServiceContext();
String sessionCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING);




The code generation for ResourceAdminService.wsdl (which can be accessed via https://localhost:9443/services/ResourceAdminService) also should be done to get the ResourceAdminServiceStub.



ResourceAdminServiceStub stub = new ResourceAdminServiceStub("https://localhost:9443/services/ResourceAdminService");
stub._getServiceClient().getOptions().setManageSession(true);
stub._getServiceClient().getOptions().setTimeOutInMilliSeconds(60000000);

stub._getServiceClient().getOptions().setProperty(HTTPConstants.COOKIE_STRING, sessionCookie);



Following code shows how to add a collection to the registry. It will create a collection named "testCollection" under the root.



String parentPath = "/";
    String mediaType = "application/zip";
     String description = "test service";
    stub.addCollection(parentPath,"testCollection", mediaType,description);



Following code shows how to add a text resource inside testCollection. It will create a resource named "testResource"(which's content is a text) inside testCollection.



parentPath = "/testCollection";
mediaType = "text/plain";
String content = "This is a test resource";
stub.addTextResource(parentPath, "testResource", mediaType, description, content);

Following code shows how to get the content from the text resource.



String text = stub.getTextContent("/testCollection/testResource");
System.out.println(text);



Before running the sample, set the classpath to CARBON_HOME/repository/lib.