SOAPElement API
JAX-RPC
also allows the use of a
javax.xml.soap.SOAPElement
object as a parameter
value for a remote method. This object is intended for when you want
to bypass an existing datatype mapping or when a mapping
doesn’t exist for the data you are using. You can
also use it if you just want to plug in the element by hand.
Regardless of the reasons, whatever you place in the
SOAPElement
parameter becomes the request
envelope’s body.
If you recall the JAXM section, we used the
SOAPElement
like this:
// Add an element and content to the Header name = envelope.createName("From"); javax.xml.soap.SOAPElement childElement = headerElement.addChildElement (name); childElement.addTextNode ("Me");
In this code, we create the element as a side effect of appending the
name to the headerElement
. A more direct way to
create an element uses the SOAPElementFactory
to
create an element and populate its contents. To create a
SOAPElementFactory
, call its static method
newInstance( )
:
javax.xml.soap.SOAPElementFactory sef = javax.xml.soap.SOAPElementFactory.newInstance( ); javax.xml.soap.SOAPElement sel = sef.createElement(...);
The interface for the SOAPElementFactory
is:
package javax.xml.soap; public abstract class SOAPElementFactory{ public abstract SOAPElement create(Name name) throws SOAPException; public abstract SOAPElement create(String localName) throws SOAPException; public abstract SOAPElement create(String localName, String prefix,String uri) throws SOAPException; public static ...
Get Java Web Services now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.