COMP 655: Distributed/Operating Systems - Summer 2011
2024-03-29 14:38:50 UTC
Home
Lectures
Assignments
Books, web, tools
 
Turnitin.com
Guidelines
Writing help
Plagiarism
 
DiNo
Glassfish
RESTful client
Menu service
JAX-RS
JAXB
EJB
Java
 
Bulletin board
Contact
 Menu service demo

The idea

The menu service keeps track of menus. Each menu consists of a day and a list of zero or more items. For example,

<menu>
    <day>Monday</day>
    <item>shepherd's pie</item>
    <item>pizza</item>
    <item>vegetarian lasagna</item>
    <item>pad thai</item>
</menu>

The service maintains menus for multiple days, which can be read as a list of menus. For example,

<menu-list>
    <menu>
        <day>today</day>
        <item>potato salad</item>
        <item>apple pie</item>
        <item>ice cream</item>
    </menu>
    <menu>
        <day>tomorrow</day>
        <item>spinach salad</item>
        <item>chocolate cake</item>
    </menu>
</menu-list>

Days can be represented by arbitrary character strings, subject to two constraints:

  • A day cannot contain a forward slash (/) character
  • A day cannot be called "item"

Items can be arbitrary character strings

A user of the menu service can read, add and remove menu items.


Viewing the demo

  • You can download the war file into the domains/domain1/autodeploy directory of a GlassFish installation. (your browser will probably change the file extension from .war to .zip, which is OK) The context root will be "menu"
  • The restful client knows about the menu service

Interface

  • The interface is designed in a RESTful style
  • XML
  • Input content
    • No request types have content. Similar to the Java homework, this demo restricts itself to input from the request URL in order to focus attention on basic URI handling in RESTful services
  • Output content
    • Successful GET requests should return an XML document, whose root is either a <menu> or <menu-list> element. See below for details.
    • POST, PUT and DELETE should not return any content. See below for their response codes.
  • Parameters
    • This service ignores request parameters

Graphical view of menu.xsd

URIs

Form Used when Example
/ Retrieving all of the menus (with GET), replacing the menu a day (with POST), adding multiple menu items for a day (with PUT) /
/day Looking up the menu for a given day (with GET), removing all of a day's menu items (with DELETE) /Monday
/day/item Adding an item to the menu for a given day (with POST or PUT), removing an item from a day's menu (with DELETE) /Tuesday/spaghetti
/item/item Retrieving all of the menus that contain a given item (with GET) /item/salmon

Back to top


Methods

GET

The menu service uses GET requests for all lookups. The URIs used in GET requests are side-effect free, bookmark-able and cacheable. The only reason for a change in the results of a GET request is an update to the underlying content.

POST

The menu service uses POST requests for adding or removing menu items.

PUT

The menu service uses PUT requests for the same purposes as POST: adding or removing menu items.

DELETE

The directory service uses DELETE requests for deleting menu items.

Back to top

 

GET /

The response is the complete list of menus.

Request content Response content Additional information
none menu-list
  menu*
    day
    item*
It is NOT an error if the service doesn't know about any menus. For example, at start-up it may be that no menus have been created yet. In that case, the menu-list element will be empty. 

Possible errors:

  • none

GET /day

The response is the menu the given day, if any.

Request content Response content Additional information
none menu
  day
  item*
The day should be URL-encoded, if necessary. For example, the URI /Saint%20Patrick's%20Day should be used to request information about the menu for Saint Patrick's Day.

Possible errors:

  • 404 - Not found; occurs if the application has no menu for the given day.

GET /item/item

The response is the list of menus, if any, that contain the given item.

Request content Response content Additional information
none menu-list
  menu*
    day
    item*
The item should be URL-encoded, if necessary. For example, the URI /item/shepherd's%20pie should be used to search for menus containing shepherd's pie.

Possible errors:

  • 404 - Not found; occurs if the application has no menu that contains the given item.

Back to top


POST /

Accepts a menu element from the request content and makes it the menu for the given day.

Request content Response content Additional information
menu
  day
  item*
none The given menu replaces the existing menu for the given day, if any.

Possible errors:

  • 400 - Bad request; occurs if the request content cannot be parsed as a menu element.

POST /day/item

Adds the given item to the menu for the given day.

Request content Response content Additional information
none none The day and the item should be URL-encoded, if necessary. For example, the URI /Saint%20Patrick's%20Day/shepherd's%20pie should be used to add shepherd's pie to the menu for Saint Patrick's Day.

Possible errors:

  • None

Back to top

 


PUT /

Accepts a menu element from the request content and adds its items to the menu for the given day.

Request content Response content Additional information
menu
   day
   item*
none The given items are added to the menu for the given day.

Possible errors:

  • 400 - Bad request; occurs if the request content cannot be parsed as a menu element.

PUT /day/item

Adds the given item to the menu for the given day.

Request content Response content Additional information
none none The day and the item should be URL-encoded, if necessary. For example, the URI /Saint%20Patrick's%20Day/shepherd's%20pie should be used to add shepherd's pie to the menu for Saint Patrick's Day.

Possible errors:

  • None

Back to top


DELETE /day/item

Deletes the given item from the menu for the given day.

Request content Response content Additional information
none none The day and the item should be URL-encoded, if necessary. For example, the URI /Saint%20Patrick's%20Day/shepherd's%20pie should be used to delete shepherd's pie from the menu for Saint Patrick's Day.

Possible errors:

  • 404 - Not found; occurs if there is no menu for the given day, or the menu for the given day does not contain the given item

DELETE  /day

Deletes the menu the given day, if any.

Request content Response content Additional information
none none The day should be URL-encoded, if necessary. For example, the URI /Saint%20Patrick's%20Day should be used to delete the menu for Saint Patrick's Day.

Possible errors:

  • 404 - Not found; occurs if the application has no menu for the given day.

Back to top