FileDocCategorySizeDatePackage
PeopleFinderRPCClient.javaAPI DocExample5630Thu Dec 15 21:39:42 GMT 2005com.oreilly.jent.people.soap

PeopleFinderRPCClient

public class PeopleFinderRPCClient extends Object
Simple command-line client for the PeopleFinder SOAP service.

Fields Summary
private static Logger
sLog
private static final String
USAGE
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

    
         
        HashMap searchParams = new HashMap();
        // Parse the command-line arguments, construct the search
        // parameters name/value map along the way
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-first")) {
                if (i >= args.length) {
                    sLog.info(USAGE);
                    return;
                }
                else {
                    i++;
                    searchParams.put(PersonDAO.FIRST_NAME, args[i]);
                }
            }
            else if (args[i].equals("-last")) {
                if (i >= args.length) {
                    sLog.info(USAGE);
                    return;
                }
                else {
                    i++;
                    searchParams.put(PersonDAO.LAST_NAME, args[i]);
                }
            }
            else if (args[i].equals("-email")) {
                if (i >= args.length) {
                    sLog.info(USAGE);
                    return;
                }
                else {
                    i++;
                    searchParams.put(PersonDAO.EMAIL, args[i]);
                }
            }
        }
        
        try {
            // Get the remote service reference
            com.oreilly.jent.people.soap.pfclient.PeopleFinder finder = 
                new PeopleFinderWSLocator().getPeopleFinderPort(new URL("http://localhost:9090/JEnt-examples/services/peopleFinder"));
            // Convert the search args into an array of SearchArg objects
            SearchArg[] sargs = new SearchArg[searchParams.size()];
            if (searchParams.size() > 0) {
                Iterator kIter = searchParams.keySet().iterator();
                int i = 0;
                while (kIter.hasNext()) {
                    String name = (String)kIter.next();
                    SearchArg arg = new SearchArg();
                    arg.setName(name);
                    arg.setValue((String)searchParams.get(name));
                    sargs[i] = arg;
                    i++;
                }
            }
            
            // Perform the search
            com.oreilly.jent.people.soap.pfclient.Person[] people = 
                finder.findPeople(sargs);
            // Print the results
            for (int i = 0; i < people.length; i++) {
                com.oreilly.jent.people.soap.pfclient.Person p = people[i];
                sLog.info(p.getFirstName() + " " + p.getLastName());
                for (int j = 0; j < p.getEmailAddresses().length; j++) {
                    String email = p.getEmailAddresses()[j];
                    sLog.info("\temail: " + email);
                }
                sLog.info("\n");
            }
        }
        catch (com.oreilly.jent.people.soap.pfclient.InvalidSearchException ise) {
            sLog.severe("Search failed: " + ise.getMessage());
        }
        catch (com.oreilly.jent.people.soap.pfclient.PersistenceException pe) {
            sLog.severe("Persistence problem during search: " + pe.getMessage());
        }
        catch (ServiceException se) {
            sLog.severe("Service failure while talking to people finder service: "
                        + se.getMessage());
        }
        catch (RemoteException re) {
            sLog.severe("Failed to make remote method call: " + re.getMessage());
            re.printStackTrace();
        }
        catch (MalformedURLException mue) {
            sLog.severe("Bad service URL: " + mue.getMessage());
        }