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.

}<br />

// Retrieve orderID from message received<br />

SOAPBody sentSB = message.getSOAPBody();<br />

Iterator sentIt = sentSB.getChildElements();<br />

SOAPBodyElement sentSBE = (SOAPBodyElement)sentIt.next();<br />

Iterator sentIt2 = sentSBE.getChildElements();<br />

SOAPElement sentSE = (SOAPElement)sentIt2.next();<br />

// Get the orderID test to put in confirmation<br />

String sentID = sentSE.getValue();<br />

// Create the confirmation message<br />

confirmation = messageFactory.createMessage();<br />

SOAPBody sb = message.getSOAPBody();<br />

QName newBodyName =<br />

new QName("http://sonata.coffeebreak.com", "confirmation", "Confirm");<br />

SOAPBodyElement confirm = sb.addBodyElement(newBodyName);<br />

// Create the orderID element for confirmation<br />

QName newOrderIDName = new QName("orderId");<br />

SOAPElement newOrderNo = confirm.addChildElement(newOrderIDName);<br />

newOrderNo.addTextNode(sentID);<br />

// Create ship-date element<br />

QName shipDateName = new QName("ship-date");<br />

SOAPElement shipDate = confirm.addChildElement(shipDateName);<br />

// Create the shipping date<br />

Date today = new Date();<br />

long msPerDay = 1000 * 60 * 60 * 24;<br />

long msTarget = today.getTime();<br />

long msSum = msTarget + (msPerDay * 2);<br />

Date result = new Date();<br />

result.setTime(msSum);<br />

String sd = result.toString();<br />

shipDate.addTextNode(sd);<br />

confirmation.saveChanges();<br />

} catch (Exception ex) {<br />

ex.printStackTrace();<br />

}<br />

return confirmation;<br />

SAAJ Coffee Supplier Service<br />

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

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

Saved successfully!

Ooh no, something went wrong!