📄 saaj2.html
字号:
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <title>Overview of SAAJ</title> <link rel="StyleSheet" href="document.css" type="text/css" media="all" /> <link rel="StyleSheet" href="catalog.css" type="text/css" media="all" /> <link rel="Table of Contents" href="J2EETutorialTOC.html" /> <link rel="Previous" href="SAAJ.html" /> <link rel="Next" href="SAAJ3.html" /> <link rel="Index" href="J2EETutorialIX.html" /> </head> <body> <table width="550" summary="layout" id="SummaryNotReq1"> <tr> <td align="left" valign="center"> <font size="-1"> <a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a> <br> <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a> <br> <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a> </td> <td align="center" valign="center"><a accesskey="p" href="SAAJ.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="SAAJ3.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a> </td> <td align="right" valign="center"> <font size="-1"> <a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a> <br> <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a> <br> <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font> </font> </td> </tr> </table> <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"> <blockquote><a name="wp72293"> </a><h2 class="pHeading1">Overview of SAAJ</h2><a name="wp72294"> </a><p class="pBody">This overview presents a high level view of how SAAJ messaging works and explains concepts in general terms. Its goal is to give you some terminology and a framework for the explanations and code examples that are presented in the tutorial section.</p><a name="wp63938"> </a><p class="pBody">The overview looks at SAAJ from two perspectives:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp63939"> </a><div class="pSmartList1"><li>Messages</li></div><a name="wp63940"> </a><div class="pSmartList1"><li>Connections</li></div></ul></div><a name="wp63942"> </a><h3 class="pHeading2">Messages</h3><a name="wp63943"> </a><p class="pBody">SAAJ messages follow SOAP standards, which prescribe the format for messages and also specify some things that are required, optional, or not allowed. With the SAAJ API, you can create XML messages that conform to the SOAP 1.1 and WS-I Basic Profile 1.0 specifications simply by making Java API calls. </p><a name="wp63944"> </a><h4 class="pHeading3">The Structure of an XML Document</h4><hr><a name="wp63946"> </a><p class="pNote">Note: For more complete information on XML documents, see Chapters <a href="IntroXML.html#wp64789">2</a> and <a href="JAXPIntro.html#wp65366">4</a>. </p><hr><a name="wp63947"> </a><p class="pBody">An XML document has a hierarchical structure with elements, subelements, subsubelements, and so on. You will notice that many of the SAAJ classes and interfaces represent XML elements in a SOAP message and have the word <em class="cEmphasis">element</em> or <em class="cEmphasis">SOAP</em> or both in their names.</p><a name="wp63948"> </a><p class="pBody">An element is also referred to as a <span style="font-style: italic">node</span>. Accordingly, the SAAJ API has the interface <code class="cCode">Node</code>, which is the base class for all the classes and interfaces that represent XML elements in a SOAP message. There are also methods such as <code class="cCode">SOAPElement.addTextNode</code>, <code class="cCode">Node.detachNode</code>, and <code class="cCode">Node.getValue</code>, which you will see how to use in the tutorial section.</p><a name="wp63949"> </a><h4 class="pHeading3">What Is in a Message?</h4><a name="wp63950"> </a><p class="pBody">The two main types of SOAP messages are those that have attachments and those that do not.</p><a name="wp63951"> </a><h5 class="pHeading4">Messages with No Attachments</h5><a name="wp63952"> </a><p class="pBody">The following outline shows the very high level structure of a SOAP message with no attachments. Except for the SOAP header, all the parts listed are required to be in every SOAP message.</p><a name="wp63954"> </a><p class="pBody">I. SOAP message</p><a name="wp63955"> </a><p class="pBody"> A. SOAP part</p><a name="wp63956"> </a><p class="pBody"> 1. SOAP envelope</p><a name="wp63957"> </a><p class="pBody"> a. SOAP header (optional)</p><a name="wp63958"> </a><p class="pBody"> b. SOAP body</p><a name="wp63960"> </a><p class="pBody">The SAAJ API provides the <code class="cCode">SOAPMessage</code> class to represent a SOAP message, the <code class="cCode">SOAPPart</code> class to represent the SOAP part, the <code class="cCode">SOAPEnvelope</code> interface to represent the SOAP envelope, and so on. <a href="SAAJ2.html#wp63962">Figure 9-1</a> illustrates the structure of a SOAP message with no attachments.</p><a name="wp63961"> </a><p class="pBody">When you create a new <code class="cCode">SOAPMessage</code> object, it will automatically have the parts that are required to be in a SOAP message. In other words, a new <code class="cCode">SOAPMessage</code> object has a <code class="cCode">SOAPPart</code> object that contains a <code class="cCode">SOAPEnvelope</code> object. The <code class="cCode">SOAPEnvelope</code> object in turn automatically contains an empty <code class="cCode">SOAPHeader</code> object followed by an empty <code class="cCode">SOAPBody</code> object. If you do not need the <code class="cCode">SOAPHeader</code> object, which is optional, you can delete it. The rationale for having it automatically included is that more often than not you will need it, so it is more convenient to have it provided. </p><a name="wp70705"> </a><p class="pBody">The <code class="cCode">SOAPHeader</code> object may contain one or more headers with information about the sending and receiving parties. The <code class="cCode">SOAPBody</code> object, which always follows the <code class="cCode">SOAPHeader</code> object if there is one, provides a simple way to send information intended for the ultimate recipient. For example, if there is a <code class="cCode">SOAPFault</code> object (see <a href="SAAJ3.html#wp77454">Using SOAP Faults</a>), it must be in the <code class="cCode">SOAPBody</code> object.</p><a name="wp73085"> </a><p class="pBody"></p><div align="left"><img src="images/Fig9-1.gif" height="307" width="279" alt="SOAPMessage Object with No Attachments" border="0" hspace="0" vspace="0"/></div><p class="pBody">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -