SOAP is the Simple Object Access Protocol (W3C Note), an XML-based protocol used for typed information exchange. In this work, SOAP is used to access the Google web service.
The Google Web API provides a SOAP interface for
The specification of the service is available as an API description and as a WDSL (Web Service Definition Language) file.
The requests are sent as SOAP-Messages using the HTTP GET command.
Based on the WSDL file, the tool wscompile (included in the Java Web Services Developer Pack) can automatically create stub classes that take care of the communication with the web service.
The following configuration file (config.xml) was used to create the stubs:
<?xml version="1.0" encoding="UTF-8"?> <configuration xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config"> <wsdl location= "http://api.google.com/GoogleSearch.wsdl" packageName="at.heinzi.googleclient.stubs"/> </configuration>
The stubs are being created automatically by ant. See README for details on the compilation process. See build.xml for details on the wscompile parameters necessary to create the stubs.
Accessing the services provided by the Google web service is now as easy as calling a procedure:
stubs.GoogleSearchPort p = new stubs.GoogleSearchService_Impl().getGoogleSearchPort(); r = p.doGoogleSearch(KEY, q, start, 10, false, "", false, "", "", ""); [...] for (int i = 0; i < r.getResultElements().length; i++) { stubs.ResultElement re = r.getResultElements()[i]; System.out.println("(" + Integer.toString(i) + ") " + re.getTitle()); System.out.println(re.getURL()); System.out.println(""); }
This method has been used in StubClient.java to implement the features "search the web", "retrieve cached page", and "ask for spelling suggestion" provided by the Google web service. StubClient allows all parameters (e.g. "filter similar results", "country restrictions") to be set and all return values (e.g. "summary", "snippet", "cached size") to be read.
The StubClient text-mode interface allows to scroll within the results (previous/next 10 results) and to display the details of specific search results. See README for instructions on how to compile and run StubClient.
Behind the scenes, the stub classes create a SOAP message, send the message to the Google web service, retrieve the result, parse it, and return it to the calling function as a Java data type or a class.
XMLClient.java hand-crafts this SOAP message and parses the response manually without using the stub classes. It is restricted to only a limited set of basic web search functionality, as its purpose is to show the handling of SOAP messages rather than the implementation of a fully featured Google client, such as StubClient.
XMLClient consists of the following classes:
XMLPrettyWriter converts SOAP to XML and prints XML in a nice hierarchical representation. To do this, the XML document is being decomposed using the XML-DOM (document object model).
Request represents a Google SOAP request. This class creates an empty SOAP message including only the Google license key and sends the message after it has been completed by a specialized subclass.
SearchRequest is derived from Request and fills the SOAP message with the parameters required to perform a Google web search.
SearchResponse parses the SOAP message containing the response from the Google web service for a web search and outputs the results.
Finally, the public static void main asks for search terms and controls the program flow.
XMLClient outputs the SOAP request message and the SOAP response message from the Google web service in raw XML as well as in a hierachical format. See README for instructions on how to compile and run XMLClient.