Part II - Web service client programs
Posted July 5, 2010 - 12:03pm
Please note that due to the current funding situation, the NGS no longer supports a Web Service interface to its resources. We have kept this tutorial online in case it is of use for users of other Grids.
In this part, we're going to work with the client programs only. The server is already up and running at a NeSC host (This is no longer available, to use this practical, set up your own GT4 server following the Part III of this practical first). There're five client programs that match required functionality.
Here are the files:
- gtwitter
- src
- Register.java
- Login.java
- Update.java
- Lister.java
- Follow.java
- Streams.java
- ClientBase.java - this is the base class to do all interfacing work.
- src
1. Register
The first program, Register.java, is ready to compile and run, let's do it: (you can use any username and password, but keep it)
cd ~/gtwitter
ant compile-client
ant register -Duser=<your_username> -Dpass=<your_password>
If you wonder how this works, you can read the source code in Register.java and especialy ClientBase.java. The createService method contains the essential steps to connect to the remote service and obtain a resource and the service port type.
If you don't like to use ant to run the client programs, you can set CLASSPATH of Globus jar files and then run the programs with java.
source $GLOBUS_LOCATION/etc/globus-devel-env.sh
export $CLASSPATH=$CLASSPATH:$HOME/gtwitter/build
java Register <your_username> <your_password>
2. Login
The Login.java is left blank for you to fill in, otherwise it does nothing. Open this file in an editor, select and copy the following code block into where appropriate:
public String login(String username, String password) throws Exception {
LoginInput ri = new LoginInput();
ri.setUsername(username);
ri.setPasscode(password);
return this.service.login(ri);
}
Save the source file, and compile and run it:
ant compile-client
ant login -Duser=<your_username> -Dpass=<your_password>
3. Update
This can be done in the same way as Login, but it's up to you to figure out what method to call this time. You can find it out from the port type stub file:
~/gtwitter/build/stubs/src/uk/ac/nesc/toe/gtwitter/stubs/Instance/GTwitterPortType.java
In this class, you can find there's a method as:
public java.lang.String update(java.lang.String param) throws java.rmi.RemoteException;
It means the update method accepts a String argument and returns a String as well. The argument is the status text to update.
Now compile and run:
ant update -Dstatus="any text you want to give"
You can add more text, but each text must be limited to no more than 140 characters long as Twitter.
4. Streams
This program will fetch what you have written on the gTwitter microblog and display.
Modify the code in the same way, then compile and run:
ant streams
5. List
Now most of you may have registered, and let's try to find out who they are. Again, edit file Lister.java, and find out how to call the service.
Modify, compile and run:
ant list
6. Follow
We have several friends on gTwitter already, so let's follow them so that we can get what they put on their microblogs.
ant follow -Duser=<username_2_follow>
You can follow more people, one each time.
7. Finally
Now let's see our streams again, and this time, you'll see also the posts by those we are following.
ant streams
- Login to post comments

