Java Reference
In-Depth Information
•
SOAPEnvelope
optionally contains a
SOAPHeader
instance and also con-
tains a mandatory
SOAPBody
instance.
•
SOAPHeader
represents the SOAP message's header block(s).
•
SOAPBody
contains either a
SOAPFault
object or a
SOAPBodyElement
object containing the actual SOAP payload XML content.
•
SOAPFault
stores a SOAP fault message.
WorkingwithSAAJinvolvescreatingaSOAPconnection,creatingSOAPmessages,
populatingeachmessagewithcontentandoptionalattachments, sendingthemessages
to an endpoint, and retrieving replies.
You create a connection by working with the
SOAPConnectionFactory
and
SOAPConnection
classes. As its name implies,
SOAPConnectionFactory
is a
factory class for retrieving
SOAPConnection
instances (actually, instances of sub-
classesoftheabstract
SOAPConnection
class).A
SOAPConnection
instancerep-
resents an endpoint-to-endpoint connection to the web service; the client and web ser-
vice exchange messages over this connection. The following example shows you how
to instantiate the factory and obtain a SOAP connection:
SOAPConnectionFactory
soapcf
=
SOAPConnectionFact-
ory.newInstance();
SOAPConnection soapc = soapcf.createConnection();
Instantiate the factory by calling
SOAPConnectionFactory
's
SOAPConnec-
tionFactory newInstance()
method.Thismethodthrows
SOAPException
whena
SOAPConnectionFactory
instancecannotbecreated.IfanonOracleJava
implementation doesn't support the SAAJ communication infrastructure, this method
throws an instance of the
java.lang.UnsupportedOperationException
class.
After instantiating
SOAPConnectionFactory
, call this instance's
SOAPCon-
nection createConnection()
method tocreate andreturn anew
SOAPCon-
nection
object.Thismethodthrows
SOAPException
whenit'sunabletocreatethis
object.
Create a SOAP message by working with the
MessageFactory
and
SOAPMes-
sage
classes.
MessageFactory
provides a pair of methods for returning a
Mes-
sageFactory
instance:
•
MessageFactory newInstance()
createsa
MessageFactory
object
basedonthedefaultSOAP1.1implementation.Thismethodfollowsanordered
lookupproceduretolocatethe
MessageFactory
implementationclass.This