Java Reference
In-Depth Information
{
synchronized
synchronized ( orderDB )
{
List < Order > orders = new
new ArrayList < Order >();
orders . addAll ( orderDB . values ());
for
for ( Order order : orders )
{
iif ( order . isCancelled ())
{
orderDB . remove ( order . getId ());
}
}
}
}
Finally, the purgeOrders() method implements the purging of cancelled orders.
StoreResource
One of the things I want to illustrate with this example is that a client needs to be aware of
only one URL to navigate through the entire system. The StoreResource class is the base
URL of the system and publishes Link headers to the relevant services of the application:
src/main/java/com/restfully/shop/services/StoreResource.java
@Path ( "/shop" )
public
public class
class StoreResource
StoreResource
{
@HEAD
public
public Response head ( @Context UriInfo uriInfo )
{
UriBuilder absolute = uriInfo . getBaseUriBuilder ();
URI customerUrl = absolute . clone (). path ( CustomerResource . class ). build ();
URI orderUrl = absolute . clone (). path ( OrderResource . class ). build ();
Response . ResponseBuilder builder = Response . ok ();
Link customers = Link . fromUri ( customerUrl )
. rel ( "customers" )
. type ( "application/xml" ). build ();
Link orders = Link . fromUri ( orderUrl )
. rel ( "orders" )
. type ( "application/xml" ). build ();
builder . links ( customers , orders );
return
return builder . build ();
}
}
Search WWH ::




Custom Search