This sample explains in detail the semantics of the function calls of Axis
Client (Sync/Async) and how you can make use of the Google Web APIs spell
checking service (doSpellingSuggestion).
Spell suggestion requests submit a query to the service and receives in return a
suggested spell correction for the query (if available). Spelling requests are
subjected to the same query string limitations as any other search request. (The
input string is limited to 2048 bytes and 10 individual words.)
In order to use the Google Web APIs you first must register with Google to receive a license key. You can do this online at http://www.google.com/apis/ ."Key" is the essential thing that is required for you to access the doSpellingSuggestion service. However note that your key will have a limit of 1000 queries per day . This key can be used to build your own SOAP based clients as well. For further information http://www.google.com/apis/.
The first and the easiest option is downloading the binary distribution which includes the compiled samples. Scripts are included for starting the program in either Windows or Unix.
Second option is to build the samples from source. This has to be done with Maven. All you have to do is go to Modules/Samples and type maven in the command prompt. This will compile and will build all the jars required and copy the necessary scripts as well.
Execute the necessary shell scripts / batch files to start the tool.
The Async Mode screen is the default and would show up like this.
If the Mode menu can be used to switch to the Sync Mode
The Sync mode screen looks as follows
The Key can be set using the settings menu
The text boxes can be cleared using the clear menu
Finally the help menu will pop up this help screen
Now you can start doing Google spell checker. Even though the tool uses the default license key it is advisable to obtain a key of your own . If you have got your own license key, you can set it by Set->key in the menu bar. First you should select the type of call (either sync or async) from the menu bar. You can see that there are two different GUIs for each call. Its because logic behind the two calls. When you work with Sync Client you can type the word in the text field given and press the send button to call Google . Suggested words will be displayed on the bottom text field. On the other hand ,the async client behaves differently. You can keep typing the words continuously on the text area and at each press of the enter or the space key ,a request will be sent and the results will be displayed in few seconds in next text area.
Asynchronous Client and Synchronous Client build by the following classes.
The main method is inside the SuggessionForm class. It creates objects of
AsyncPanel and SyncPanel. setSyncPanel and setAsyncPanel method call to the GUI
to display the appropriate GUI. After that, the program is running according to
the selected (events fired by the GUI) call (Async/Sync) . KeyListner in the
AsyncPanel is listening to the characters typed in the text area and when it
detects a Space or Enter key press, it calls the doAsyncSpellingSuggestion
method and sends requests to the Google Web API. User can type continuously without any
interruption. When the response arrives the oncomplete method of the callback is
invoked which in turn updates the text area . In the response SOAP body, the suggested
text is returned. This is extracted and displayed on the text area. The
call to the Google web API from the Async Client is done by the
call.invokeNonBlocking("doGoogleSpellingSugg",requestElement,new
GoogleCallBack(word));
axisop – is a string which caries the operation name.
toSend – is a Element that holds the request soap envelope.
callback – is a class that receives the response soap envelope.
In non blocking API client, the client will not hang until the operation
completes ,on the other hand it needs a callback
mechanism to get the responses (if any) for a service invocation. To get this
response client has to register a call back with the SOAP engine. When the
response is received , SOAPEngine calls the onComplete(AsyncResult) of the
call back object.
On the other hand with the SyncClient the main difference is after typing a word there
is a button to be pressed which sends a call to the Google Web API. This call is
done in a synchronized manner using the invokeBlocking("doGoogleSpellingSugg",requestElement)
statement.
In a blocking client API , the client will keep blocking till it gets the
response (if any) from the service. This is the preferred method when invoking
web services that do not take long time to complete and the hanging in the
client side is negligible. This will be a huge drawback in the client side
performance, if the operation takes considerable amount of time where the
asynchronous capability will be useful.
The request SOAP message is built at the FormModel class. According to the Google Web API WSDL file, required namespaces are selected and attached to the envelope. We don't have to include anything in the header. The name of the first child element of the body should be operation name and it should be namespace qualified. We also have to include the binding namespace to this element. Here, it is attached as an attribute to that element,
OMElement method = omfactory.createOMElement("doSpellingSuggestion", opN);
method.addAttribute("soapenv:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/",null);
You can find a sample SOAP response message from the toolkit that you download
from the Google Web API page. To get the suggested text first take the body of
the SOAP Envelop .In the SOAP Envelop there are two
elements(doSpellingSuggestionResponse, return) but we only want one of them that
is “return” element. Then acquire the text of the return “element”. That is the
“suggested string” from Google.!!
QName qName1 = new QName("urn:GoogleSearch", "doSpellingSuggestionResponse");
QName qName2 = new QName("urn:GoogleSearch", "return");
SOAPBody body = responseEnvelope.getBody();
OMElement val =
body.getFirstChildWithName(qName1).getFirstChildWithName(qName2);
String sugestion = val.getText();