Interface SOAPEnvelope
-
- All Superinterfaces:
Element,Node,Node,SOAPElement
public interface SOAPEnvelope extends SOAPElement
The container for the SOAPHeader and SOAPBody portions of aSOAPPartobject. By default, aSOAPMessageobject is created with aSOAPPartobject that has aSOAPEnvelopeobject. TheSOAPEnvelopeobject by default has an emptySOAPBodyobject and an emptySOAPHeaderobject. TheSOAPBodyobject is required, and theSOAPHeaderobject, though optional, is used in the majority of cases. If theSOAPHeaderobject is not needed, it can be deleted, which is shown later.A client can access the
SOAPHeaderandSOAPBodyobjects by calling the methodsSOAPEnvelope.getHeaderandSOAPEnvelope.getBody. The following lines of code use these two methods after starting with theSOAPMessageobject message to get theSOAPPartobject sp, which is then used to get theSOAPEnvelopeobject 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
SOAPEnvelopeobject by retrieving the current one, deleting it, and then adding a new body or header. Thejakarta.xml.soap.NodemethoddetachNodedeletes the XML element (node) on which it is called. For example, the following line of code deletes theSOAPBodyobject that is retrieved by the methodgetBody.
To create ase.getBody().detachNode();SOAPHeaderobject to replace the one that was removed, a client uses the methodSOAPEnvelope.addHeader, which creates a new header and adds it to theSOAPEnvelopeobject. Similarly, the methodaddBodycreates a newSOAPBodyobject and adds it to theSOAPEnvelopeobject. 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.
It is an error to add aSOAPPart sp = message.getSOAPPart(); SOAPEnvelope se = sp.getEnvelope(); se.getHeader().detachNode(); SOAPHeader sh = se.addHeader(); se.getBody().detachNode(); SOAPBody sb = se.addBody();SOAPBodyorSOAPHeaderobject if one already exists.The
SOAPEnvelopeinterface provides three methods for creatingNameobjects. One method createsNameobjects with a local name, a namespace prefix, and a namesapce URI. The second method createsNameobjects with a local name and a namespace prefix, and the third createsNameobjects with just a local name. The following line of code, in which se is aSOAPEnvelopeobject, creates a newNameobject with all three.Name name = se.createName("GetLastTradePrice", "WOMBAT", "http://www.wombat.org/trader");- Since:
- 1.6
-
-
Field Summary
-
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description SOAPBodyaddBody()Creates aSOAPBodyobject and sets it as theSOAPBodyobject for thisSOAPEnvelopeobject.SOAPHeaderaddHeader()Creates aSOAPHeaderobject and sets it as theSOAPHeaderobject for thisSOAPEnvelopeobject.NamecreateName(String localName)Creates a newNameobject initialized with the given local name.NamecreateName(String localName, String uri)Creates a newNameobject initialized with the given local name and namespace prefix.NamecreateName(String localName, String prefix, String uri)Creates a newNameobject initialized with the given local name, namespace prefix, and namespace URI.SOAPBodygetBody()Returns theSOAPBodyobject associated with thisSOAPEnvelopeobject.SOAPHeadergetHeader()Returns theSOAPHeaderobject for thisSOAPEnvelopeobject.-
Methods inherited from interface org.w3c.dom.Element
getAttribute, getAttributeNode, getAttributeNodeNS, getAttributeNS, getElementsByTagName, getElementsByTagNameNS, getSchemaTypeInfo, getTagName, hasAttribute, hasAttributeNS, removeAttribute, removeAttributeNode, removeAttributeNS, setAttribute, setAttributeNode, setAttributeNodeNS, setAttributeNS, setIdAttribute, setIdAttributeNode, setIdAttributeNS
-
Methods inherited from interface jakarta.xml.soap.Node
detachNode, getParentElement, getValue, recycleNode, setParentElement, setValue
-
Methods inherited from interface org.w3c.dom.Node
appendChild, cloneNode, compareDocumentPosition, getAttributes, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData
-
Methods inherited from interface jakarta.xml.soap.SOAPElement
addAttribute, addAttribute, addChildElement, addChildElement, addChildElement, addChildElement, addChildElement, addChildElement, addNamespaceDeclaration, addTextNode, createQName, getAllAttributes, getAllAttributesAsQNames, getAttributeValue, getAttributeValue, getChildElements, getChildElements, getChildElements, getElementName, getElementQName, getEncodingStyle, getNamespacePrefixes, getNamespaceURI, getVisibleNamespacePrefixes, removeAttribute, removeAttribute, removeContents, removeNamespaceDeclaration, setElementQName, setEncodingStyle
-
-
-
-
Method Detail
-
createName
Name createName(String localName, String prefix, String uri) throws SOAPException
Creates a newNameobject initialized with the given local name, namespace prefix, and namespace URI.This factory method creates
Nameobjects for use in the SOAP/XML document.- Parameters:
localName- aStringgiving the local nameprefix- aStringgiving the prefix of the namespaceuri- aStringgiving the URI of the namespace- Returns:
- a
Nameobject initialized with the given local name, namespace prefix, and namespace URI - Throws:
SOAPException- if there is a SOAP error
-
createName
Name createName(String localName, String uri) throws SOAPException
Creates a newNameobject initialized with the given local name and namespace prefix.This factory method creates
Nameobjects for use in the SOAP/XML document.- Parameters:
localName- aStringgiving the local nameuri- aStringgiving the URI of the namespace- Returns:
- a
Nameobject initialized with the given local name, namespace prefix, and namespace URI - Throws:
SOAPException- if there is a SOAP error
-
createName
Name createName(String localName) throws SOAPException
Creates a newNameobject initialized with the given local name.This factory method creates
Nameobjects for use in the SOAP/XML document.- Parameters:
localName- aStringgiving the local name- Returns:
- a
Nameobject initialized with the given local name - Throws:
SOAPException- if there is a SOAP error
-
getHeader
SOAPHeader getHeader() throws SOAPException
Returns theSOAPHeaderobject for thisSOAPEnvelopeobject.A new
SOAPMessageobject is by default created with aSOAPEnvelopeobject that contains an emptySOAPHeaderobject. As a result, the methodgetHeaderwill always return aSOAPHeaderobject unless the header has been removed and a new one has not been added.- Returns:
- the
SOAPHeaderobject ornullif there is none - Throws:
SOAPException- if there is a problem obtaining theSOAPHeaderobject
-
getBody
SOAPBody getBody() throws SOAPException
Returns theSOAPBodyobject associated with thisSOAPEnvelopeobject.A new
SOAPMessageobject is by default created with aSOAPEnvelopeobject that contains an emptySOAPBodyobject. As a result, the methodgetBodywill always return aSOAPBodyobject unless the body has been removed and a new one has not been added.- Returns:
- the
SOAPBodyobject for thisSOAPEnvelopeobject ornullif there is none - Throws:
SOAPException- if there is a problem obtaining theSOAPBodyobject
-
addHeader
SOAPHeader addHeader() throws SOAPException
Creates aSOAPHeaderobject and sets it as theSOAPHeaderobject for thisSOAPEnvelopeobject.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.
- Returns:
- the new
SOAPHeaderobject - Throws:
SOAPException- if thisSOAPEnvelopeobject already contains a validSOAPHeaderobject
-
addBody
SOAPBody addBody() throws SOAPException
Creates aSOAPBodyobject and sets it as theSOAPBodyobject for thisSOAPEnvelopeobject.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.
- Returns:
- the new
SOAPBodyobject - Throws:
SOAPException- if thisSOAPEnvelopeobject already contains a validSOAPBodyobject
-
-