background image

Code Examples

<< getSOAPBody() Method | Request.java Class Code >>
<< getSOAPBody() Method | Request.java Class Code >>
C
ODE
E
XAMPLES
151
null
. If it is not, the code prints the values of the
DetailEntry
objects as long as
there are any.
Detail newDetail = newFault.getDetail();
if (newDetail != null) {
Iterator entries = newDetail.getDetailEntries();
while ( entries.hasNext() ) {
DetailEntry newEntry = (DetailEntry)entries.next();
String value = newEntry.getValue();
System.out.println(" Detail entry = " + value);
}
}
In summary, you have seen how to add a
SOAPFault
object and its contents to a
message as well as how to retrieve the contents. A
SOAPFault
object, which is
optional, is added to the
SOAPBody
object to convey status or error information. It
must always have a fault code and a
String
explanation of the fault. A
SOAP-
Fault
object must indicate the actor that is the source of the fault only when
there are multiple actors; otherwise, it is optional. Similarly, the
SOAPFault
object must contain a
Detail
object with one or more
DetailEntry
objects only
when the contents of the
SOAPBody
object could not be processed successfully.
See SOAPFaultTest.java (page 168) for an example that uses code like that
shown in this section.
Code Examples
The first part of this tutorial uses code fragments to walk you through the funda-
mentals of using the SAAJ API. In this section, you will use some of those code
fragments to create applications. First, you will see the program
Request.java
.
Then you will see how to run the programs
MyUddiPing.java
,
HeaderExam-
ple.java
,
DOMExample.java
,
DOMSrcExample.java
,
Attachments.java
, and
SOAPFaultTest.java
.
Note: Before you run any of the examples, follow the preliminary setup instructions
in Building the Examples (page xxxiii).