Java Reference
In-Depth Information
procedure first examines the
javax.xml.soap.MessageFactory
sys-
tem property, and lastly calls an instance of the
SAAJMetaFactory
class's
MessageFactory newMessageFactory(String protocol)
meth-
odtoreturnthatfactory.Thismethodthrows
SOAPException
whenit'sun-
able to create the factory.
•
MessageFactory newInstance(String protocol)
creates a
MessageFactory
object that is based on the SOAP implementation spe-
cified by the
protocol
argument, which is one of the
SOAPConstants
interface's
DEFAULT_SOAP_PROTOCOL
,
DYNAMIC_SOAP_PROTOCOL
,
SOAP_1_1_PROTOCOL
,or
SOAP_1_2_PROTOCOL
constants. Thismethod
throws
SOAPException
when it's unable to create the factory.
Afterinstantiating
MessageFactory
,calloneofthefollowingmethodstocreate
a
SOAPMessage
instance:
•
SOAPMessage createMessage()
createsandreturnsanew
SOAPMes-
sage
object(actually,aninstanceofaconcretesubclassofthisabstractclass)
with default
SOAPPart
,
SOAPEnvelope
,
SOAPBody
(initially empty) and
SOAPHeader
objects. This method throws
SOAPException
when a
SOAPMessage
instance cannot be created, and
UnsupportedOpera-
tionException
when the
MessageFactory
instance's protocol is
DYNAMIC_SOAP_PROTOCOL
.
•
SOAPMessage createMessage(MimeHeaders headers, In-
putStream in)
internalizes the contents of the given
java.io.InputStream
object into a new
SOAPMessage
object and re-
turns this object. The
MimeHeaders
instance specifies transport-specific
headersthatdescribethevariousattachmentstotheSOAPmessage.Thismeth-
odthrows
SOAPException
whena
SOAPMessage
instancecannotbecre-
ated,
IOException
when there's a problem reading data from the input
stream,and
IllegalArgumentException
whenthe
MessageFactory
instance requires one or more MIME headers to be present in the argument
passed to
headers
and these headers are missing.
The following example shows you how to instantiate the factory and create a
SOAPMessage
object that is ready to be populated:
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage soapm = mf.createMessage();