Java Reference
In-Depth Information
Note
Check out the “Famous Places” page (
http://cas.sdss.org/dr6/
tp://cas.sdss.org/
)
to obtain the right ascension and declination values for
various astronomical images.
Working with RESTful Web Services
JAX-WSalsosupportsRESTfulwebservices.Thissectionfirstshowsyouhowtocre-
ateandaccessyourownRESTfullibrarywebservice,publishthiswebservicelocally
via the default lightweight HTTP server, and access the service via a simple client. It
thenshowsyouhowtoaccessGoogle'sRESTfulChartswebservicetoobtainchartim-
ages corresponding to entered data values.
Note
JavaEEprovidesJavaAPIforRESTfulWebServices(JAX-RS)tosimplify
the creation of RESTful web services via various annotations. For example,
@GET
is
arequestmethod(HTTPverb)designatorcorrespondingtothesimilarlynamedHTTP
verb.TheJavamethodannotatedwiththisrequestmethoddesignatorprocessesHTTP
GET
requests.CheckoutChapter19“BuildingRESTfulWebServiceswithJAX-RS”
in the Java EE 6 Tutorial (see
http://download.oracle.com/javaee/6/
tutorial/doc/giepu.html
)
to learn about JAX-RS.
Creating and Accessing a Library Web Service
Thelibrarywebservice,whichI'venamedLibrary,consistsofthefourHTTPoperations
thathandlerequeststodeleteaspecificbook(identifiedviaitsISBN)orallbooks,get
aspecificbook(identifiedviaitsISBN)ortheISBNsofallbooks,insertanewbook,
class.
Listing 11-11.
Library's endpoint class
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;