Java Reference
In-Depth Information
SOAPMessage describesaSOAPmessageoptionallyfollowedbyMIME-typedat-
tachments.TheSOAPmessagepartofthisobjectisdefinedbyaninstanceofaconcrete
subclass of the abstract SOAPPart class.
SOAPPart encapsulatesaninstanceofaclassthatimplementsthe SOAPEnvelope
interface, and the SOAPEnvelope instance encapsulates instances of classes that
implement the SOAPHeader and SOAPBody interfaces. Call SOAPMessage 's
SOAPPart getSOAPPart() method to return the SOAPPart instance. You can
then call SOAPPart 's SOAPEnvelope getEnvelope() method to return the
SOAPEnvelope instance,andcall SOAPEnvelope 's SOAPBody getBody() and
SOAPHeader getHeader() methods to return the SOAPEnvelope instance's
SOAPBody and SOAPHeader instances.
Tip Becausea SOAPEnvelope instancedefaultstostoringanempty SOAPHead-
er instance,youcanremovethis SOAPHeader instancewhenit'snotneededbycall-
ing SOAPHeader 's inherited (from the javax.xml.soap.Node interface) void
detachNode() method.
Thefollowingexampleshowsyouhowtoobtainthe SOAPPart , SOAPEnvelope ,
and SOAPBody instances from the SOAPMessage instance, and also how to detach
the SOAPHeader instance:
SOAPPart soapp = soapm.getSOAPPart();
SOAPEnvelope soape = soapp.getEnvelope();
SOAPBody soapb = soape.getBody();
soape.getHeader().detachNode();
Tip SOAPMessage declares SOAPBody getSOAPBody() and SOAPHeader
getSOAPHeader() methods that conveniently let you access the SOAPBody and
SOAPHeader instances without having to go through getEnvelope() . Calling
thesemethodsisequivalenttocalling getEnvelope().getBody() and getEn-
velope().getHeader() , respectively.
SOAPEnvelope and various other interfaces extend SOAPElement , which
provides methods that are applicable to different kinds of element implementation
instances. For example, the SOAPElement addNamespaceDeclara-
tion(String prefix, String uri) methodisusefulforaddinganamespace
declarationwiththespecified prefix and uri valuestoa SOAPEnvelope instance.
Thefollowingexampleshowshowtoadddeclarationsforthe xsd and xsi namespaces
shown in Listing 11-16 to its Envelope element:
Search WWH ::




Custom Search