C H A P T E R 16 |
Tutorial--Section 4.1 Prepare to Create a Web Service Model |
This chapter describes how to expand the application to access data via a Web service. You must be running a version of the Sun ONE Studio that includes the Web service model wizard. You must also have a connection to the Internet without a proxy/firewall which will interfere with communication to the Web service.
You can expand the existing application by adding a Web service-based model and a page to display that model's data. First, there are some resources you need to download to build a model for a Web service, and you need to register as a user for this Web service.
Download the Google Web service software SDK that contains the WSDL file that the Sun ONE Application Framework needs to create the Web Service model.
1. To download the Google Web Service SDK, go to http://www.google.com/apis/download.html
4. Save the file on your hard drive.
Open the zip file and extract the googleapi/GoogleSearch.wsdl file to your application's lib directory (.../JatoTutorial/WEB-INF/lib). There are three versions of this file in the zip file. Be sure to get the only one that is not under the dotnet directory. That is all you need to build the Web service model.
To use the Google Web service, you must register as a user to receive a key that is passed to the Web service with each query.
1. To register with Google, go to
https://www.google.com/accounts/NewAccount?continue=http://api.google.com/createkey&followup=http://api.google.com/createkey
2. Enter an email address and password to register a new account.
You will receive an email to verify your account. Once you verify your account, you will receive another email with your key (it is a long string of letters and numbers). Keep this email handy because you will need it when you create the Web service model.
Using the WSDL file, you will create a Web service model that will perform an Internet search using the Google Internet search engine via their Web service.
1. Select the main module folder.
2. Click the Add Model button on the Sun ONE Application Framework toolbar.
The Select Model Type panel displays.
3. Enter GoogleSearchModel in the Model name textbox.
4. Select Web Service Model from the model component list.
The Select Local WSDL File panel displays.
Navigate down the JatoTutorial application directory structure to the lib directory (JatoTutorial/WEB-INF/lib), and select GoogleSearch (the WSDL file).
Your file might be in a subdirectory of the lib directory. When you extracted it from the zip file, it was in a base directory called googleapi.
6. Click Finish to create the Web service model.
The GoogleSearchModel object is created in the main module.
7. Double-click the GoogleSearchModel node to view the code in the GoogleSearchModel class.
This Web service has a few operations that can be used. The following tasks focus only on the doGoogleSearch operation.
Copyright © 2003, Sun Microsystems, Inc. All rights reserved.