Download Oracle VM VirtualBox Programming Guide and

Transcript
3 Using the raw web service with any
language
The following examples show you how to use the raw web service, without the object-oriented
client-side code that was described in the previous chapter.
3.1 Raw web service example for Java with Axis
Axis is an older web service toolkit created by the Apache foundation. If your distribution does
not have it installed, you can get a binary from http://www.apache.org. The following examples assume that you have Axis 1.4 installed.
The VirtualBox SDK ships with an example for Axis that, again, is called clienttest.java
and that imitates a few of the commands of VBoxManage over the wire.
Then perform the following steps:
1. Create a working directory somewhere. Under your VirtualBox installation directory, find
the sdk/webservice/samples/java/axis/ directory and copy the file clienttest.java
to your working directory.
2. Open a terminal in your working directory. Execute the following command:
java org.apache.axis.wsdl.WSDL2Java /path/to/vboxwebService.wsdl
The vboxwebService.wsdl file should be located in the sdk/webservice/ directory.
If this fails, your Apache Axis may not be located on your system classpath, and you may
have to adjust the CLASSPATH environment variable. Something like this:
export CLASSPATH="/path-to-axis-1_4/lib/*":$CLASSPATH
Use the directory where the Axis JAR files are located. Mind the quotes so that your shell
passes the “*“ character to the java executable without expanding. Alternatively, add a
corresponding -classpath argument to the “java” call above.
If the command executes successfully, you should see an “org” directory with subdirectories containing Java source files in your working directory. These classes represent the
interfaces that the VirtualBox web service offers, as described by the WSDL file.
This is the bit that makes using web services so attractive to client developers: if a language’s toolkit understands WSDL, it can generate large amounts of support code automatically. Clients can then easily use this support code and can be done with just a few
lines of code.
3. Next, compile the clienttest.java source:
javac clienttest.java
This should yield a “clienttest.class” file.
4. To start the VirtualBox web service, open a second terminal and change to the directory
where the VirtualBox executables are located. Then type:
./vboxwebsrv -v
23