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 Coffee Supplier Service<br />

1036<br />

}<br />

SOAPElement coffeeName2 = coffee.addChildElement(coffeeNm2);<br />

coffeeName2.addTextNode("Espresso");<br />

QName priceName2 = new QName("price");<br />

SOAPElement price2 = coffee.addChildElement(priceName2);<br />

price2.addTextNode("5.00");<br />

QName coffeeNm3 = new QName("coffee-name");<br />

SOAPElement coffeeName3 = coffee.addChildElement(coffeeNm3);<br />

coffeeName3.addTextNode("Dorada");<br />

QName priceName3 = new QName("price");<br />

SOAPElement price3 = coffee.addChildElement(priceName3);<br />

price3.addTextNode("6.00");<br />

QName coffeeNm4 = snew QName("coffee-name");<br />

SOAPElement coffeeName4 = coffee.addChildElement(coffeeNm4);<br />

coffeeName4.addTextNode("House Blend");<br />

QName priceName4 = new QName("price");<br />

SOAPElement price4 = coffee.addChildElement(priceName4);<br />

price4.addTextNode("5.00");<br />

message.saveChanges();<br />

} catch(Exception e) {<br />

logger.severe("onMessage: Exception: " + e.toString());<br />

}<br />

return message;<br />

Returning the Order Confirmation<br />

ConfirmationServlet creates the confirmation message that is returned to the call method<br />

that is invoked in OrderRequest. It is very similar to the code in PriceListServlet except that<br />

instead of building a price list, its onMessage method builds a confirmation containing the<br />

order number and shipping date.<br />

<strong>The</strong> onMessage method for this servlet uses the SOAPMessage object passed to it by the doPost<br />

method to get the order number sent in OrderRequest. <strong>The</strong>n it builds a confirmation message<br />

containing the order ID and shipping date. <strong>The</strong> shipping date is calculated as today’s date plus<br />

two days.<br />

public SOAPMessage onMessage(SOAPMessage message) {<br />

logger.info("onMessage");<br />

SOAPMessage confirmation = null;<br />

try {<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!