Here's the actual client application code for the ADB version of the example, which uses its own generated data object classes with a partially unwrapped interface:
public class WebServiceClient
{
public static void main(String[] args) throws Exception { // allow override of target address
String host = args.length > 0 ? args[0] : "localhost";
String port = args.length > 1 ? args[1] : "8080";
String target = "http://" + host + ":" + port +
"/axis2/services/adb-library"; // create the client stub
AdbLibraryStub stub = new AdbLibraryStub(target); // retrieve a book directly
String isbn = "0061020052";
GetBookResponse gbr = stub.getBook(isbn);
BookInformation book = gbr.getGetBookReturn();
if (book == null) {
System.out.println("No book found with ISBN '" + isbn + ''');
} else {
System.out.println("Retrieved '" + book.getTitle() + ''');
} // retrieve the list of types defined
GetTypesResponse gtr = stub.getTypes(new GetTypes());
TypeInformation[] types = gtr.getGetTypesReturn();
System.out.println("Retrieved " + types.length + " types:");
for (int i = 0; i < types.length; i++) {
System.out.println(" '" + types[i].getName() + "' with " +
types[i].getCount() + " books");
} // add a new book
String title = "The Dragon Never Sleeps";
isbn = "0445203498";
try {
stub.addBook("scifi", isbn, new String[] { "Cook, Glen" }, title);
System.out.println("Added '" + title + ''');
title = "This Should Not Work";
stub.addBook("xml", isbn, new String[] { "Nobody, Ima" }, title);
System.out.println("Added duplicate book - should not happen!");
} catch (AddDuplicateFaultException e) {
System.out.println("Failed adding '" + title +
"' with ISBN '" + isbn + "' - matches existing title '" +
e.getFaultMessage().getBook().getTitle() + ''');
} // create a callback instance
BooksByTypeCallback cb = new BooksByTypeCallback(); // retrieve all books of a type asynchronously
stub.startgetBooksByType("scifi", cb);
long start = System.currentTimeMillis();
synchronized (cb) {
while (!cb.m_done) {
try {
cb.wait(100L);
} catch (Exception e) {}
}
}
BookInformation[] books = cb.m_books;
System.out.println("Asynchronous operation took " +
(System.currentTimeMillis()-start) + " millis");
if (cb.m_books != null) {
System.out.println("Retrieved " + books.length +
" books of type 'scifi':");
for (int i = 0; i < books.length; i++) {
System.out.println(" '" + books[i].getTitle() + ''');
}
} else {
System.out.println("Returned exception:");
cb.m_exception.printStackTrace(System.out);
}
} public static class BooksByTypeCallback extends AdbLibraryCallbackHandler
{
private boolean m_done;
private Exception m_exception;
private BookInformation[] m_books; public void receiveResultgetBooksByType(GetBooksByTypeResponse resp) {
m_books = resp.getGetBooksByTypeReturn();
m_done = true;
} public synchronized void receiveErrorgetBooksByType(Exception e) {
m_done = true;
}
};
}
The classes generated by ADB are simple bean-style classes, which makes them fairly easy to use. But ADB's unwrapped support is currently not as comprehensive as JiBX's, which makes the interface a little awkward - it requires a wrapper object to be supplied for requests that don't take any parameters (such as the
getTypes() method), and always returns a wrapped response. Look at the code following the "retrieve a book directly" and "retrieve the list of types defined" comments, for instance, and compare that with the corresponding
JiBX client code.
JiBX also generates appropriate names for the unwrapped parameters in the generated stub and server-side skeleton class, which gives greatly improved usability. As an especially bad example, here's what the unwrapped
getBook() method looks like in ADB:
public com.sosnoski.ws.library.wsdl.AddBookResponse addBook(
java.lang.String param1, java.lang.String param2, java.lang.String[] param3, java.lang.String param4)
throws java.rmi.RemoteException, org.apache.axis2.adb.library.AddDuplicateFaultException;That's somewhat difficult to interpret (to put it mildly). I guessed that the parameters were in the same order as in the WSDL document, so I was able to refer to the schema there to determine the meanings of the different parameters. But JiBX uses the appropriate parameter names directly:
public void addBook(
java.lang.String type, java.lang.String isbn, java.lang.String[] author, java.lang.String title)
throws java.rmi.RemoteException, org.apache.axis2.jibx.library.AddDuplicateFaultException;Once ADB adds full unwrapping support the only major difference will be that JiBX allows you to work with existing classes. If you
don't have existing classes to represent the data, its currently much easier to generate classes from the WSDL for ADB than for JiBX (with JiBX you currently need to extract the schema from the WSDL, then use the outdated Xsd2Jibx tool and manually tweak the resulting classes and binding to suit your needs).