All Implemented Interfaces:
SOAPPartobject. By default, a
SOAPMessageobject is created with a
SOAPPartobject that has a
SOAPEnvelopeobject by default has an empty
SOAPBodyobject and an empty
SOAPBodyobject is required, and the
SOAPHeaderobject, though optional, is used in the majority of cases. If the
SOAPHeaderobject is not needed, it can be deleted, which is shown later.
A client can access the
objects by calling the methods
following lines of code use these two methods after starting with
object message to get the
SOAPPart object sp,
which is then used to get the
SOAPEnvelope object se.
SOAPPart sp = message.getSOAPPart(); SOAPEnvelope se = sp.getEnvelope(); SOAPHeader sh = se.getHeader(); SOAPBody sb = se.getBody();
It is possible to change the body or header of a
object by retrieving the current one, deleting it, and then adding
a new body or header. The
deleteNode deletes the XML element (node) on which it is
called. For example, the following line of code deletes the
SOAPBody object that is retrieved by the method
se.getBody().detachNode();To create a
SOAPHeaderobject to replace the one that was removed, a client uses the method
SOAPEnvelope.addHeader, which creates a new header and adds it to the
SOAPEnvelopeobject. Similarly, the method
addBodycreates a new
SOAPBodyobject and adds it to the
SOAPEnvelopeobject. The following code fragment retrieves the current header, removes it, and adds a new one. Then it retrieves the current body, removes it, and adds a new one.
SOAPPart sp = message.getSOAPPart(); SOAPEnvelope se = sp.getEnvelope(); se.getHeader().detachNode(); SOAPHeader sh = se.addHeader(); se.getBody().detachNode(); SOAPBody sb = se.addBody();It is an error to add a
SOAPHeaderobject if one already exists.
SOAPEnvelope interface provides three methods for creating
Name objects. One method creates
Name objects with
a local name, a namespace prefix, and a namesapce URI. The second method creates
Name objects with a local name and a namespace prefix, and the third
Name objects with just a local name. The following line of
code, in which se is a
SOAPEnvelope object, creates a new
Name object with all three.
Name name = se.createName("GetLastTradePrice", "WOMBAT", "http://www.wombat.org/trader");
|Method from javax.xml.soap.SOAPEnvelope Summary:|
|addBody, addHeader, createName, createName, getBody, getHeader|
|Method from javax.xml.soap.SOAPEnvelope Detail:|
public SOAPBody addBody() throws SOAPException
It is illegal to add a body when the envelope already contains a body. Therefore, this method should be called only after the existing body has been removed.
public SOAPHeader addHeader() throws SOAPException
It is illegal to add a header when the envelope already contains a header. Therefore, this method should be called only after the existing header has been removed.
abstract public Name createName(String localName) throws SOAPException
This factory method creates
abstract public Name createName(String localName, String prefix, String uri) throws SOAPException
This factory method creates
public SOAPBody getBody() throws SOAPException
public SOAPHeader getHeader() throws SOAPException