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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

SAAJ<strong>Tutorial</strong><br />

SAAJ<strong>Tutorial</strong><br />

588<br />

SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();<br />

SOAPConnection connection = factory.createConnection();<br />

. . .// create a request message and give it content<br />

java.net.URL endpoint = new URL("http://fabulous.com/gizmo/order");<br />

SOAPMessage response = connection.call(request, endpoint);<br />

Note that the second argument to the call method, which identifies where the message is being<br />

sent, can be a String object or a URL object. Thus, the last two lines of code from the preceding<br />

example could also have been the following:<br />

String endpoint = "http://fabulous.com/gizmo/order";<br />

SOAPMessage response = connection.call(request, endpoint);<br />

A web service implemented for request-response messaging must return a response to any<br />

message it receives. <strong>The</strong> response is a SOAPMessage object, just as the request is a SOAPMessage<br />

object. When the request message is an update, the response is an acknowledgment that the<br />

update was received. Such an acknowledgment implies that the update was successful. Some<br />

messages may not require any response at all. <strong>The</strong> service that gets such a message is still<br />

required to send back a response because one is needed to unblock the call method. In this<br />

case, the response is not related to the content of the message; it is simply a message to unblock<br />

the call method.<br />

Now that you have some background on SOAP messages and SOAP connections, in the next<br />

section you will see how to use the SAAJ API.<br />

This tutorial walks you through how to use the SAAJ API. First, it covers the basics of creating<br />

and sending a simple SOAP message. <strong>The</strong>n you will learn more details about adding content to<br />

messages, including how to create SOAP faults and attributes. Finally, you will learn how to<br />

send a message and retrieve the content of the response.<br />

After going through this tutorial, you will know how to perform the following tasks:<br />

■ “Creating and Sending a Simple Message” on page 589<br />

■ “Adding Content to the Header” on page 597<br />

■ “Adding Content to the SOAPPart Object” on page 598<br />

■ “Adding a Document to the SOAP Body” on page 599<br />

■ “Manipulating Message Content Using SAAJ or DOM APIs” on page 599<br />

■ “Adding Attachments” on page 599<br />

■ “Adding Attributes” on page 602<br />

■ “Using SOAP Faults” on page 607<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

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

Saved successfully!

Ooh no, something went wrong!