FileDocCategorySizeDatePackage
BookMapBookServiceClient.javaAPI DocExample2000Fri Sep 20 12:36:24 BST 2002ora.jwsnut.chapter2.client

BookMapBookServiceClient.java

package ora.jwsnut.chapter2.client;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

// JAX-RPC imports
import javax.xml.rpc.Service;
import javax.xml.rpc.Stub;

// Service imports
import ora.jwsnut.chapter2.bookservice.BookInfo;
import ora.jwsnut.chapter2.bookservice.BookQuery;

// Import for service
import ora.jwsnut.chapter2.bookservice.BookService_Impl;

public class BookMapBookServiceClient {
    
    public static void main(String[] args) {
        
        try {
            if (args.length != 1) {
                usage();
            }
            
            // Get a reference to the stub and set the service address
            BookService_Impl service = new BookService_Impl();
            BookQuery bookQuery = (BookQuery)service.getBookQueryPort();
            ((Stub)bookQuery )._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, args[0]);
            
            // Perform the RPC and print the results          
            HashMap map = bookQuery.getBookMap();
            Iterator iter = map.entrySet().iterator();
            while (iter.hasNext()) {
                Map.Entry entry = (Map.Entry)iter.next();
                BookInfo info = (BookInfo)entry.getValue();
                System.out.println("KEY: [" + entry.getKey() + "], value = "+
                                info.getTitle() + " by " +
                                info.getAuthor() + ", edited by " +
                                info.getEditor() + ", price USD " +
                                info.getPrice());
            }
            System.exit(0);
        } catch (Throwable t) {
            System.out.println("CLASS: " + t.getClass().getName() + "\n\n");
            System.out.println(t.getMessage());
            t.printStackTrace(System.out);
        }
    }  
    
    private static void usage() {
        System.err.println("Usage: BookMapBookServiceClient address");
        System.exit(1);
    }
}