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.

<strong>The</strong> Coffee Break servers send two kinds of messages:<br />

■ Requests for current wholesale coffee prices<br />

■ Customer orders for coffee<br />

<strong>The</strong> SAAJ coffee supplier responds with two kinds of messages:<br />

■ Current price lists<br />

■ Order confirmations<br />

All the messages they send conform to an agreed-upon XML structure, which is specified in a<br />

DTD for each kind of message. This allows them to exchange messages even though they use<br />

different document formats internally.<br />

<strong>The</strong> four kinds of messages exchanged by the Coffee Break servers and the SAAJ supplier are<br />

specified by the following DTDs:<br />

■ request-prices.dtd<br />

■ price-list.dtd<br />

■ coffee-order.dtd<br />

■ confirm.dtd<br />

<strong>The</strong>se DTDs can be found at<br />

tut-install/javaeetutorial5/examples/coffeebreak/cb-saaj/dtds/. <strong>The</strong> dtds directory<br />

also contains a sample of what the XML documents specified in the DTDs might look like.<br />

<strong>The</strong> corresponding XML files for the DTDs are as follows:<br />

■ request-prices.xml<br />

■ price-list.xml<br />

■ coffee-order.xml<br />

■ confirm.xml<br />

Because of the DTDs, both parties know ahead of time what to expect in a particular kind of<br />

message and can therefore extract its content using the SAAJ API.<br />

Code for the client and server applications is in this directory:<br />

tut-install/javaeetutorial5/examples/coffeebreak/cb-saaj/src/java<br />

SAAJ Client<br />

<strong>The</strong> Coffee Break server, which is a SAAJ client in this scenario, sends requests to the SAAJ<br />

supplier. <strong>The</strong> SAAJ client application uses the SOAPConnection method call to send messages.<br />

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

SAAJ Coffee Supplier Service<br />

Chapter 36 • <strong>The</strong> Coffee Break Application 1025

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

Saved successfully!

Ooh no, something went wrong!