Java Reference
In-Depth Information
.
request
()
.
get
(
Products
.
class
);
Product product
=
null
null
;
iif
(
prods
.
getProducts
().
size
() >
0
)
{
System
.
out
.
println
(
"- Found iPhone in the database."
);
product
=
prods
.
getProducts
().
iterator
().
next
();
}
else
else
{
throw
throw new
new
RuntimeException
(
"Failed to find an iPhone in the database!"
);
}
The customer wants to buy a product called
iPhone
, so the client searches the product data-
base for it.
System
.
out
.
println
();
System
.
out
.
println
(
"** Create Order for iPhone"
);
LineItem item
=
new
new
LineItem
();
item
.
setProduct
(
product
);
item
.
setQuantity
(
1
);
Order order
=
new
new
Order
();
order
.
setTotal
(
product
.
getCost
());
order
.
setCustomer
(
customer
);
order
.
setDate
(
new
new
Date
().
toString
());
order
.
getLineItems
().
add
(
item
);
response
=
client
.
target
(
orders
).
request
().
post
(
Entity
.
xml
(
order
));
Assert
.
assertEquals
(
201
,
response
.
getStatus
());
response
.
close
();
System
.
out
.
println
();
System
.
out
.
println
(
"** Show all orders."
);
String xml
=
client
.
target
(
orders
).
request
().
get
(
String
.
class
);
System
.
out
.
println
(
xml
);
}
}
Finally, an order is created within the database.
Build and Run the Example Program
Perform the following steps:
1. Download the latest Wildfly 8.0 Application Server from
http://www.wildfly.org/
2. Unzip Wildfly 8.0 into any directory you want.