//package GoogleSearch; public class TestGoogle { public static void main (String[] args) throws Exception { System.err.println ("This is to test the Google web service through Apache Axis"); if (args.length != 3) { printUsageAndExit(); } String clientKey = args[0]; String directive = args[1]; String directiveArg = args[2]; // Report the arguments received System.out.println("Parameters:"); System.out.println("Client key = " + clientKey); System.out.println("Directive = " + directive); System.out.println("Args = " + directiveArg); GoogleSearch.GoogleSearchService gss = new GoogleSearch.GoogleSearchServiceLocator(); GoogleSearch.GoogleSearchPort port = gss.getGoogleSearchPort(); try { /* if (directive.equalsIgnoreCase("search")) { s.setQueryString(directiveArg); GoogleSearchResult r = s.doSearch(); System.out.println("Google Search Results:"); System.out.println("======================"); System.out.println(r.toString()); } else if (directive.equalsIgnoreCase("cached")) { System.out.println("Cached page:"); System.out.println("============"); byte [] cachedBytes = s.doGetCachedPage(directiveArg); // Note - this conversion to String should be done with reference // to the encoding of the cached page, but we don't do that here. String cachedString = new String(cachedBytes); System.out.println(cachedString); } else */ if (directive.equalsIgnoreCase("spell")) { System.out.println("Spelling suggestion:"); String suggestion = port.doSpellingSuggestion(clientKey,directiveArg); System.out.println(suggestion); } else { printUsageAndExit(); } } catch (Exception f) { System.out.println("The call to the Google Web APIs failed:"); System.out.println(f.toString()); } } private static void printUsageAndExit(){ System.err.println("Usage: java " + TestGoogle.class.getName() + " " + " (search | cached | spell )"); System.exit(1); } }