Saturday, March 27, 2010

Restore a Registry Resource stored in a file to WSO2 Registry

Following code snippet shows, how to programmetically restore a Registry Resourece written in to a file, back to WSO2 Registry using RemoteRegistry. This is a follow-up to an earlier blogpost.

import org.wso2.carbon.registry.app.RemoteRegistry;
import org.wso2.carbon.registry.core.exceptions.RegistryException;

import java.net.URL;
import java.net.MalformedURLException;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.IOException;

public class RemoteRegistrySampleTest {
public static void main(String[] args) {
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 esb2xRemoteRegistry = null;
try {
esb2xRemoteRegistry = new RemoteRegistry(new URL("https://localhost:9443/registry"),
"admin", "admin");
esb2xRemoteRegistry.restore("/esb-resources", new FileReader("/home/heshan/Dev/wso2_heshan/temp/registry.xml"));
} catch (RegistryException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}
}

No comments: