Sunday, February 21, 2010

Governance Registry-Identify the Remote API

Here my try is to introduce the Remote API and its abilities.

How to create an instance of the RemoteRegistry
Before we start use the Remote API we have to create an instance of the registry to use it. It can be done like below.
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"),username,password);

Reading a resource
reading aresource from /foo/c1.
Resource resource = registry.get("/foo/c1");

Adding a collection 
Add a collection /c1/c2.
Collection collection = registry.newCollection();  
registry.put("/c1/c2", collection);

Adding a resource
Add a resource r1 to the collection /c1/c2.
Resource r1 = registry.newResource();
String str = "My File Content";
r1.setContent(str.getBytes());
registry.put("/c1/c2/r1", r1);

Checking the existence of a resource 
Check whether r1 is in the collection /c1c2.
boolean value = registry.resourceExists("/c1/c2/r1");

Delete resource
Delete the resource r1 from the collection /c1/c2.
registry.delete("/c1/c2/r1");

Rename a resource
Rename resource 
r1 to 
r2 in the collection /c1/c2.
registry.rename("/c1/c2/r1", "/c1/c2/r2");

Creating versions of resources/collections
Create a version for 
resource or collection.
registry.createVersion("/c1/c2");

Retrieving different versions of a Given Resource
Retrieve the versions of the collection /c1/c2.
String [] versions = registry.getVersions("/c1/c2");

Restoring to an old version
Restoring the old version.
registry.restoreVersion ("/c1/c2;version:2");

Adding a Tag
Add a tag to the resource /c1/c2/r2.
registry.applyTag("/c1/c2/r2" , "rename resource");

Retrieving all tags of a given resource
Retrieve
the tags apply to the resource /c1/c2/r2.
Tag[] tags = registry.getTags("/c1/c2/r2");

Deleting a tag
Delete a tag apply to the resource /c1/c2/r2.
registry.removeTag("/c1/c2/r2","rename resource");

Commenting a resource
Make a comment on a resource 
/c1/c2/r2.
Comment c1 = new Comment();
c1.setText("This is my comment");
String commentpath = registry.addComment("/c1/c2/r2", c1), c1);

Edit a comment
Edit a comment which applied to a resource.
registry.editComment(commentpath,"This is cool");

Rating a resource
Rate a resource.
registry.rateResource("c1/c2/r2 " , 4);

Importing the local file system to the registry
Import a file to the registry via remote client.
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);

Exporting the registry to a file system
Export the content of a resource in the registry to a file in the Remote Client machine.  
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);

Wednesday, February 17, 2010

Governance Registry- Remote Client part-1

Governance Registry is a WSO2 product which use to store and govern the data.

Here I am going to talk about creating a remote client for the WSO2 Governance Registry using Remote API.

For this I use the wso2 Governance Registry v3.03 which you can download from here.
Also it must be install Apache ANT in your machine.

In this post I am describe how to run the sample. Later I'll show how to what are the functions provide by the API and how to use them.
(sample path :- wso2greg-3.0.3/samples/filesampleutils)

First we have to set some of the jars which need to run the sample.

Jars you need to run the sample
-----------------------------------
1.jaxen-1.1.1. jar( http://www.java2s.com/Code/JarDownload/jaxen-1.1.1.jar.zip)
2.abdera -jars 0.4.0 (http://abdera.apache.org/)
3.commons httpclient 3.0.1 jar(http://www.java2s.com/Code/JarDownload/commons-httpclient-3.0.1.jar.zip)
4.commons-codec-1.3 jar (http://www.java2s.com/Code/JarDownload/commons-codec-1.3.jar.zip)
5.axiom-impl-1.2.5 jar(http://www.java2s.com/Code/JarDownload/axiom-impl-1.2.5.jar.zip)
6.axiom-api-1.2.5 jar(http://www.java2s.com/Code/JarDownload/axiom-api-1.2.5.jar.zip)
7.org.wso2.carbon.registry.core-2.0.2.jar (Find at GREG_HOME\webapps\ROOT\WEB-INF\plugins\common folder)
8.axis2-transport-base-1.0.0.wso2v2.jar(Find at GREG_HOME\webapps\ROOT\WEB-INF\plugins\common folder)

Copy above jars to the bin directory in the HOME.

Now you are ready to run the sample.

change directory to the samples/filesampleutils/src

In this example we were given two functionalities.
1. To upload a file of collection to the Registry
2. Download a file or a collection from the Registry.

To upload a file we need to execute ant upload

Then there will be some details to fill regarding the upload,
1. Keystore file path : Provide HOME/resources/security/client-truststore.jks
2. Registry URL : Provide "https://localhost:9443/registry" this is the URL which registry cab be accessed.
3. Username : user name of login to registry(default it's "admin")
4. Password : password of login to registry(default it's "admin")
5. From path : this is the path where upload file/directory is.
(eg :- /home/example/Sample.txt or /home/example/)
6. To path : this is the path where we going to save in the repository (eg :- /)

After fill these you can log on to https://localhost:9443/carbon and select the Browse from the Resources and you will appear your uploaded file/directory in there.

To upload a file we need to execute ant download

Then there will be some details to fill regarding the download,
1. Keystore file path : Provide HOME/resources/security/client-truststore.jks
2. Registry URL : Provide "https://localhost:9443/registry" this is the URL which registry cab be accessed.
3. Username : user name of login to registry(default it's "admin")
4. Password : password of login to registry(default it's "admin")
5. From path : this is the path where download file/directory from.
(eg :- /C1/C2)
6. To path : this is the path where we going to save download file/directory in the local disk.
(eg :- /home/example/)

Now you can see the file or directory you downloaded at the To path.

Thursday, February 11, 2010

Install D-link DWA120 in Ubuntu


This problem I faced with installing D-Link DWA 120 wifi adaptor to my Ubuntu machine. Yasith aiya found a method to do it.

For this you need the WinXp driver which include in the CD you get.
First we need to install ndiswrapper to install this.

1. Plug the device

2. Then type the following commands on Terminal
sudo apt-get install update
sudo apt-get install ndiswrapper-common
sudo apt-get install ndiswrapper-utils1.9
To see whether ndiswrapper install correctly we can type "ndiswrapper"

3. Now copy the WinXp driver to the local disk

4. Change directory of Terminal to driver folder which include .inf file and type followings
sudo ndiswrapper -i X.inf
sudo ndiswrapper -m
sudo modprobe ndiswrapper

Now you can see the device detected. (Try iwconfig)

Wednesday, January 27, 2010

Web Services using AXIS2

In this session I was trying to deploy a web service using Apache Axis2 in eclipse IDE.
Apache Axis2 can be downloaded from here. Here I used Axis2 1.5.1 which is the recently released version.
Apache tomcat server can be downloaded from here. Here I am using the newer version of Apache tomcat 6.0.16.
Eclipse IDE for java ee developers can be downloaded from here. It is a must to use eclipse j2ee platform here.
Then we can start our work......

Start eclipse.
  1. Set axis2 preference. navigate Window-->Preferences-->Web Services-->Axis2 Preferences-->Axis2 Runtime. Then set the Axis2 runtime location of downloaded Axis2 bin folder location. Click Ok.


  2. Then we must setup the web server which we use to deploy from. To do this....... right click on the Project Explorer pan-->New-->Other-->Server-->Server-->Next--> Select apache tomcat server according to the tomcat version. Click finish.



  3. Now its time to start the project..... Right click on the Project Explorer pan-->New-->Other-->Dynamic Web Project-->Next -->Name the project-->Click Finish.


  4. Next we create a java package in the previously created project by right click on the project name in the Project Explorer pan. This is the package which include our web service.
  5. Create a class in the package created on previous step and write the program in it.
  6. Right click on the class name in the Project Explorer pan-->Web Services-->Create Web Service.
  7. In the configuration set Web Service Runtime as Apache Axis2 and click Finish.
  8. Now the Web Service will create and deploy by the Apache tomcat server.
  9. You can see whether this work or not by visit localhost:8080/(Project name)-->Services Then it will show your public methods under your java class file name in which we implement the web service.
  10. If you want to see the wsdl file just click on the java class file name.





I will present how to create a client program which uses this web service later......