10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Code Examples<br />

newDetail. Not all SOAPFault objects are required to have a Detail object, so the code tests to<br />

see whether newDetail is null. If it is not, the code prints the values of the DetailEntry objects<br />

as long as there are any.<br />

Detail newDetail = newFault.getDetail();<br />

if (newDetail != null) {<br />

Iterator entries = newDetail.getDetailEntries();<br />

while ( entries.hasNext() ) {<br />

DetailEntry newEntry = (DetailEntry)entries.next();<br />

String value = newEntry.getValue();<br />

System.out.println(" Detail entry = " + value);<br />

}<br />

}<br />

In summary, you have seen how to add a SOAPFault object and its contents to a message as well<br />

as how to retrieve the contents. A SOAPFault object, which is optional, is added to the SOAPBody<br />

object to convey status or error information. It must always have a fault code and a String<br />

explanation of the fault. A SOAPFault object must indicate the actor that is the source of the<br />

fault only when there are multiple actors; otherwise, it is optional. Similarly, the SOAPFault<br />

object must contain a Detail object with one or more DetailEntry objects only when the<br />

contents of the SOAPBody object could not be processed successfully.<br />

See “SOAP Fault Example” on page 622 for an example that uses code like that shown in this<br />

section.<br />

<strong>The</strong> first part of this tutorial uses code fragments to walk you through the fundamentals of using<br />

the SAAJ API. In this section, you will use some of those code fragments to create applications.<br />

First, you will see the program Request.java. <strong>The</strong>n you will see how to run the programs<br />

HeaderExample.java, DOMExample.java, DOMSrcExample.java, Attachments.java, and<br />

SOAPFaultTest.java.<br />

Note – Before you run any of the examples, follow the preliminary setup instructions in<br />

“Building the Examples” on page 69.<br />

Request Example<br />

Code Examples<br />

<strong>The</strong> class Request puts together the code fragments used in the section “SAAJ <strong>Tutorial</strong>” on<br />

page 588 and adds what is needed to make it a complete example of a client sending a<br />

request-response message. In addition to putting all the code together, it adds import<br />

statements, a main method, and a try/catch block with exception handling.<br />

Chapter 19 • SOAP with Attachments API for <strong>Java</strong> 611

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!