August 29, 2002

GoogleShell

I got David Watson's GoogleShell working but I had to make a few changes. I removed the proxy settings as I don't need a proxy. I made the Google key a parameter, so that I could safely publish the working code and referenced the wsdl file from googe's site as I think the one included with the code is a beta version, at least that was what the error message told me. OK, I'm sold on SOAP being easy to use with Java now.
import electric.registry.Registry;
import electric.util.Context;

public class GoogleShell {

	public static void main( String[] args ) throws Exception{

		String key = args[0];

		// set proxy location and authentication credentials
		Context context = new Context();
		/* Set proxy if necessary..
		context.setProperty( "proxyHost", "your.proxy.here" );
		context.setProperty( "proxyPort", "8080" );
		*/

		// bind to web service whose WSDL is at the specified URL
		String url = "http://api.google.com/GoogleSearch.wsdl";

		IGoogleSearchService google = ( IGoogleSearchService ) Registry.bind(
			url, IGoogleSearchService.class, context
		);

		// invoke the web service as if it was a local java object
		String ret = google.doSpellingSuggestion( key, "Britney Spars" );
		System.out.println( "Spelling = " + ret );

		GoogleSearchResult result = google.doGoogleSearch(
			key, "Stuart Woodward", 0, 10, false, "", false, "lang_en", "latin1", "latin1"
		);
		for ( int i = 0; i < result.endIndex; i++ )
			System.out.println( result.resultElements[i].URL );

	}
}
Output was:
Spelling = Britney Spears http://www2.gol.com/users/stuart/ http://www2.gol.com/users/stuart/celtihs.html http://www.natural-metrics.freeserve.co.uk/ http://www.stuartwoodward.com/history.html http://www.stuartwoodward.com/ http://www.stuartwoodward.com/resume/ http://stuartcw.livejournal.com/ http://stuartcw.livejournal.com/calendar http://lists.w3.org/Archives/Public/www-international/1998JulSep/0052.html http://www.tokyopc.org/tpc/officers.html
Posted by stuartcw at August 29, 2002 01:24 PM
Comments