Thursday, July 21, 2005

Writing your first program in Java SOAP

Writing your first program in Java SOAP
---------------------------------------

1) Setup tomcat on your machine. This will be your app container.

2) Write HelloWorld.java (see below). This then becomes the server-side program that will serve the client requests. Compile this and put the helloworld.jar file in your
tomcat's lib directory.

3) Write HelloClient.java (see below). This is the remote client that needs to access the services of HelloWorld.java.

Now we need a router to route client request to the server-side jar helloworld.jar.

4) Download soap.war (from apache) and put it in your tomcat webapps directory. This is the router for soap requests.

PS: To confirm if it is actually installed, point your browser to /soap/admin/index.html. You should see a page which lists all deployed SOAP apps.

5) Next step is to register the HelloWorld server program with the router.
java org.apache.soap.server.ServiceManagerClient http://localhost:8180/soap/servlet/rpcrouter deploy HelloWorld.xml

(see HelloWorld.xml below).

PS: Check if the server is registered or not here:
http://localhost:8180/soap/admin/index.html

6) Run the client:
java HelloClient.java http://localhost:8180/soap/servlet/rpcrouter MyName

Enjoy!

//////////////////// HelloClient.java /////////////////////////
public class HelloClient {
public static void main (String[] args)
throws Exception {

System.out.println("\n\nCalling the SOAP Server to say hello\n\n");
System.out.println("\n\nCalling the SOAP Server to say hello\n\n");
URL url = new URL (args[0]);
String name = args[1];

Call call = new Call ( );
call.setTargetObjectURI("urn:HelloWorld");
call.setMethodName("sayHello");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
Vector params = new Vector ( );
params.addElement (new Parameter("name", String.class, name, null));
call.setParams (params);

System.out.print("The SOAP Server says: ");

Response resp = call.invoke(url, "");

if (resp.generatedFault ( )) {
Fault fault = resp.getFault ( );
System.out.println ("\nOuch, the call failed: ");
System.out.println (" Fault Code = " + fault.getFaultCode ( ));
System.out.println (" Fault String = " + fault.getFaultString ( ));
} else {
Parameter result = resp.getReturnValue ( );
System.out.print(result.getValue ( ));
System.out.println( );
}
}
}
//////////////////// HelloClient.java /////////////////////////

//////////////////// HelloWorld.java /////////////////////////
public class HelloWorld {
public String sayHello(String name) {
return "Hola " + name;
}
}
//////////////////// HelloWorld.java /////////////////////////

//////////////////// HelloWorld.xml /////////////////////////
id="urn:HelloWorld">
scope="Application"
methods="sayHello">



org.apache.soap.server.DOMFaultListener


//////////////////// HelloWorld.xml /////////////////////////

Useful links:
http://www.xml.com/pub/a/2002/01/30/soap.html
http://www.oreilly.com/catalog/progwebsoap/chapter/ch03.html
http://ws.apache.org/soap/

Wednesday, July 20, 2005

Google Moon

http://moon.google.com/

Contains NASA imagery of moon.

Monday, July 18, 2005

Installing CVS on Debian

1) As root, install the cvs package
# apt-get install cvs

- Debian typically installs cvs in /var/lib/cvs directory.
- Debian cvs root directory is owned by root and the group is "src".

2) Setting up a user:
a) Add the following lines to the .bashrc or .profile:
export CVSROOT=:ext:vineet@localhost:/var/lib/cvs/
export CVS_RSH="ssh"

b) Add the user to the group "src" by using the "usermod" command.

3) Password-less ssh login:
Copy your ssh public key from the file ~/.ssh/id_rsa.pub to ~/.ssh/authorized_keys file.

4) Create a new module, if needed, by the command:
cvs import -m "Created foochal.org" foochal.org "Foochal" "zero"

The above command will create a new module in the location:
/var/lib/cvs/foochal.org.

You can tweak the location of the above directory in the cvs by passing the option to import. For details read the CVS manual.