Java Reference
In-Depth Information
}
}
Following various import statements, Listing 11-11 presents the Library class,
whichisprefixedwith @WebServiceProvider , @ServiceMode ,and @Binding
annotations.
@WebServiceProvider specifiesthat Library isawebserviceendpointclass
implementingthe javax.xml.ws.Provider<T> interface(analternativetoanSEI
for services that need to work at the XML message level) in terms of its T in-
voke(T request) method. The actual type argument passed to type parameter
T identifies the source of request and reponse data, and is one of
javax.xml.transform.Source , javax.activation.DataSource , or
javax.xml.soap.SOAPMessage .ForaRESTfulwebserviceprovider,youwould
specify Source or DataSource for T .
Note Although you can process SOAP messages directly with a web service pro-
vider,itiscommontoignorethesemessagesbyworkingwith @WebService —an-
notatedSEIsandSIBs,aspreviouslydiscussed.Also,youcanworkwithSOAPmes-
sages from an API perspective by using the SAAJ API, which I present later in this
chapter.
WhenarequestismadetotheRESTfulwebservice,theproviderclass's invoke()
methodiscalledwithasourceofbytes,suchasa POST request'sXMLdocument.The
invoke() methodrespondstotherequestinsomeappropriateway,returningasource
of bytes in XML format that form the service's response. This method throws an in-
stanceofthe WebServiceException runtimeexceptionclassoroneofitsdescend-
ent classes (e.g., javax.xml.ws.http.HTTPException ) when something goes
wrong.
Note A class annotated with @WebService exposes a separate method for each
webserviceoperation.Forexample, TempVerter exposes c2f() and f2c() meth-
ods for the Celsius-to-Fahrenheit and Fahrenheit-to-Celsius messages. In contrast,
@WebServiceProvider exposesasingle invoke() methodtohandleallopera-
tions.
@ServiceMode specifiesthat Library 's invoke() methodreceivesentirepro-
tocol messages (instead of message payloads) by having its value() element ini-
tializedto javax.xml.ws.Service.Mode.MESSAGE .Whenthisannotationisn't
present, value() defaults to javax.xml.ws.Service.Mode.PAYLOAD .
Search WWH ::




Custom Search