background image

SAAJ Tutorial

<< SAAJ Connections | Creating and Sending a Simple Message >>
<< SAAJ Connections | Creating and Sending a Simple Message >>

SAAJ Tutorial

Note that the second argument to the call method, which identifies where the message is being
sent, can be a String object or a URL object. Thus, the last two lines of code from the preceding
example could also have been the following:
String endpoint =
"http://fabulous.com/gizmo/order";
SOAPMessage response = connection.call(request, endpoint);
A web service implemented for request-response messaging must return a response to any
message it receives. The response is a SOAPMessage object, just as the request is a SOAPMessage
object. When the request message is an update, the response is an acknowledgment that the
update was received. Such an acknowledgment implies that the update was successful. Some
messages may not require any response at all. The service that gets such a message is still
required to send back a response because one is needed to unblock the call method. In this
case, the response is not related to the content of the message; it is simply a message to unblock
the call method.
Now that you have some background on SOAP messages and SOAP connections, in the next
section you will see how to use the SAAJ API.
SAAJ Tutorial
This tutorial walks you through how to use the SAAJ API. First, it covers the basics of creating
and sending a simple SOAP message. Then you will learn more details about adding content to
messages, including how to create SOAP faults and attributes. Finally, you will learn how to
send a message and retrieve the content of the response.
After going through this tutorial, you will know how to perform the following tasks:
"Creating and Sending a Simple Message" on page 591
"Adding Content to the Header" on page 598
"Adding Content to the SOAPPart Object" on page 599
"Adding a Document to the SOAP Body" on page 600
"Manipulating Message Content Using SAAJ or DOM APIs" on page 601
"Adding Attachments" on page 601
"Adding Attributes" on page 603
"Using SOAP Faults" on page 608
In the section
"Code Examples" on page 613
, you will see the code fragments from earlier parts
of the tutorial in runnable applications, which you can test yourself. To see how the SAAJ API
can be used in server code, see the SAAJ part of the Coffee Break case study (
"SAAJ Coffee
Supplier Service" on page 1032
), which shows an example of both the client and the server code
for a web service application.
A SAAJ client can send request-response messages to web services that are implemented to do
request-response messaging. This section demonstrates how you can do this.
SAAJ Tutorial
The Java EE 5 Tutorial · September 2007
590