final String NS_URI = "urn:jwsnut.chapter6.handlerbookservice/wsdl/HandlerBookQuery";
try {
if (args.length != 1) {
usage();
}
// The WSDL URL is the only command line argument
URL wsdlURL = new URL(args[0]);
// Form the names of the service and of the port
QName serviceName = new QName(NS_URI, "HandlerBookService");
QName portName = new QName(NS_URI, "HandlerBookQueryPort");
// Get the Service
ServiceFactory factory = ServiceFactory.newInstance();
Service service = factory.createService(wsdlURL, serviceName);
// Build a handler chain with one handler
QName[] headers = new QName[] {
new QName(NS_URI, "auth"),
new QName(NS_URI, "time")
};
HashMap map = new HashMap();
map.put("debug", "true");
HandlerInfo info = new HandlerInfo(ClientHandler.class, map, headers);
ArrayList handlerList = new ArrayList();
handlerList.add(info);
// Add the handler chain the HandlerRegistry
HandlerRegistry handlerRegistry = service.getHandlerRegistry();
handlerRegistry.setHandlerChain(portName, handlerList);
// Now get the dynamic proxy
HandlerBookQuery bookQuery =
(HandlerBookQuery)service.getPort(portName,
HandlerBookQuery.class);
// Get info for each book.
StringHolder stringHolder = new StringHolder();
int count = bookQuery.getBookCount();
System.out.println("Book count = " + count);
for (int i = 0; i < count; i++) {
String title = bookQuery.getBookTitle(i);
bookQuery.getBookAuthor(title, stringHolder);
System.out.println("Title: " + title + ", author: " + stringHolder.value);
}
// Log success
bookQuery.log("ProxyHandlerBookServiceClient: success");
System.exit(0);
} catch (Throwable t) {
System.out.println("CLASS: " + t.getClass().getName() + "\n\n");
System.out.println(t.getMessage());
t.printStackTrace(System.out);
}