Java Reference
In-Depth Information
Note @ServiceMode isn't necessary in the context of a RESTful web service,
whereprotocolmessagesandpayloadsareidentical—I'veincludedthisannotationin
Listing11-11 tobringittoyourattention.However, @ServiceMode wouldbeneces-
sarywhenworkingwithSOAPmessages(byimplementing Provider<SOAPMes-
sage> )andwanting toprocess the entire message instead ofjust the payload. You'll
learnaboutSOAPmessagearchitecturelaterinthischapterwhenIintroducetheSAAJ
API.
@BindingType specifies that Library 's invoke() method receives arbitrary
XMLmessagesoverHTTPbyhavingits value() elementinitializedto HTTPBind-
ing.HTTP_BINDING —thedefaultbindingisSOAP1.1overHTTP.Unlike @Ser-
viceMode , @BindingType must be specified with this initialization; otherwise,
you'll receive a runtime exception when a RESTful client sends a nonSOAP request
message to this web service provider.
Library firstdeclaresa LIBFILE constantthatidentifiesthenameofthefilethat
storesinformationaboutthebooksinthelibrary.IcouldhaveusedJDBCtocreateand
accessalibrarydatabase,butdecidedtouseafiletokeep Listing11-11 frombecoming
longer.
This string constant is initialized to library.ser , where ser indicates that the
file stores serialized data. The stored data is an XML encoding of a map that contains
Book and Author instances—I'llpresentthemap,discussitsencoding/decoding,and
present these classes shortly.
The LIBFILE constantdeclarationisfollowedbya wsContext fielddeclaration,
where wsContext is declared to be of type
javax.xml.ws.WebServiceContext and is annotated with @Resource . We-
bServiceContext isaninterfacethatmakesitpossibleforawebserviceendpoint
implementationclasstoaccessarequestmessage'scontextandotherinformation.The
@Resource annotation causes an implementation of this interface to be injected into
an endpoint implementation class, and causes an instance of this implementation class
(a dependency) to be assigned to the variable.
Note Dependency injection refers to the insertion of a class into another class and
ofobjectsoftheinsertedclasstobeinsertedintoaclassinstance.Theinsertedobjects
areknownas dependencies becauseinstancesoftheclassinwhichtheseobjectswere
inserteddependuponthem.Dependencyinjectionreducesclasscomplexitybyoffload-
ing developer tasks to a dependency injection framework.
Search WWH ::




Custom Search