The SOAPBodyElement Class
The SOAPBodyElement Class
// Retrieve orderID from message received
SOAPBody sentSB = message.getSOAPBody();
Iterator sentIt = sentSB.getChildElements();
SOAPBodyElement sentSBE = (SOAPBodyElement)sentIt.next();
Iterator sentIt2 = sentSBE.getChildElements();
SOAPElement sentSE = (SOAPElement)sentIt2.next();
// Get the orderID test to put in confirmation
String sentID = sentSE.getValue();
// Create the confirmation message
confirmation = messageFactory.createMessage();
SOAPBody sb = message.getSOAPBody();
QName newBodyName =
new QName(
"http://sonata.coffeebreak.com", "confirmation", "Confirm");
SOAPBodyElement confirm = sb.addBodyElement(newBodyName);
// Create the orderID element for confirmation
QName newOrderIDName = new QName(
"orderId");
SOAPElement newOrderNo = confirm.addChildElement(newOrderIDName);
newOrderNo.addTextNode(sentID);
// Create ship-date element
QName shipDateName = new QName(
"ship-date");
SOAPElement shipDate = confirm.addChildElement(shipDateName);
// Create the shipping date
Date today = new Date();
long msPerDay = 1000 * 60 * 60 * 24;
long msTarget = today.getTime();
long msSum = msTarget + (msPerDay * 2);
Date result = new Date();
result.setTime(msSum);
String sd = result.toString();
shipDate.addTextNode(sd);
confirmation.saveChanges();
} catch (Exception ex) {
ex.printStackTrace();
}
return confirmation;
}
SAAJ Coffee Supplier Service
Chapter 36 · The Coffee Break Application
1045