SAAJ Tutorial
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:
In the section
, 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 (
), 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