background image

Returning the Order Confirmation

<< The onMessage Method | The SOAPBodyElement Class >>
<< The onMessage Method | The SOAPBodyElement Class >>

Returning the Order Confirmation

SOAPElement coffeeName2 = coffee.addChildElement(coffeeNm2);
coffeeName2.addTextNode(
"Espresso");
QName priceName2 = new QName(
"price");
SOAPElement price2 = coffee.addChildElement(priceName2);
price2.addTextNode(
"5.00");
QName coffeeNm3 = new QName(
"coffee-name");
SOAPElement coffeeName3 = coffee.addChildElement(coffeeNm3);
coffeeName3.addTextNode(
"Dorada");
QName priceName3 = new QName(
"price");
SOAPElement price3 = coffee.addChildElement(priceName3);
price3.addTextNode(
"6.00");
QName coffeeNm4 = snew QName(
"coffee-name");
SOAPElement coffeeName4 = coffee.addChildElement(coffeeNm4);
coffeeName4.addTextNode(
"House Blend");
QName priceName4 = new QName(
"price");
SOAPElement price4 = coffee.addChildElement(priceName4);
price4.addTextNode(
"5.00");
message.saveChanges();
} catch(Exception e) {
logger.severe(
"onMessage: Exception: " + e.toString());
}
return message;
}
Returning the Order Confirmation
ConfirmationServlet
creates the confirmation message that is returned to the call method
that is invoked in OrderRequest. It is very similar to the code in PriceListServlet except that
instead of building a price list, its onMessage method builds a confirmation containing the
order number and shipping date.
The onMessage method for this servlet uses the SOAPMessage object passed to it by the doPost
method to get the order number sent in OrderRequest. Then it builds a confirmation message
containing the order ID and shipping date. The shipping date is calculated as today's date plus
two days.
public SOAPMessage onMessage(SOAPMessage message) {
logger.info(
"onMessage");
SOAPMessage confirmation = null;
try {
SAAJ Coffee Supplier Service
The Java EE 5 Tutorial · September 2007
1044