📄 saaj4.html
字号:
Name is businessListAttribute name is genericAttribute value is 2.0Attribute name is operatorAttribute value is www.ibm.com/services/uddiAttribute name is truncatedAttribute value is falseAttribute name is xmlnsAttribute value is urn:uddi-org:api_v2...<a name="wp88965"> </a></pre></div><a name="wp88977"> </a><p class="pBody">To run <code class="cCode">DOMSrcExample</code>, use a command like the following:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">asant run-domsrc -Dxml-file=domsrc2.xml<a name="wp88978"> </a></pre></div><a name="wp88979"> </a><p class="pBody">When you run <code class="cCode">DOMSrcExample</code>, you will see output that begins like the following:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">run-domsrc: Running DOMSrcExample. Body contents: Content is: Name is businessList Attribute name is generic Attribute value is 2.0 Attribute name is operator Attribute value is www.ibm.com/services/uddi Attribute name is truncated Attribute value is false Attribute name is xmlns Attribute value is urn:uddi-org:api_v2 ...<a name="wp88980"> </a></pre></div><a name="wp88981"> </a><p class="pBody">If you run <code class="cCode">DOMSrcExample</code> with the file <code class="cCode">uddimsg.xml</code> or <code class="cCode">slide.xml</code>, you will see runtime errors.</p><a name="wp88966"> </a><h3 class="pHeading2">Attachments.java</h3><a name="wp88967"> </a><p class="pBody">The example <code class="cCode">Attachments.java</code>, based on the code fragments in the sections <a href="SAAJ3.html#wp79746">Creating an AttachmentPart Object and Adding Content</a> and <a href="SAAJ3.html#wp64148">Accessing an AttachmentPart Object</a>, creates a message with a text attachment and an image attachment. It then retrieves the contents of the attachments and prints out the contents of the text attachment. You will find the code for <code class="cCode">Attachments</code> in the following directory:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative"><<code class="cVariable">INSTALL</code>>/j2eetutorial14/examples/saaj/attachments/src/<a name="wp87689"> </a></pre></div><a name="wp88998"> </a><p class="pBody"><code class="cCode">Attachments</code> first creates a message in the usual way. It then creates an <code class="cCode">AttachmentPart</code> for the text attachment:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">AttachmentPart attachment1 = message.createAttachmentPart();<a name="wp88999"> </a></pre></div><a name="wp89000"> </a><p class="pBody">After it reads input from a file into a string named <code class="cCode">stringContent</code>, it sets the content of the attachment to the value of the string and the type to text-plain, and also sets a content ID.</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">attachment1.setContent(stringContent, "text/plain");attachment1.setContentId("attached_text");<a name="wp89001"> </a></pre></div><a name="wp89002"> </a><p class="pBody">It then adds the attachment to the message:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">message.addAttachmentPart(attachment1);<a name="wp89003"> </a></pre></div><a name="wp89004"> </a><p class="pBody">The example uses a <code class="cCode">javax.activation.DataHandler</code> object to hold a reference to the graphic that constitutes the second attachment. It creates this attachment using the form of the <code class="cCode">createAttachmentPart</code> method that takes a <code class="cCode">DataHandler</code> argument.</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">// Create attachment part for imageURL url = new URL("file:///./xml-pic.jpg"); DataHandler dataHandler = new DataHandler(url); AttachmentPart attachment2 = message.createAttachmentPart(dataHandler); attachment2.setContentId("attached_image"); message.addAttachmentPart(attachment2);<a name="wp89005"> </a></pre></div><a name="wp89006"> </a><p class="pBody">The example then retrieves the attachments from the message. It displays the <code class="cCode">contentId</code> and <code class="cCode">contentType</code> attributes of each attachment and the contents of the text attachment. Because the example does not display the contents of the graphic, the URL does not have to refer to an actual graphic, although in this case it does.</p><a name="wp87721"> </a><h4 class="pHeading3">Running Attachments</h4><a name="wp87724"> </a><p class="pBody">To run <code class="cCode">Attachments</code>, you use the file <code class="cCode">build.xml</code> that is in the directory <<code class="cVariable">INSTALL</code><code class="cCode">>/j2eetutorial14/examples/saaj/attachments/</code>.</p><a name="wp87743"> </a><p class="pBody">To run <code class="cCode">Attachments</code>, use the following command:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">asant run -Dfile=<code class="cVariable">path_name</code><a name="wp87749"> </a></pre></div><a name="wp87785"> </a><p class="pBody">Specify any text file as the <code class="cVariable">path_name</code> argument. The <code class="cCode">attachments</code> directory contains a file named <code class="cCode">addr.txt</code> that you can use:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">asant run -Dfile=addr.txt<a name="wp87786"> </a></pre></div><a name="wp87750"> </a><p class="pBody">When you run <code class="cCode">Attachments</code> using this command line, you will see output like the following:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">Running Attachments.Attachment attached_text has content type text/plainAttachment contains:Update address for Sunny Skies, Inc., to 10 Upbeat StreetPleasant Grove, CA 95439Attachment attached_image has content type image/jpeg<a name="wp87796"> </a></pre></div><a name="wp87678"> </a><h3 class="pHeading2">SOAPFaultTest.java</h3><a name="wp87621"> </a><p class="pBody">The example <code class="cCode">SOAPFaultTest.java</code>, based on the code fragments in the sections <a href="SAAJ3.html#wp69922">Creating and Populating a SOAPFault Object</a> and <a href="SAAJ3.html#wp70057">Retrieving Fault Information</a>, creates a message with a <code class="cCode">SOAPFault</code> object. It then retrieves the contents of the <code class="cCode">SOAPFault</code> object and prints them out. You will find the code for <code class="cCode">SOAPFaultTest</code> in the following directory:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative"><<code class="cVariable">INSTALL</code>>/j2eetutorial14/examples/saaj/fault/src/<a name="wp87629"> </a></pre></div><a name="wp87630"> </a><h4 class="pHeading3">Running SOAPFaultTest</h4><a name="wp87631"> </a><p class="pBody">To run <code class="cCode">SOAPFaultTest</code>, you use the file <code class="cCode">build.xml</code> that is in the directory <<code class="cVariable">INSTALL</code><code class="cCode">>/j2eetutorial14/examples/saaj/fault/</code>.</p><a name="wp87632"> </a><p class="pBody">To run <code class="cCode">SOAPFaultTest</code>, use the following command:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">asant run<a name="wp87633"> </a></pre></div><a name="wp87634"> </a><p class="pBody">When you run <code class="cCode">SOAPFaultTest</code>, you will see output like the following (line breaks have been inserted in the message for readability):</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">Here is what the XML message looks like:<a name="wp87635"> </a><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Client</faultcode><faultstring>Message does not have necessary info</faultstring><faultactor>http://gizmos.com/order</faultactor><detail><PO:order xmlns:PO="http://gizmos.com/orders/">Quantity element does not have a value</PO:order><PO:confirmation xmlns:PO="http://gizmos.com/confirm">Incomplete address: no zip code</PO:confirmation></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>SOAP fault contains: Fault code = SOAP-ENV:Client Local name = Client Namespace prefix = SOAP-ENV, bound to http://schemas.xmlsoap.org/soap/envelope/ Fault string = Message does not have necessary info Fault actor = http://gizmos.com/order Detail entry = Quantity element does not have a value Detail entry = Incomplete address: no zip code<a name="wp87636"> </a></pre></div> </blockquote> <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"> <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="SAAJ3.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="SAAJ5.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"><p><font size="-1">All of the material in <em>The J2EE(TM) 1.4 Tutorial</em> is <a href="J2EETutorialFront2.html">copyright</a>-protected and may not be published in other workswithout express written permission from Sun Microsystems.</font> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -