Java Reference
In-Depth Information
} catch (ServiceException e)
{
e.printStackTrace();
}
}
}
This recipe uses several classes that were generated by the wsdl2java utility, which
was discussed earlier in this chapter. These classes were generated from the web service
located at the following URL:
http://www.httprecipes.com/1/11/soap/
The URL where the web service resides forms part of the package name created by
AXIS. The following import statement accesses the classes used to access the above web
service.
import com.httprecipes.www._1._11.soap.*;
As you can see, the above package name is based on the URL.
Once the classes have been imported, it is very easy to make use of the web service.
First, create a locator object. This is used to locate the web service.
PigLatinTranslatorLocator locator = new PigLatinTranslatorLoca-
tor();
Next, a binding is created between the locator and a local class to access the web ser-
vice.
PigLatinTranslatorBindingStub trans = (PigLatinTranslatorBindingS-
tub) locator.getPigLatinTranslatorPort();
Now that the web service has been bound, you can call any method on the web service
by using the bound object, which in this case is named trans .
System.out.println( trans.translate("Hello world!") );
As you can see, the AXIS framework makes it very easy to use web services.
Recipe #11.3: A Google Hybrid Bot
It is also possible to create a hybrid bot. A hybrid bot uses both traditional HTML pars-
ing, as discussed in the preceding chapters, as well as web services. The Google Search API
is a great choice for hybrid bots. You can use the Google Search API to locate web pages that
match your criteria, and then use a traditional HTML bot to scan these sites for what you are
looking for.
Search WWH ::




Custom Search