JAXMServlet | javax.xml.messaging |
JAXM 1.1; JWSDP 1.0 | serializable |
public abstract class JAXMServlet extends javax.servlet.http.HttpServlet { // Public Constructors public JAXMServlet( ); // Protected Class Methods protected static javax.xml.soap.MimeHeaders getHeaders(javax.servlet.http.HttpServletRequest req); protected static void putHeaders(javax.xml.soap.MimeHeaders headers, javax.servlet.http.HttpServletResponse res); // Public Instance Methods public void setMessageFactory(javax.xml.soap.MessageFactory msgFactory); // Public Methods Overriding HttpServlet public void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletExceptionjava.io.IOException; // Public Methods Overriding GenericServlet public void init(javax.servlet.ServletConfig servletConfig) throws javax.servlet.ServletException; // Protected Instance Fields protected javax.xml.soap.MessageFactory msgFactory; }
JAXMServlet is a skeleton servlet that can be subclassed to create a container-resident JAXM client. The subclass must do the following:
Declare that it implements either the OnewayListener or ReqRespListener interface
Install a suitable MessageFactory i n the init( ) method
Provide an implementation of the onMessage( ) method
A SOAP message is delivered to the servlet as an HTTP POST request and is therefore handled in the servlet's doPost( ) method, which converts the body of the request to a javax.xml.soap.SOAPMessage object. This object is then passed to the onMessage( ) method, which the JAXM client is required to implement.
A client should implement the OnewayListener interface if it does not intend to return a reply immediately. In this case, the onMessage( ) method has the following signature:
public void onMessage(SOAPMessage message);
The ReqRespListener interface is intended for clients that create a synchronous reply that is, the reply method is sent back as the body of the HTTP response message. This interface, therefore, has a variant of onMessage( ) that requires the client to construct and return a reply message:
public SOAPMessage onMessage(SOAPMessage message);
In the JAXM reference implementation, it is not possible to construct a working JAXM client that implements the ReqRespListener interface, since the message returned by onMessage( ) is ignored by the JAXM provider. All JAXM clients must, therefore, be asynchronous. It is possible, however, to use JAXMServlet as the base class for a SOAP message receiver that uses the SAAJ API and implements the ReqRespListener interface rather than a JAXM client (although this option is not available for the J2EE 1.4 platform, which does not include JAXM).
The conversion between the representation of a SOAP message in the body of an HTML request or response and the corresponding SOAPMessage is performed by a javax.xml.soap.MessageFactory . A suitable factory must be installed by overriding the init( ) method, calling super.init( ) , and then using the setMessageFactory( ) method. By default, JAXMServlet installs a factory that does not perform processing specific to any of the JAXM profiles. A client that wishes to handle profiled messages (e.g., for WS-Routing or ebXML TRP) must instead supply the message factory provided by that profile. These classes are implementation-dependent, but you can get one in a portable fashion by using the createMessageFactory( ) method of the ProviderConnection class, as the following code snippet shows:
ProviderConnection conn = ProviderConnectionFactory.newInstance( ) .createConnection( ); setMessageFactory(conn.createMessageFactory("soaprp"));