In simple words, the RemoteRegistry is a Java API for interacting with a Registry instance. Regardless of where a given Registry instance is located, either locally or remotely, we can still talk to it using RemoteRegistry.
The RemoteRegistry is yet another implementation of org.wso2.registry.Registry interface. However, the difference between the RemoteRegistry and a standard Registry is that, the RemoteRegistry is not an actual registry
but a client for interacting with a registry instance.
Communication between the Registry and the RemoteRegistry takes place using the Atom Publishing Protocol (APP). When we start the registry server, an atom feed is generated . Thereafter, if you browse https://localhost:9443/registry/atom/ (this address changes depending on your application server settings), you'd be able to see the atom feed from the registry. The structure and format of the feed is described in the following location: http://www.wso2.org/wiki/display/registry/Registry+Protocol.
To create an instance of the RemoteRegistry, what we need first is the URL of a registry. If the root of the registry is http://foo.com/, the URL for the RemoteRegistry instance would be http://foo.com/registry/atom.
Once we have the URL figured out, we can create an instance of the RemoteRegistry using the following code:
RemoteRegistry remote_registry = new RemoteRegistry(new URL("https://localhost:9443/registry"));
Creating an instance of the RemoteRegistry in this manner, is similar to accessing a registry without login into it with communication taking place as an anonymous user.
If you have a user name and password for the registry, you can pass them along when creating the remote_registry instance. At that point, all permissions granted for the particular username/password pair
will apply to the owner of the remote_registry instance. Creating the remote_registry with user name and the password can be done using:
RemoteRegistry remote_registry = new RemoteRegistry(new URL("https://localhost:9443/registry"), "admin", "admin");In this example, we have created the remote_registry instance with username="admin" and the password as also "admin".
You can learn how to use Registry API from the Registry API guide.
We can use the RemoteRegistry to export our entire local file system into the Registry. What we need to do is to give the location of the file system and the location where we want to put them in the Registry.
Once we do that, inside the registry it will create the same structure as the file system and upload all files into the Registry. We can consider this as any check-in operation on any kind of version management
system. Following code demonstrates how to import a local file system into the Registry:
File file = new File("Path of the file"); RemoteRegistry remote_registry = new RemoteRegistry(new URL("http://localhost:9443/registry"), "admin", "admin"); RegistryClientUtils.importToRegistry(file ,"/myfile/filesystem" ,remote_registry);
In the previous section, we discussed how to import a local file system into the Registry. There is another way round of this and it is to check-out the Registry to a local file system. To export, we can select
either the entire Registry or a selected node. Depending on the node we select, the remote_registry instance will create the same structure within the file system. Even if we have the resource with binary data,
then it will create all of the necessary files in the file system.
Let's say we want to export "/myfile/filesystem" into my local file system then we can use the following code:
File toFile = new File("Path of the new file"); RemoteRegistry remote_registry = new RemoteRegistry(new URL("http://localhost:9443/registry"), "admin", "admin"); RegistryClientUtils.exportFromRegistry( toFile, "/myfile/filesystem" ,remote_registry);