The 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:
-
Specifies that the following class implements a
Provider
object that implements the service whosewsdl:service
element is namedstockQuoteReporter
and whosewsdl:port
element is namedstockQuoteReporterPort
. -
Specifies that this
Provider
implementation uses message mode. -
Provides the required default public constructor.
-
Provides an implementation of the
invoke()
method that takesa SOAPMessage
object and returns aSOAPMessage
object. -
Extracts the request message from the body of the incoming SOAP message.
-
Checks the root element of the request message to determine how to process the request.
-
Creates the factories needed for building the response.
-
Builds the SOAP message for the response.
-
Returns the response as a SOAPMessage object.
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:
-
Specifies that the class implements a
Provider
object that implements the service whosewsdl:service
element is namedstockQuoteReporter
and whosewsdl:port
element is namedstockQuoteReporterPort
. -
Specifies that this Provider implementation uses payload mode.
-
Provides the required default public constructor.
-
Provides an implementation of the
invoke()
method that takes aDOMSource
object and returns aDOMSource
object.
The 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:
-
Specifies that the following class implements a
Provider
object that implements the service whosewsdl:service
element is namedstockQuoteReporter
and whosewsdl:port
element is namedstockQuoteReporterPort
. -
Specifies that this
Provider
implementation uses message mode. -
Provides the required default public constructor.
-
Provides an implementation of the
invoke()
method that takesa SOAPMessage
object and returns aSOAPMessage
object. -
Extracts the request message from the body of the incoming SOAP message.
-
Checks the root element of the request message to determine how to process the request.
-
Creates the factories needed for building the response.
-
Builds the SOAP message for the response.
-
Returns the response as a SOAPMessage object.
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:
-
Specifies that the class implements a
Provider
object that implements the service whosewsdl:service
element is namedstockQuoteReporter
and whosewsdl:port
element is namedstockQuoteReporterPort
. -
Specifies that this Provider implementation uses payload mode.
-
Provides the required default public constructor.
-
Provides an implementation of the
invoke()
method that takes aDOMSource
object and returns aDOMSource
object.