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.

Common Code<br />

5. When an order is placed, suborders are sent to one or more suppliers using the supplier’s<br />

preferred protocol.<br />

<strong>The</strong> Coffee Break servers share the CoffeeBreak.properties file, which contains the URLs<br />

exposed by the JAX-WS and SAAJ suppliers; the URLHelper class, which is used by the server<br />

and client classes to retrieve the URLs; the DateHelper utility class; and several generated<br />

<strong>Java</strong>Beans components, described in “JAX-WS Coffee Supplier Service” on page 1023. <strong>The</strong>se<br />

<strong>Java</strong>Beans components are generated from the cb-jaxws JAX-WS web service by the wsimport<br />

tool.<br />

<strong>The</strong> source code for the shared files is in the<br />

tut-install/javaeetutorial5/examples/coffeebreak/<br />

cb-common/src/java/com/sun/cb/common/ directory.<br />

JAX-WS Coffee Supplier Service<br />

<strong>The</strong> Coffee Break servers are clients of the JAX-WS coffee supplier service. <strong>The</strong> service code<br />

consists of the service implementation class, and several <strong>Java</strong>Beans components that are used<br />

for method parameters and return types. <strong>The</strong> <strong>Java</strong>Beans components are:<br />

■ AddressBean: shipping information for customer<br />

■ ConfirmationBean: order ID and ship date<br />

■ CustomerBean: customer contact information<br />

■ LineItemBean: order item<br />

■ OrderBean: order ID, customer, address, list of line items, total price<br />

■ PriceItemBean: price list entry (coffee name and wholesale price)<br />

■ PriceListBean: price list<br />

<strong>The</strong>se <strong>Java</strong>Beans components are propagated to the clients by means of the wsimport tool.<br />

Service Implementation<br />

JAX-WS Coffee Supplier Service<br />

<strong>The</strong> Supplier class implements the placeOrder and getPriceList methods. So that you can<br />

focus on the code related to JAX-WS, these methods are short and simplistic. In a real world<br />

application, these methods would access databases and would interact with other services, such<br />

as shipping, accounting, and inventory.<br />

<strong>The</strong> placeOrder method accepts as input a coffee order and returns a confirmation for the<br />

order. To keep things simple, the placeOrder method confirms every order and sets the ship<br />

date in the confirmation to the next day. <strong>The</strong> source code for the placeOrder method follows:<br />

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

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

Saved successfully!

Ooh no, something went wrong!