POP-OUT | CLOSE
SOAP services will be retired at 12/31/2012. Please migrate
your web services to corresponding RESTful services. Contact us with any questions

Developing for the RCSB PDB Web Services: Writing a Java client

There are several ways to build applications that use web services. This example will demonstrate using web services with Java Axis.

First download axis for Java (http://ws.apache.org/axis/java/releases.html). You should now have a folder that contains the axis distribution. At the time of this tutorial this is axis-1_4.

The best approach is to use axis with Ant (http://ant.apache.org/bindownload.cgi) and even better is to integrate it with Eclipse (http://www.eclipse.org/downloads/). Setting this up is beyond the scope for the moment.


Make sure you have the latest version of java.

On a command line type the following:

java -version

You should see something that indicates a version greater than 1.3.

Example: java version "1.5.0_08" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03) Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixed mode)

Cygwin

This tutorial uses bash shell in cygwin. If you do not have cygwin, download it from (http://www.cygwin.com/) and click the Òinstall cygwinÓ icon.


Generate Java stubs

Now we are ready to generate the Java stubs from the Web Services WSDL file located on the PDB web site. On the command line run the following:

java -classpath "axis-1_4/lib/axis.jar;axis-1_4/lib/commons-logging-1.0.4.jar;axis-1_4/lib/commons-discovery-0.2.jar;axis-1_4/lib/jaxrpc.jar;axis-1_4/lib/saaj.jar;axis-1_4/lib/wsdl4j-1.5.1.jar" org.apache.axis.wsdl.WSDL2Java http://www.pdb.org/pdb/services/pdbws?WSDL

This is a long command and this is where Ant and Eclipse come in handy. However, this will convert the PDB WSDL file located at http://www.pdb.org/pdb/services/pdbws?WSDL into a Java stubs package.

If you look in the directory (e.g. type ÒlsÓ ) you will see a new directory that contains the package of all the new Java files.


Build Application

Now we are ready to build our web services Java application. For the purposes of this demonstration we will make this a very simple application that retrieves the secondary structure for a set of PDB chain IDÕs.

The first thing we need to do is to create a web service locator object. If we look in the package that was generated we will see that there is a file called PdbWebServiceServiceLocator.java. This is the locator object. In the source we simply instantiate this:

PdbWebServiceServiceLocator locator = new PdbWebServiceServiceLocator ();

From this we can retrieve the PDB web services for a particular physical location using a URL.

URL url = new URL ("http://www.pdb.org/pdb/services/pdbws" ); PdbWebService p = locator.getpdbws( url );

Now we have the PdbWebService object that allows us to make our calls. If you have not already figured this out, this PdbWebService object is located in the axis-generated package and viewing this file (PdbWebServices.java) allows you to see all the available web services through a Java interface.


Source code

Here is the source for a simple Java client that gets the secondary structure in ASCII format:

import java.net.URL; import localhost.pdbws.PdbWebService; import localhost.pdbws.PdbWebServiceServiceLocator; public class SimpleSecondary{ public static void main ( String[] _args ){ // create the locator object PdbWebServiceServiceLocator locator = new PdbWebServiceServiceLocator (); try { // create a url object that contains the location of the WSDL URL url = new URL ( "http://www.pdb.org/pdb/services/pdbws" ); PdbWebService p = locator.getpdbws( url ); String sequence = p.getKabschSander("1MWP", "A"); System.out.println ( " sequence 1: "+ sequence ); String sequence1 = p.getKabschSander("4hhb", "A"); System.out.println ( " sequence 2: "+ sequence1 ); String sequence2 = p.getKabschSander("4hhb", "B"); System.out.println ( " sequence 3: "+ sequence2 ); String sequence3 = p.getKabschSander("1Y98", "A"); System.out.println ( " sequence 4: "+ sequence3 ); String sequence4 = p.getKabschSander("1HVR", "B"); System.out.println ( " sequence 5: "+ sequence4 ); } catch ( Exception _e ) { _e.printStackTrace(); } } }

Compile this Java file using JDK (Java Development Kit 1.4 or greater):

javac -classpath "axis-1_4/lib/axis.jar;axis-1_4/lib/jaxrpc.jar;." SimpleSecondary.java

(make sure you are in the directory where axis is. In other words make sure the classpath is correct).

Run the Java program:

java -classpath "axis-1_4/lib/axis.jar;axis-1_4/lib/jaxrpc.jar;axis-1_4/lib/axis.jar;axis-1_4/lib/commons-logging-1.0.4.jar;axis-1_4/lib/commons-discovery-0.2.jar;axis-1_4/lib/saaj.jar;axis-1_4/lib/wsdl4j-1.5.1.jar;." SimpleSecondary

Where the secondary structure ASCII output for the Kabsch & Sander algorithm looks like the following:

EEE TTSB EEE TTT EEE TTS B SHHHHHHHHHHHSTTS EEEEEE SS EEE EEEGGGEEEE EEE EEEEE