LibraryToggle FramesPrintFeedback

Unlike 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:

  • The root element of a request is based in the value of the name attribute of the wsdl:operation element that corresponds to the operation that is invoked.

    [Warning]Warning

    If the service uses doc/literal bare messages, the root element of the request is based on the value of name attribute of the wsdl:part element referred to by the wsdl:operation element.

  • The root element of all messages is namespace qualified.

  • If the service uses rpc/literal messages, the top-level elements in the messages are not namespace qualified.

    [Important]Important

    The children of top-level elements might be namespace qualified, but to be certain you will must check their schema definitions.

  • If the service uses rpc/literal messages, none of the top-level elements can be null.

  • If the service uses doc/literal messages, then the schema definition of the message determines if any of the elements are namespace qualified.

Example 19.11 shows a Provider implementation that works with SOAPMessage objects in message mode.

Example 19.11. Provider<SOAPMessage> Implementation

import javax.xml.ws.Provider;
import javax.xml.ws.Service;
import javax.xml.ws.ServiceMode;
import javax.xml.ws.WebServiceProvider;

1@WebServiceProvider(portName="stockQuoteReporterPort"
                    serviceName="stockQuoteReporter")
2@ServiceMode(value="Service.Mode.MESSAGE")
public class  stockQuoteReporterProvider implements Provider<SOAPMessage>
{
3public stockQuoteReporterProvider()
  {
  }

4public SOAPMessage invoke(SOAPMessage request)
  {
5  SOAPBody requestBody = request.getSOAPBody();
6  if(requestBody.getElementName.getLocalName.equals("getStockPrice"))
    {
7    MessageFactory mf = MessageFactory.newInstance();
      SOAPFactory sf = SOAPFactory.newInstance();

8    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();
9    return response;
    }
    ...
  }
}

The code in Example 19.11 does the following:

1

Specifies that the following class implements a Provider object that implements the service whose wsdl:service element is named stockQuoteReporter, and whose wsdl:port element is named stockQuoteReporterPort.

2

Specifies that this Provider implementation uses message mode.

3

Provides the required default public constructor.

4

Provides an implementation of the invoke() method that takes a SOAPMessage object and returns a SOAPMessage object.

5

Extracts the request message from the body of the incoming SOAP message.

6

Checks the root element of the request message to determine how to process the request.

7

Creates the factories required for building the response.

8

Builds the SOAP message for the response.

9

Returns the response as a SOAPMessage object.

Example 19.12 shows an example of a Provider implementation using DOMSource objects in payload mode.

Example 19.12. Provider<DOMSource> Implementation

import javax.xml.ws.Provider;
import javax.xml.ws.Service;
import javax.xml.ws.ServiceMode;
import javax.xml.ws.WebServiceProvider;

1@WebServiceProvider(portName="stockQuoteReporterPort" serviceName="stockQuoteReporter")
2@ServiceMode(value="Service.Mode.PAYLOAD")
public class  stockQuoteReporterProvider implements Provider<DOMSource>
3public stockQuoteReporterProvider()
  {
  }

4public DOMSource invoke(DOMSource request)
  {
    DOMSource response = new DOMSource();
    ...
    return response;
  }
}

The code in Example 19.12 does the following:

1

Specifies that the class implements a Provider object that implements the service whose wsdl:service element is named stockQuoteReporter, and whose wsdl:port element is named stockQuoteReporterPort.

2

Specifies that this Provider implementation uses payload mode.

3

Provides the required default public constructor.

4

Provides an implementation of the invoke() method that takes a DOMSource object and returns a DOMSource object.

Comments powered by Disqus
loading table of contents...