|
Page Edited :
CXF20DOC :
Provider Services
Provider Services has been edited by Christian Schneider (Sep 12, 2007). Content:Messaging ModesOverviewObjects that implement the Provider interface have two messaging modes:
The messaging mode you specify determines the level of messaging detail that is passed to your implementation. Message modeWhen using message mode, a Provider implementation works with complete messages. A complete message includes any binding specific headers and wrappers. For example, a Provider implementation that uses a SOAP binding would receive requests as fully specified SOAP message. Any response returned from the implementation would also need to be a fully specified SOAP message. You specify that a Provider implementation uses message mode by providing the value java.xml.ws.Service.Mode.MESSAGE as the value to the javax.xml.ws.ServiceMode annotation. @WebServiceProvider @ServiceMode(value=Service.Mode.MESSAGE) public class stockQuoteProvider implements Provider<SOAPMessage> { ... }
You specify that a Provider implementation uses payload mode by providing the value java.xml.ws.Service.Mode.PAYLOAD as the value to the javax.xml.ws.ServiceMode annotation. @WebServiceProvider @ServiceMode(value=Service.Mode.PAYLOAD) public class stockQuoteProvider implements Provider<DOMSource> { ... }
Data TypesOverviewProvider implementations, because they are low-level objects, cannot use the same JAXB generated types as the higher level consumer APIs. Provider implementations work with the following types of objects:
Using Source objectsA Provider implementation can accept and return objects that are derived from the javax.xml.transform.Source interface. Source objects are low level objects that hold XML documents. Each Source implementation provides methods that access the stored XML documents and manipulate its contents. The following objects implement the Source interface:
Using SOAPMessage objectsProvider implementations can use javax.xml.soap.SOAPMessage objects when the following conditions are true:
A SOAPMessage object, as the name implies, holds a SOAP message. They contain one SOAPPart object and zero or more AttachmentPart objects. The SOAPPart object contains the SOAP specific portions of the SOAP message including the SOAP envelope, any SOAP headers, and the SOAP message body. The AttachmentPart objects contain binary data that was passed as an attachment. Using DataSource objectsProvider implementations can use objects that implement the javax.activation.DataSource interface when the following conditions are true:
DataSource objects provide a mechanism for working with MIME typed data from a variety of sources including URLs, files, and byte arrays. Implementing a Provider ObjectOverviewThe Provider interface is relatively easy to implement. It only has one method, invoke(), that needs to be implemented. In addition it has three simple requirements:
The complexity of implementing the Provider interface surrounds handling the request messages and building the proper responses. Working with messagesUnlike the higher-level SEI based service implementations, Provider implementations receive requests as raw XML data and must send responses as raw XML data. This requires that the developer has intimate knowledge of the messages used by the service being implemented. These details can typically be found in the WSDL document describing the service. WS-I Basic Profile provides guidelines about the messages used by services including:
Implementing the invoke() methodThe Provider interface has only one method, invoke(), that needs to be implemented. invoke() receives the incoming request packaged into the type of object declared by the type of Provider interface being implemented and returns the response message packaged into the same type of object. For example, an implementation of a Provider<SOAPMessage> interface would receive the request as a SOAPMessage object and return the response as a SOAPMessage object. The messaging mode used by the Provider implementation determines the amount of binding specific information the request and response messages contain. Implementation using message mode receive all of the binding specific wrappers and headers along with the request. They must also add all of the binding specific wrappers and headers to the response message. Implementations using payload mode only receive the body of the request. The XML document returned by an implementation using payload mode will be placed into the body of the request message. ExamplesThe following shows a Provider implementation that works with SOAPMessage objects in message mode. import javax.xml.ws.Provider; import javax.xml.ws.Service; import javax.xml.ws.ServiceMode; import javax.xml.ws.WebServiceProvider; @WebServiceProvider(portName="stockQuoteReporterPort" serviceName="stockQuoteReporter") @ServiceMode(value="Service.Mode.MESSAGE") public class stockQuoteReporterProvider implements Provider<SOAPMessage> { public stockQuoteReporterProvider() { } public SOAPMessage invoke(SOAPMessage request) { SOAPBody requestBody = request.getSOAPBody(); if(requestBody.getElementName.getLocalName.equals("getStockPrice")) { MessageFactory mf = MessageFactory.newInstance(); SOAPFactory sf = SOAPFactory.newInstance(); SOAPMessage response = mf.createMessage(); SOAPBody respBody = response.getSOAPBody(); Name bodyName = sf.createName("getStockPriceResponse"); respBody.addBodyElement(bodyName); SOAPElement respContent = respBody.addChildElement("price"); respContent.setValue("123.00"); response.saveChanges(); return response; } ... } } The code does the following:
The following shows an example of a Provider implementation using DOMSource objects in payload mode. import javax.xml.ws.Provider; import javax.xml.ws.Service; import javax.xml.ws.ServiceMode; import javax.xml.ws.WebServiceProvider; @WebServiceProvider(portName="stockQuoteReporterPort" serviceName="stockQuoteReporter") @ServiceMode(value="Service.Mode.PAYLOAD") public class stockQuoteReporterProvider implements Provider<DOMSource> public stockQuoteReporterProvider() { } public DOMSource invoke(DOMSource request) { DOMSource response = new DOMSource(); ... return response; } } The code does the following:
|
Unsubscribe or edit your notifications preferences
