Java Reference
In-Depth Information
For instance, one Yahoo! service allows you to do image searches from your
application. To make a request for, say, images from JavaOne with the results in
JSON form, you can use the following URL:
http://search.yahooapis.com/ ImageSearchService /V1/
imageSearch?appid=YahooDemo&query= JavaOne &results=
2&output= json
Here, we've specified the ImageSearchService , with the text JavaOne as the
search query, and the output set to JSON . Another service that Yahoo! provides is
called the LocalSearchService , which allows you to search for anything in a
particular location. We'll use this service in the sample JavaFX mashup applica-
tion, discussed in the next section. However, let's first take a quick look at the
GeoNames Web service.
GeoNames Web Services
GeoNames provides a number of Web service APIs that return interesting data
relevant to specific locations. For instance, there are services that provide weather
data, Wikipedia data, earthquake data, and so on, for locations you specify. You
can explore the full set of Web service APIs at http://www.geonames.org/export/
ws-overview.html. Most of the GeoNames services support both XML and
JSON as output.
For instance, you can look up weather by airport code (using an airport close to
the location you want the current weather for) with the following URL:
http://ws.geonames.org/weatherIcaoJSON?ICAO=K JFK
Here, we've requested the JSON weather service specifically, and have provided
the airport code JFK with a K as a prefix, per the service contract. Alternatively,
you can request weather data for a specific location supplied as longitude and
latitude data. We're going to use this form of the weather service in the sample
JavaFX mashup application. Let's take a look at how to use JavaFX to call exter-
nal Web services, and then parse the output.
JavaFX and REST
As of version 1.0, JavaFX includes two classes that allow you to easily build REST
clients. These classes are javafx.async.RemoteTextDocument and javafx.data
.pull.PullParser . With RemoteTextDocument (see Figure 10.2), you can asyn-
 
 
Search WWH ::




Custom Search